Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/embed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"@orpc/server": "catalog:",
"@playwright/test": "^1.61.1",
"@solid-primitives/event-listener": "^2.4.6",
"@tanstack/router-core": "^1.171.14",
"@types/node": "^26.1.0",
"@unocss/postcss": "^66.7.2",
"@unocss/reset": "^66.7.2",
Expand Down
19 changes: 10 additions & 9 deletions packages/embed/tests/e2e/composer-rich-input.it.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {expect, test, type Page} from '@playwright/test'
import recorderServer from '@conciv/extension-recorder'
import {watchRpcWire} from '@conciv/extension-testkit/rpc-wire'
import {setupWidgetSuite} from './helpers/suite.js'
import {openPanel} from './helpers/panel.js'
import {openPanelOnNewSession} from './helpers/panel.js'
import {untilPanelDraft} from './helpers/drafts.js'

const ASSISTANT_TEXT = 'Rich input reply'
Expand All @@ -19,14 +19,15 @@ const suite = setupWidgetSuite({
const composer = (page: Page) => page.getByRole('textbox', {name: 'Message the conciv agent'})
const panel = (page: Page) => page.getByRole('dialog', {name: 'conciv chat agent'})

const waitForDraftWrite = (fragment: string) => untilPanelDraft(suite.kit(), (draft) => draft.text.includes(fragment))
const waitForDraftWrite = (sessionId: string, fragment: string) =>
untilPanelDraft(suite.kit(), sessionId, (draft) => draft.text.includes(fragment))

async function openComposer(page: Page): Promise<void> {
await page.goto(suite.host().base, {waitUntil: 'domcontentloaded'})
await openPanel(page)
async function openComposer(page: Page): Promise<string> {
const sessionId = await openPanelOnNewSession(page, suite)
const input = composer(page)
await input.click()
await expect(input).toHaveText('')
return sessionId
}

async function pickSuggestion(page: Page, listName: string, optionName: string): Promise<void> {
Expand Down Expand Up @@ -151,13 +152,13 @@ test.describe('the rich composer input in the live widget shadow DOM', () => {

test('a reload restores the draft as plain directive text with the caret at the end', async ({page}) => {
test.setTimeout(180_000)
await openComposer(page)
const sessionId = await openComposer(page)
const input = composer(page)

await input.pressSequentially('ship ')
await input.pressSequentially('/config')
await pickSuggestion(page, 'Commands', '/config')
await waitForDraftWrite('ship /config')
await waitForDraftWrite(sessionId, 'ship /config')

await page.reload({waitUntil: 'domcontentloaded'})
const restored = composer(page)
Expand All @@ -169,14 +170,14 @@ test.describe('the rich composer input in the live widget shadow DOM', () => {

test('a reload restores the caret where the draft left it, not at the end', async ({page}) => {
test.setTimeout(90_000)
await openComposer(page)
const sessionId = await openComposer(page)
const input = composer(page)

await input.pressSequentially('hello world')
for (let step = 0; step < 6; step += 1) await page.keyboard.press('ArrowLeft')
await input.pressSequentially('X')
await expect(input).toHaveText('helloX world')
await waitForDraftWrite('helloX world')
await waitForDraftWrite(sessionId, 'helloX world')

await page.reload({waitUntil: 'domcontentloaded'})
const restored = composer(page)
Expand Down
9 changes: 3 additions & 6 deletions packages/embed/tests/e2e/draft-selection.it.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import {expect, test} from '@playwright/test'
import {setupWidgetSuite} from './helpers/suite.js'
import {openPanel} from './helpers/panel.js'
import {panelSessionId} from './helpers/navigation.js'
import {openPanelOnNewSession} from './helpers/panel.js'
import {untilPanelDraft} from './helpers/drafts.js'

const suite = setupWidgetSuite()

test.describe('draft persistence carries the caret offsets', () => {
test('persists the draft text with the caret position after the debounce', async ({page}) => {
test.setTimeout(90_000)
await page.goto(suite.host().base, {waitUntil: 'domcontentloaded'})
await openPanel(page)
const sessionId = await openPanelOnNewSession(page, suite)

const input = page.getByRole('textbox', {name: 'Message the conciv agent'})
await input.click()
await input.pressSequentially('hello!')
for (let step = 0; step < 6; step += 1) await input.press('ArrowLeft')
await input.pressSequentially('say ')
await untilPanelDraft(suite.kit(), (draft) => draft.text === 'say hello!')
await untilPanelDraft(suite.kit(), sessionId, (draft) => draft.text === 'say hello!')

const sessionId = await panelSessionId(suite.kit())
expect(await suite.kit().rpc.drafts.get({sessionId})).toMatchObject({
text: 'say hello!',
selectionStart: 4,
Expand Down
15 changes: 6 additions & 9 deletions packages/embed/tests/e2e/helpers/drafts.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import type {DraftRow} from '@conciv/contract'
import {until} from '@conciv/harness-testkit/until'
import type {EmbedKit} from '../../helpers/boot.js'
import {panelSessionId} from './navigation.js'

export async function panelDraft(kit: EmbedKit): Promise<DraftRow | null> {
const sessionId = await panelSessionId(kit)
if (!sessionId) return null
return kit.rpc.drafts.get({sessionId})
}

export function untilPanelDraft(kit: EmbedKit, matches: (draft: DraftRow) => boolean): Promise<void> {
export function untilPanelDraft(
kit: EmbedKit,
sessionId: string,
matches: (draft: DraftRow) => boolean,
): Promise<void> {
return until(
async () => {
const draft = await panelDraft(kit)
const draft = await kit.rpc.drafts.get({sessionId})
return draft !== null && matches(draft)
},
{hangGuardMs: 30_000, intervalMs: 100},
Expand Down
24 changes: 0 additions & 24 deletions packages/embed/tests/e2e/helpers/navigation.ts

This file was deleted.

16 changes: 16 additions & 0 deletions packages/embed/tests/e2e/helpers/panel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {expect, type Page} from '@playwright/test'
import type {WidgetSuite} from './suite.js'

export async function openPanel(page: Page): Promise<void> {
const composer = page.getByRole('textbox', {name: 'Message the conciv agent'})
Expand All @@ -8,6 +9,21 @@ export async function openPanel(page: Page): Promise<void> {
await expect(composer).toBeVisible({timeout: 30_000})
}

export async function openPanelOnNewSession(page: Page, suite: WidgetSuite): Promise<string> {
const {sessionId} = await suite.kit().rpc.sessions.create()
const title = `session under test ${sessionId.slice(-12)}`
await suite.kit().rpc.sessions.rename({sessionId, title})
await page.goto(suite.host().base, {waitUntil: 'domcontentloaded'})
await openPanel(page)

await page.getByRole('button', {name: /^Session: /}).click()
const option = page.getByRole('option', {name: new RegExp(title)})
await expect(option).toBeVisible({timeout: 30_000})
await option.click()
await expect(page.getByRole('button', {name: `Session: ${title}`})).toBeVisible({timeout: 30_000})
return sessionId
}

export async function sendMessage(page: Page, text: string, reply: string): Promise<void> {
await page.getByRole('textbox', {name: 'Message the conciv agent'}).fill(text)
await page.getByRole('button', {name: 'Send message'}).click()
Expand Down
9 changes: 8 additions & 1 deletion packages/embed/tests/e2e/native-widget.it.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {DraftRow} from '@conciv/contract'
import {bootCoreKit, type CoreKit} from '@conciv/extension-testkit/core-kit'
import type {PageToNativeMessage} from '@conciv/extension-ios/bridge'
import {GRAB_MIME, parseGrabPayload, type GrabPayload} from '@conciv/grab/grab-attachment'
import {watchRpcWire} from '@conciv/extension-testkit/rpc-wire'
import {captureNativePosts, installNativeStub, type NativeBridge} from './helpers/native-bridge.js'
import {untilPanelDraft} from './helpers/drafts.js'

Expand Down Expand Up @@ -44,9 +45,11 @@ function grabPayloadOf(draft: DraftRow): GrabPayload | null {
}

let kit: CoreKit
let sessionId: string

test.beforeAll(async () => {
kit = await bootCoreKit({id: 'fake-native', text: 'Hello from conciv', nativePageDir: nativeDistDir})
sessionId = (await kit.rpc.sessions.create()).sessionId
})

test.afterAll(async () => {
Expand Down Expand Up @@ -119,7 +122,9 @@ test.describe('native widget bridge', () => {
})

test('opens the panel on native open and is idempotent, and closes on native close', async ({page: fixturePage}) => {
const wire = watchRpcWire(fixturePage)
const {page} = await openNative(fixturePage)
await wire.sessionsBootTraffic()
await callNative(page, 'open', {v: 1, seq: 1})
await callNative(page, 'open', {v: 1, seq: 2})
await expect(composerBox(page)).toHaveCount(1, {timeout: 30_000})
Expand All @@ -132,7 +137,9 @@ test.describe('native widget bridge', () => {
page: fixturePage,
}) => {
test.setTimeout(120_000)
const wire = watchRpcWire(fixturePage)
const {page, bridge} = await openNative(fixturePage)
await wire.sessionsBootTraffic()
const picked = Promise.withResolvers<PageToNativeMessage>()
bridge.notify = (message) => {
if (message.type === 'grab.pick') picked.resolve(message)
Expand All @@ -150,7 +157,7 @@ test.describe('native widget bridge', () => {
await callNative(page, 'grabResult', {v: 1, seq: 3, requestId: pick?.requestId, grab: NEUTRAL_GRAB})
await expect(panel(page).getByText('PaymentCardCell')).toBeVisible({timeout: 30_000})
await expect(grabPreview(page)).toHaveAttribute('src', IMAGE_DATA_URL)
await untilPanelDraft(kit, (draft) => {
await untilPanelDraft(kit, sessionId, (draft) => {
const payload = grabPayloadOf(draft)
return payload !== null && payload.text.includes('[view]') && payload.text.includes('PaymentCardCell')
})
Expand Down
9 changes: 3 additions & 6 deletions packages/embed/tests/e2e/reload-continuity.it.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {expect, test} from '@playwright/test'
import {setupWidgetSuite} from './helpers/suite.js'
import {openPanel} from './helpers/panel.js'
import {panelSessionId} from './helpers/navigation.js'
import {openPanelOnNewSession} from './helpers/panel.js'
import {untilPanelDraft} from './helpers/drafts.js'

const ASSISTANT_TEXT = 'Continuity reply'
Expand All @@ -11,8 +10,7 @@ const suite = setupWidgetSuite({text: ASSISTANT_TEXT})
test.describe('reload continuity through the db-backed navigation row', () => {
test('restores the open panel route, the transcript, and the draft after a reload', async ({page}) => {
test.setTimeout(240_000)
await page.goto(suite.host().base, {waitUntil: 'domcontentloaded'})
await openPanel(page)
const sessionId = await openPanelOnNewSession(page, suite)

const input = page.getByRole('textbox', {name: 'Message the conciv agent'})
await input.fill('remember me')
Expand All @@ -21,9 +19,8 @@ test.describe('reload continuity through the db-backed navigation row', () => {

await input.fill('an unsent draft survives')
await input.press('End')
await untilPanelDraft(suite.kit(), (draft) => draft.text === 'an unsent draft survives')
await untilPanelDraft(suite.kit(), sessionId, (draft) => draft.text === 'an unsent draft survives')

const sessionId = await panelSessionId(suite.kit())
expect(await suite.kit().rpc.drafts.get({sessionId})).toMatchObject({text: 'an unsent draft survives'})

await page.reload({waitUntil: 'domcontentloaded'})
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading