|
| 1 | +/** |
| 2 | + * Feature assertion: the "Conversation width" segmented control in |
| 3 | + * Settings → Appearance actually applies and persists an app-wide reading-column |
| 4 | + * width preference. |
| 5 | + * |
| 6 | + * Drives the real UI over CDP entirely in the draft/no-session state (no seeded |
| 7 | + * conversation, no backend connection): opens Settings → Appearance, selects each |
| 8 | + * width option, and asserts the observable effects that the transcript + composer |
| 9 | + * consume — the selected radio state, the `data-conversation-width` attribute on |
| 10 | + * <html>, the computed `--chat-content-max-width` CSS custom property (the value |
| 11 | + * the chat containers read via `max-width: var(--chat-content-max-width, 840px)`), |
| 12 | + * and the persisted localStorage value. |
| 13 | + * |
| 14 | + * Cycling through all three options proves it both applies and reverts, not merely |
| 15 | + * renders. |
| 16 | + */ |
| 17 | + |
| 18 | +import type { Assertion } from '../runner'; |
| 19 | + |
| 20 | +const SETTINGS_NAV = '[data-testid="nav:settings"]'; |
| 21 | +const APPEARANCE_NAV = '[data-testid="settings-nav-appearance"]'; |
| 22 | +const CONTROL = '[data-testid="conversation-width-control"]'; |
| 23 | +const STORAGE_KEY = 'craft-conversation-width'; |
| 24 | + |
| 25 | +type Mode = 'comfortable' | 'wide' | 'full'; |
| 26 | + |
| 27 | +const EXPECTED_MAX_WIDTH: Record<Mode, string> = { |
| 28 | + comfortable: '840px', |
| 29 | + wide: '1100px', |
| 30 | + full: 'none', |
| 31 | +}; |
| 32 | + |
| 33 | +/** aria-checked ("true" | "false" | null) for a given option button. */ |
| 34 | +function optionCheckedExpr(mode: Mode): string { |
| 35 | + return `(() => { |
| 36 | + const el = document.querySelector('[data-testid="conversation-width-control-${mode}"]'); |
| 37 | + return el ? el.getAttribute('aria-checked') : null; |
| 38 | + })()`; |
| 39 | +} |
| 40 | + |
| 41 | +/** The `data-conversation-width` marker value on <html>. */ |
| 42 | +function htmlModeExpr(): string { |
| 43 | + return `document.documentElement.getAttribute('data-conversation-width')`; |
| 44 | +} |
| 45 | + |
| 46 | +/** The computed `--chat-content-max-width` custom property on <html>. */ |
| 47 | +function cssVarExpr(): string { |
| 48 | + return `getComputedStyle(document.documentElement).getPropertyValue('--chat-content-max-width').trim()`; |
| 49 | +} |
| 50 | + |
| 51 | +/** The persisted localStorage value (JSON-encoded string) for the preference. */ |
| 52 | +function storedValueExpr(): string { |
| 53 | + return `window.localStorage.getItem(${JSON.stringify(STORAGE_KEY)})`; |
| 54 | +} |
| 55 | + |
| 56 | +const assertion: Assertion = { |
| 57 | + name: 'conversation-width control applies and persists an app-wide width preference', |
| 58 | + async run(app) { |
| 59 | + const { session } = app; |
| 60 | + |
| 61 | + // App fully mounted. |
| 62 | + await session.waitForFunction( |
| 63 | + '!document.getElementById("_loader") && (document.getElementById("root")?.childElementCount ?? 0) > 0', |
| 64 | + { timeoutMs: 30000, message: 'app did not mount' }, |
| 65 | + ); |
| 66 | + |
| 67 | + // Open Settings → Appearance (real user path). |
| 68 | + await session.click(SETTINGS_NAV, { timeoutMs: 15000 }); |
| 69 | + await session.click(APPEARANCE_NAV, { timeoutMs: 15000 }); |
| 70 | + |
| 71 | + // The control is the feature under test — its presence is the first signal. |
| 72 | + await session.waitForSelector(CONTROL, { |
| 73 | + timeoutMs: 15000, |
| 74 | + message: 'conversation-width control did not render', |
| 75 | + }); |
| 76 | + |
| 77 | + // Initial state: comfortable selected, <html> marked comfortable, 840px column. |
| 78 | + const initialChecked = await session.evaluate<string | null>(optionCheckedExpr('comfortable')); |
| 79 | + if (initialChecked !== 'true') { |
| 80 | + throw new Error(`expected "comfortable" selected initially, saw aria-checked=${initialChecked}`); |
| 81 | + } |
| 82 | + const initialMode = await session.evaluate<string | null>(htmlModeExpr()); |
| 83 | + if (initialMode !== 'comfortable') { |
| 84 | + throw new Error(`expected data-conversation-width="comfortable" initially, saw ${JSON.stringify(initialMode)}`); |
| 85 | + } |
| 86 | + const initialVar = await session.evaluate<string>(cssVarExpr()); |
| 87 | + if (initialVar !== EXPECTED_MAX_WIDTH.comfortable) { |
| 88 | + throw new Error(`expected --chat-content-max-width=840px initially, saw ${JSON.stringify(initialVar)}`); |
| 89 | + } |
| 90 | + |
| 91 | + // Selecting each mode applies + persists; the final "comfortable" proves revert. |
| 92 | + const sequence: Mode[] = ['full', 'wide', 'comfortable']; |
| 93 | + for (const mode of sequence) { |
| 94 | + await session.click(`[data-testid="conversation-width-control-${mode}"]`); |
| 95 | + |
| 96 | + // Radio state flips on. |
| 97 | + await session.waitForFunction( |
| 98 | + `${optionCheckedExpr(mode)} === 'true'`, |
| 99 | + { timeoutMs: 5000, message: `"${mode}" option did not become selected` }, |
| 100 | + ); |
| 101 | + |
| 102 | + // <html> marker updates. |
| 103 | + await session.waitForFunction( |
| 104 | + `${htmlModeExpr()} === ${JSON.stringify(mode)}`, |
| 105 | + { timeoutMs: 5000, message: `data-conversation-width did not update to "${mode}"` }, |
| 106 | + ); |
| 107 | + |
| 108 | + // CSS custom property (what the chat containers actually read) updates. |
| 109 | + await session.waitForFunction( |
| 110 | + `${cssVarExpr()} === ${JSON.stringify(EXPECTED_MAX_WIDTH[mode])}`, |
| 111 | + { timeoutMs: 5000, message: `--chat-content-max-width did not become ${EXPECTED_MAX_WIDTH[mode]} for "${mode}"` }, |
| 112 | + ); |
| 113 | + |
| 114 | + // Persisted (JSON-encoded string). |
| 115 | + const stored = await session.evaluate<string | null>(storedValueExpr()); |
| 116 | + if (stored !== JSON.stringify(mode)) { |
| 117 | + throw new Error(`expected persisted ${JSON.stringify(JSON.stringify(mode))} after selecting "${mode}", saw ${JSON.stringify(stored)}`); |
| 118 | + } |
| 119 | + } |
| 120 | + }, |
| 121 | +}; |
| 122 | + |
| 123 | +export default assertion; |
0 commit comments