|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +/** |
| 4 | + * Theme Line Width Tests |
| 5 | + * |
| 6 | + * Verifies that essay content line widths are consistent across themes. |
| 7 | + * The EssayLayout uses fixed rem values (48rem = 768px on xl screens) to ensure |
| 8 | + * consistent line widths regardless of theme font size or family. |
| 9 | + */ |
| 10 | + |
| 11 | +test.describe('Theme Line Width Comparison', () => { |
| 12 | + const themes = ['nyt', 'chinese-aesthetic', 'brutalism'] as const; |
| 13 | + |
| 14 | + test.describe('EssayLayout content width', () => { |
| 15 | + for (const theme of themes) { |
| 16 | + test(`${theme} theme - measures content width on desktop`, async ({ page }) => { |
| 17 | + await page.setViewportSize({ width: 1440, height: 900 }); |
| 18 | + |
| 19 | + // Navigate to EssayLayout story |
| 20 | + await page.goto( |
| 21 | + `/iframe.html?id=blog-essay-essaylayout--default&viewMode=story&globals=theme:${theme}` |
| 22 | + ); |
| 23 | + |
| 24 | + await page.waitForSelector('.essay-layout', { timeout: 10000 }); |
| 25 | + |
| 26 | + // Get the essay-content element |
| 27 | + const contentArea = page.locator('.essay-content'); |
| 28 | + await expect(contentArea).toBeVisible(); |
| 29 | + |
| 30 | + // Measure computed styles |
| 31 | + const styles = await contentArea.evaluate((el) => { |
| 32 | + const computed = window.getComputedStyle(el); |
| 33 | + const rect = el.getBoundingClientRect(); |
| 34 | + return { |
| 35 | + maxWidth: computed.maxWidth, |
| 36 | + width: rect.width, |
| 37 | + fontSize: computed.fontSize, |
| 38 | + fontFamily: computed.fontFamily, |
| 39 | + }; |
| 40 | + }); |
| 41 | + |
| 42 | + console.log(`Theme: ${theme}`); |
| 43 | + console.log(` Max-width: ${styles.maxWidth}`); |
| 44 | + console.log(` Actual width: ${styles.width}px`); |
| 45 | + console.log(` Font-size: ${styles.fontSize}`); |
| 46 | + console.log(` Font-family: ${styles.fontFamily.slice(0, 50)}...`); |
| 47 | + |
| 48 | + // Verify max-width is set to fixed pixel value (768px = 48rem on xl screens) |
| 49 | + expect(styles.maxWidth).toMatch(/px/); |
| 50 | + }); |
| 51 | + } |
| 52 | + |
| 53 | + test('all themes have same content width on desktop', async ({ page }) => { |
| 54 | + await page.setViewportSize({ width: 1440, height: 900 }); |
| 55 | + |
| 56 | + const contentWidths: Record<string, number> = {}; |
| 57 | + |
| 58 | + for (const theme of themes) { |
| 59 | + await page.goto( |
| 60 | + `/iframe.html?id=blog-essay-essaylayout--default&viewMode=story&globals=theme:${theme}` |
| 61 | + ); |
| 62 | + |
| 63 | + await page.waitForSelector('.essay-layout', { timeout: 10000 }); |
| 64 | + |
| 65 | + const contentArea = page.locator('.essay-content'); |
| 66 | + await expect(contentArea).toBeVisible(); |
| 67 | + |
| 68 | + const width = await contentArea.evaluate((el) => { |
| 69 | + return el.getBoundingClientRect().width; |
| 70 | + }); |
| 71 | + |
| 72 | + contentWidths[theme] = width; |
| 73 | + } |
| 74 | + |
| 75 | + console.log('\n=== Content Width Comparison ==='); |
| 76 | + console.log('NYT width:', contentWidths['nyt'], 'px'); |
| 77 | + console.log('Chinese-aesthetic width:', contentWidths['chinese-aesthetic'], 'px'); |
| 78 | + console.log('Brutalism width:', contentWidths['brutalism'], 'px'); |
| 79 | + |
| 80 | + // All themes should have the same content width (672px = 42rem) |
| 81 | + const expectedWidth = 672; |
| 82 | + const tolerance = 2; // Allow small rounding differences |
| 83 | + |
| 84 | + expect(Math.abs(contentWidths['nyt'] - expectedWidth)).toBeLessThanOrEqual(tolerance); |
| 85 | + expect(Math.abs(contentWidths['chinese-aesthetic'] - expectedWidth)).toBeLessThanOrEqual(tolerance); |
| 86 | + expect(Math.abs(contentWidths['brutalism'] - expectedWidth)).toBeLessThanOrEqual(tolerance); |
| 87 | + }); |
| 88 | + |
| 89 | + test('documents font sizes across themes (vary by design)', async ({ page }) => { |
| 90 | + await page.setViewportSize({ width: 1440, height: 900 }); |
| 91 | + |
| 92 | + const fontSizes: Record<string, string> = {}; |
| 93 | + const fontFamilies: Record<string, string> = {}; |
| 94 | + |
| 95 | + for (const theme of themes) { |
| 96 | + await page.goto( |
| 97 | + `/iframe.html?id=blog-essay-essaylayout--default&viewMode=story&globals=theme:${theme}` |
| 98 | + ); |
| 99 | + |
| 100 | + await page.waitForSelector('.essay-layout', { timeout: 10000 }); |
| 101 | + |
| 102 | + const contentArea = page.locator('.essay-content'); |
| 103 | + await expect(contentArea).toBeVisible(); |
| 104 | + |
| 105 | + const styles = await contentArea.evaluate((el) => { |
| 106 | + const computed = window.getComputedStyle(el); |
| 107 | + return { |
| 108 | + fontSize: computed.fontSize, |
| 109 | + fontFamily: computed.fontFamily, |
| 110 | + }; |
| 111 | + }); |
| 112 | + |
| 113 | + fontSizes[theme] = styles.fontSize; |
| 114 | + fontFamilies[theme] = styles.fontFamily; |
| 115 | + } |
| 116 | + |
| 117 | + console.log('\n=== Font Style Comparison ==='); |
| 118 | + console.log('NYT font-size:', fontSizes['nyt'], '| font-family:', fontFamilies['nyt'].slice(0, 40)); |
| 119 | + console.log('Chinese-aesthetic font-size:', fontSizes['chinese-aesthetic'], '| font-family:', fontFamilies['chinese-aesthetic'].slice(0, 40)); |
| 120 | + console.log('Brutalism font-size:', fontSizes['brutalism'], '| font-family:', fontFamilies['brutalism'].slice(0, 40)); |
| 121 | + |
| 122 | + // All themes should have valid font sizes (this is a documentation test) |
| 123 | + for (const theme of themes) { |
| 124 | + const size = parseFloat(fontSizes[theme]); |
| 125 | + expect(size).toBeGreaterThan(0); |
| 126 | + expect(fontFamilies[theme]).toBeTruthy(); |
| 127 | + } |
| 128 | + }); |
| 129 | + }); |
| 130 | +}); |
0 commit comments