|
| 1 | +/** |
| 2 | + * Feature assertion: starter prompt suggestions on the empty conversation state. |
| 3 | + * |
| 4 | + * Drives the real built app over CDP through the full path: |
| 5 | + * boot into the empty draft chat → the suggestion chips render → click one → |
| 6 | + * the composer is populated with that suggestion's (fuller) prompt → the |
| 7 | + * suggestions surface disappears once the composer has content. |
| 8 | + * |
| 9 | + * This proves the feature actually *does* something (seeds the composer), not |
| 10 | + * merely that the chips render. |
| 11 | + */ |
| 12 | + |
| 13 | +import type { Assertion } from '../runner'; |
| 14 | + |
| 15 | +const SUGGESTIONS = '[data-testid="empty-suggestions"]'; |
| 16 | +const CHIP = '[data-testid="empty-suggestion"]'; |
| 17 | +const COMPOSER = '[role="textbox"][aria-multiline="true"]'; |
| 18 | + |
| 19 | +/** Visible chips only (defensive against hidden/duplicated nodes). */ |
| 20 | +const VISIBLE_CHIPS_EXPR = `[...document.querySelectorAll(${JSON.stringify( |
| 21 | + CHIP, |
| 22 | +)})].filter((el) => el.offsetParent !== null)`; |
| 23 | + |
| 24 | +/** Trimmed text of the (visible) composer, with zero-width chars stripped. */ |
| 25 | +const COMPOSER_TEXT_EXPR = `(() => { |
| 26 | + const el = [...document.querySelectorAll(${JSON.stringify( |
| 27 | + COMPOSER, |
| 28 | + )})].find((n) => n.offsetParent !== null); |
| 29 | + if (!el) return null; |
| 30 | + return (el.textContent || '').replace(/[\\u200B-\\u200D\\uFEFF]/g, '').trim(); |
| 31 | +})()`; |
| 32 | + |
| 33 | +const assertion: Assertion = { |
| 34 | + name: 'empty-state starter suggestions seed the composer', |
| 35 | + async run(app) { |
| 36 | + const { session } = app; |
| 37 | + |
| 38 | + // App fully mounted. |
| 39 | + await session.waitForFunction( |
| 40 | + '!document.getElementById("_loader") && (document.getElementById("root")?.childElementCount ?? 0) > 0', |
| 41 | + { timeoutMs: 30000, message: 'React UI did not mount' }, |
| 42 | + ); |
| 43 | + |
| 44 | + // Reach the ready AppShell (not onboarding / workspace-picker). The empty |
| 45 | + // draft chat — with its centered composer — is the default landing view. |
| 46 | + await session.waitForSelector('[aria-label="Craft menu"]', { |
| 47 | + timeoutMs: 30000, |
| 48 | + message: 'app did not reach the ready AppShell state', |
| 49 | + }); |
| 50 | + |
| 51 | + // 1. The suggestions surface renders on the empty conversation. |
| 52 | + await session.waitForSelector(SUGGESTIONS, { |
| 53 | + timeoutMs: 15000, |
| 54 | + message: 'starter suggestions did not render on the empty conversation', |
| 55 | + }); |
| 56 | + |
| 57 | + // 2. It shows the full set of chips (4). |
| 58 | + await session.waitForFunction(`${VISIBLE_CHIPS_EXPR}.length === 4`, { |
| 59 | + timeoutMs: 8000, |
| 60 | + message: 'expected 4 visible starter-suggestion chips', |
| 61 | + }); |
| 62 | + |
| 63 | + // 3. The composer starts empty. |
| 64 | + const before = await session.evaluate<string | null>(COMPOSER_TEXT_EXPR); |
| 65 | + if (before == null) throw new Error('could not locate the composer text box'); |
| 66 | + if (before.length !== 0) { |
| 67 | + throw new Error(`composer was not empty at start (saw: ${JSON.stringify(before)})`); |
| 68 | + } |
| 69 | + |
| 70 | + // 4. Capture the first chip's visible label, then click it. |
| 71 | + const label = await session.evaluate<string | null>( |
| 72 | + `(() => { const el = ${VISIBLE_CHIPS_EXPR}[0]; return el ? (el.textContent || '').trim() : null; })()`, |
| 73 | + ); |
| 74 | + if (!label) throw new Error('could not read the first suggestion label'); |
| 75 | + |
| 76 | + const clicked = await session.evaluate<boolean>( |
| 77 | + `(() => { const el = ${VISIBLE_CHIPS_EXPR}[0]; if (!el) return false; el.click(); return true; })()`, |
| 78 | + ); |
| 79 | + if (!clicked) throw new Error('failed to click the first suggestion chip'); |
| 80 | + |
| 81 | + // 5. The composer is populated with the suggestion's prompt. The prompt is a |
| 82 | + // full sentence, so it must be non-empty and longer than the short label — |
| 83 | + // proving it seeded the *prompt*, not merely echoed the chip title. |
| 84 | + await session.waitForFunction( |
| 85 | + `(() => { |
| 86 | + const text = ${COMPOSER_TEXT_EXPR}; |
| 87 | + return typeof text === 'string' && text.length > ${label.length} && text.length > 20; |
| 88 | + })()`, |
| 89 | + { |
| 90 | + timeoutMs: 8000, |
| 91 | + message: 'clicking a suggestion did not populate the composer with its prompt', |
| 92 | + }, |
| 93 | + ); |
| 94 | + |
| 95 | + // 6. Once the composer has content, the suggestions surface goes away |
| 96 | + // (matching the empty-state-only behavior of the feature). |
| 97 | + await session.waitForFunction( |
| 98 | + `!document.querySelector(${JSON.stringify(SUGGESTIONS)})`, |
| 99 | + { |
| 100 | + timeoutMs: 8000, |
| 101 | + message: 'suggestions did not hide after the composer was populated', |
| 102 | + }, |
| 103 | + ); |
| 104 | + }, |
| 105 | +}; |
| 106 | + |
| 107 | +export default assertion; |
0 commit comments