|
| 1 | +import { test, expect } from './fixtures/server' |
| 2 | +import { withClipboardLock } from './fixtures/clipboardLock' |
| 3 | +import { noteCard, openCard } from './fixtures/atlasBoard' |
| 4 | +import { deleteViaPageMenu } from './fixtures/atlasPage' |
| 5 | + |
| 6 | +// The clipboard bridge (goal 0099): Copy for AI emits the JSON |
| 7 | +// envelope; the Quick Panel's clipboard door recognizes a reply, |
| 8 | +// renders the review surface (collisions default-unchecked), and the |
| 9 | +// accept runs the seeded route workflow. Shared worker pool: every |
| 10 | +// entity this file creates it deletes; clipboard sections take the |
| 11 | +// cross-process lock per testing.md's real-pasteboard discipline. |
| 12 | + |
| 13 | +async function openPanelWithClipboard(page: import('@playwright/test').Page, payload: string) { |
| 14 | + await page.goto('about:blank') |
| 15 | + await page.goto('/#/quickpanel') |
| 16 | + await page.context().grantPermissions(['clipboard-read', 'clipboard-write']) |
| 17 | + await page.evaluate((t) => navigator.clipboard.writeText(t), payload) |
| 18 | + const search = page.getByRole('combobox', { name: 'Quick Panel search' }) |
| 19 | + await expect(search).toBeFocused() |
| 20 | + await search.fill('apply from clipboard') |
| 21 | + const option = page.getByRole('option', { name: 'Apply from clipboard…' }) |
| 22 | + await expect(option).toBeVisible() |
| 23 | + await option.click() |
| 24 | +} |
| 25 | + |
| 26 | +test('Copy for AI puts the reply-contract envelope on the clipboard', async ({ page }) => { |
| 27 | + await withClipboardLock(async () => { |
| 28 | + await page.goto('/') |
| 29 | + await page.getByRole('link', { name: 'Atlas' }).click() |
| 30 | + await expect(page.getByTestId('atlas-board')).toBeVisible() |
| 31 | + await page.context().grantPermissions(['clipboard-read', 'clipboard-write']) |
| 32 | + |
| 33 | + const card = noteCard(page, 'Getting started') |
| 34 | + await openCard(page, card) |
| 35 | + await page.getByTestId('atlas-overlay-copy-for-ai').click() |
| 36 | + |
| 37 | + // The copy handler's binding round-trip + clipboard write are |
| 38 | + // async relative to the click -- poll until the envelope lands. |
| 39 | + await expect.poll(() => page.evaluate(() => navigator.clipboard.readText())).toContain('"mill"') |
| 40 | + const raw = await page.evaluate(() => navigator.clipboard.readText()) |
| 41 | + const envelope = JSON.parse(raw) |
| 42 | + expect(envelope.mill).toBe(1) |
| 43 | + expect(envelope.kind).toBe('context') |
| 44 | + expect(envelope.schema.type).toBe('object') |
| 45 | + expect(envelope.allowedActions).toContain('create-cards') |
| 46 | + expect(envelope.items[0].title).toBe('Getting started') |
| 47 | + expect(envelope.instructions).toContain('JSON code block') |
| 48 | + await page.keyboard.press('Escape') |
| 49 | + }) |
| 50 | +}) |
| 51 | + |
| 52 | +test('a valid reply reviews with collisions unchecked, and accepting creates only the checked card', async ({ page }) => { |
| 53 | + const freshTitle = 'ZzE2eBridgeCard' |
| 54 | + await withClipboardLock(async () => { |
| 55 | + const reply = JSON.stringify({ |
| 56 | + mill: 1, kind: 'reply', action: 'create-cards', |
| 57 | + items: [{ title: 'Getting started' }, { title: freshTitle, note: 'from the reply' }], |
| 58 | + }) |
| 59 | + await openPanelWithClipboard(page, reply) |
| 60 | + |
| 61 | + const review = page.getByTestId('quick-panel-reply-review') |
| 62 | + await expect(review).toBeVisible() |
| 63 | + const checkboxes = review.getByTestId('quick-panel-reply-card-checkbox') |
| 64 | + await expect(checkboxes).toHaveCount(2) |
| 65 | + await expect(checkboxes.nth(0)).not.toBeChecked() |
| 66 | + await expect(checkboxes.nth(1)).toBeChecked() |
| 67 | + await expect(review.getByText(/Already exists as/)).toBeVisible() |
| 68 | + |
| 69 | + const confirm = review.getByTestId('quick-panel-reply-confirm') |
| 70 | + await expect(confirm).toContainText('Create 1 card') |
| 71 | + await confirm.click() |
| 72 | + await expect(review).toHaveCount(0) |
| 73 | + }) |
| 74 | + |
| 75 | + // The accepted card exists; the declined collision stayed singular. |
| 76 | + await page.goto('/') |
| 77 | + await page.getByRole('link', { name: 'Atlas' }).click() |
| 78 | + await expect(page.getByTestId('atlas-board')).toBeVisible() |
| 79 | + const created = noteCard(page, freshTitle) |
| 80 | + await expect(created).toBeVisible() |
| 81 | + await expect(noteCard(page, 'Getting started')).toHaveCount(1) |
| 82 | + |
| 83 | + // Cleanup (within-file discipline). |
| 84 | + await openCard(page, created) |
| 85 | + const overlay = page.locator('[data-component="atlas-card-overlay"]') |
| 86 | + await deleteViaPageMenu(page, overlay) |
| 87 | + await expect(created).toHaveCount(0) |
| 88 | +}) |
| 89 | + |
| 90 | +test('an invalid reply names its failures and Copy corrected context re-emits the contract', async ({ page }) => { |
| 91 | + await withClipboardLock(async () => { |
| 92 | + const bad = JSON.stringify({ mill: 1, kind: 'reply', action: 'create-cards', items: [{ note: 'no title here' }] }) |
| 93 | + await openPanelWithClipboard(page, bad) |
| 94 | + |
| 95 | + const invalid = page.getByTestId('quick-panel-reply-invalid') |
| 96 | + await expect(invalid).toBeVisible() |
| 97 | + await expect(invalid).toContainText('title') |
| 98 | + |
| 99 | + await invalid.getByTestId('quick-panel-reply-copy-correction').click() |
| 100 | + await expect(invalid.getByTestId('quick-panel-reply-copy-correction')).toContainText('Copied') |
| 101 | + const raw = await page.evaluate(() => navigator.clipboard.readText()) |
| 102 | + const envelope = JSON.parse(raw) |
| 103 | + expect(envelope.kind).toBe('context') |
| 104 | + expect(envelope.instructions).toContain('did not validate') |
| 105 | + expect(envelope.schema.properties.action.enum).toContain('create-cards') |
| 106 | + }) |
| 107 | +}) |
0 commit comments