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
8 changes: 3 additions & 5 deletions shell/e2e/a2a-inline-surface-order.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import {expect, test, type Page} from '@playwright/test';
import {connectMockAgent} from '../src/app/agent-chat/test/mock-a2a-agent';
import {RENDERER_URLS} from './helpers';
import {inlineSurfaceFrame} from '../src/app/preview/testing/preview-frame-locators';
import {RENDERER_URLS} from '../src/app/preview/testing/renderer-urls';

const AGENT_URL = 'http://mock-agent.local';

Expand Down Expand Up @@ -82,10 +83,7 @@ function bubbleBlockOrder(page: Page, index: number): Promise<string[]> {
}

async function expectInlineSurface(page: Page, index: number, text: string) {
const frame = page
.locator('.inline-surface-card iframe.preview-iframe')
.nth(index)
.contentFrame();
const frame = inlineSurfaceFrame(page, index);
await expect(frame.locator('body')).toContainText(text, {timeout: SURFACE_RENDER_TIMEOUT_MS});
}

Expand Down
43 changes: 20 additions & 23 deletions shell/e2e/a2a-multi-frame-surfaces.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

import {expect, test, type FrameLocator, type Page} from '@playwright/test';
import {connectMockAgent, sseEvent} from '../src/app/agent-chat/test/mock-a2a-agent';
import {RENDERER_URLS} from './helpers';
import {
inlineSurfaceFrame,
sideCanvasFrame,
} from '../src/app/preview/testing/preview-frame-locators';
import {RENDERER_URLS} from '../src/app/preview/testing/renderer-urls';

const AGENT_URL = 'http://mock-agent.local';

Expand Down Expand Up @@ -85,15 +89,6 @@ async function sendPrompt(page: Page, text: string) {
await prompt.press('Enter');
}

/** The guest document of the n-th inline surface in the transcript (0-based). */
function inlineFrame(page: Page, index: number): FrameLocator {
return page.locator('.inline-surface-card iframe.preview-iframe').nth(index).contentFrame();
}

function canvasFrame(page: Page): FrameLocator {
return page.locator('.side-canvas-viewport iframe.preview-iframe').contentFrame();
}

async function expectSurface(frame: FrameLocator, text: string) {
await expect(frame.locator('body')).toContainText(text, {timeout: SURFACE_RENDER_TIMEOUT_MS});
}
Expand All @@ -116,7 +111,7 @@ test('inline surfaces keep their own content while the side canvas is opened and
await sendPrompt(page, 'turn one');
await expect(page.locator('.agent-text-content')).toContainText('Reply for turn 1.');
await expect(page.locator('.inline-surface-card')).toHaveCount(1);
await expectSurface(inlineFrame(page, 0), 'INLINE SURFACE #1');
await expectSurface(inlineSurfaceFrame(page, 0), 'INLINE SURFACE #1');

// Opening canvas #1 mounts a second frame. Its payload must reach that
// frame only: the inline frame, which was the default dispatch target until
Expand All @@ -126,28 +121,30 @@ test('inline surfaces keep their own content while the side canvas is opened and
// down. The permanent variant of the same misrouting is covered below.
await page.getByRole('button', {name: 'View Turn 1 details in Canvas'}).click();
await expect(page.locator('.side-canvas-column')).toBeVisible();
await expectSurface(canvasFrame(page), 'CANVAS CONTENT #1');
await expectSurface(inlineFrame(page, 0), 'INLINE SURFACE #1');
await expect(inlineFrame(page, 0).locator('body')).not.toContainText('CANVAS CONTENT');
await expectSurface(sideCanvasFrame(page), 'CANVAS CONTENT #1');
await expectSurface(inlineSurfaceFrame(page, 0), 'INLINE SURFACE #1');
await expect(inlineSurfaceFrame(page, 0).locator('body')).not.toContainText('CANVAS CONTENT');

// Turn 2 arrives while the canvas is open and mounts a new inline frame,
// which becomes the newest frame. Nothing already on screen may change.
await sendPrompt(page, 'turn two');
await expect(page.locator('.inline-surface-card')).toHaveCount(2);
await expectSurface(inlineFrame(page, 1), 'INLINE SURFACE #2');
await expectSurface(inlineFrame(page, 0), 'INLINE SURFACE #1');
await expectSurface(canvasFrame(page), 'CANVAS CONTENT #1');
await expectSurface(inlineSurfaceFrame(page, 1), 'INLINE SURFACE #2');
await expectSurface(inlineSurfaceFrame(page, 0), 'INLINE SURFACE #1');
await expectSurface(sideCanvasFrame(page), 'CANVAS CONTENT #1');

// Opening canvas #2 replaces the canvas payload. Before readiness was
// tracked per frame this payload also went to the newest frame, so the
// turn-2 inline surface was overwritten with the canvas content for good.
await page.getByRole('button', {name: 'View Turn 2 details in Canvas'}).click();
await expectSurface(canvasFrame(page), 'CANVAS CONTENT #2');
await expectSurface(inlineFrame(page, 1), 'INLINE SURFACE #2');
await expectSurface(inlineFrame(page, 0), 'INLINE SURFACE #1');
await expectSurface(sideCanvasFrame(page), 'CANVAS CONTENT #2');
await expectSurface(inlineSurfaceFrame(page, 1), 'INLINE SURFACE #2');
await expectSurface(inlineSurfaceFrame(page, 0), 'INLINE SURFACE #1');
for (const index of [0, 1]) {
await expect(inlineFrame(page, index).locator('body')).not.toContainText('CANVAS CONTENT');
await expect(inlineSurfaceFrame(page, index).locator('body')).not.toContainText(
'CANVAS CONTENT',
);
}
await expect(canvasFrame(page).locator('body')).not.toContainText('CANVAS CONTENT #1');
await expect(canvasFrame(page).locator('body')).not.toContainText('INLINE SURFACE');
await expect(sideCanvasFrame(page).locator('body')).not.toContainText('CANVAS CONTENT #1');
await expect(sideCanvasFrame(page).locator('body')).not.toContainText('INLINE SURFACE');
});
21 changes: 11 additions & 10 deletions shell/e2e/copilot-assistant.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
setGeminiScenarios,
splitTextIntoGeminiChunks,
} from './helpers/gemini-fixture';
import {RENDERER_URLS} from './helpers';
import {previewFrame} from '../src/app/preview/testing/preview-frame-locators';
import {RENDERER_URLS} from '../src/app/preview/testing/renderer-urls';

const DRAFT_TEXT = 'Ready to use from my selected catalog';
const MODEL_TEXT = 'Updated by deterministic Gemini fixture';
Expand Down Expand Up @@ -106,7 +107,7 @@ async function openDraftInWorkspace(page: Page): Promise<void> {
);

await expect(
page.frameLocator('.workspace-container iframe').getByText(DRAFT_TEXT),
previewFrame(page.locator('.workspace-container')).getByText(DRAFT_TEXT),
).toBeVisible();
await expect.poll(() => readRawDraft(page)).toContain(DRAFT_TEXT);
}
Expand Down Expand Up @@ -172,7 +173,7 @@ async function openSampleInWorkspace(page: Page): Promise<void> {
await page.goto(`/?renderer=${RENDERER_URLS.angular}`);
await expect(page.locator('.header-title')).toContainText('my_basic_catalog');
await expect(
page.frameLocator('.workspace-container iframe').getByText('Book a Car'),
previewFrame(page.locator('.workspace-container')).getByText('Book a Car'),
).toBeVisible();
}

Expand Down Expand Up @@ -363,7 +364,7 @@ test.describe('Copilot assistant replacement browser journey', () => {
);

await expect(
page.frameLocator('.workspace-container iframe').getByText(MODEL_TEXT),
previewFrame(page.locator('.workspace-container')).getByText(MODEL_TEXT),
).toBeVisible();
await expect(chatHistory(page)).toContainText('1 component in this canvas');
await expect.poll(() => readRawDraft(page)).toContain(MODEL_TEXT);
Expand All @@ -384,7 +385,7 @@ test.describe('Copilot assistant replacement browser journey', () => {
const editedDraft = replaceDraftText(await readRawDraft(page), 'Book a Car', MODEL_TEXT);
await setGeminiScenarios(page, [{chunks: splitTextIntoGeminiChunks(editedDraft)}]);
await submitPrompt(page, prompt);
const preview = page.frameLocator('.workspace-container iframe');
const preview = previewFrame(page.locator('.workspace-container'));
await expect(preview.getByText(MODEL_TEXT)).toBeVisible();
await expect(chatHistory(page)).toContainText('7 components in this canvas');

Expand All @@ -411,7 +412,7 @@ test.describe('Copilot assistant replacement browser journey', () => {

await expect(page.locator('.header-title')).toContainText('Basic Catalog');
await expect(
page.frameLocator('.workspace-container iframe').getByText(LIT_SAMPLE_TEXT),
previewFrame(page.locator('.workspace-container')).getByText(LIT_SAMPLE_TEXT),
).toBeVisible();
await expect.poll(() => readRawDraft(page)).toContain(LIT_SAMPLE_TEXT);
await expect(page.locator('a2ui-composer-chat-panel').getByText(reply)).toBeHidden();
Expand All @@ -431,7 +432,7 @@ test.describe('Copilot assistant replacement browser journey', () => {

await expect(parseErrorCard(page)).toBeVisible();
await expect(
page.frameLocator('.workspace-container iframe').getByText(DRAFT_TEXT),
previewFrame(page.locator('.workspace-container')).getByText(DRAFT_TEXT),
).toBeVisible();
await expect.poll(() => readRawDraft(page)).toBe(originalDraft);
await expectGeminiRequestForCurrentDraft(page, DRAFT_TEXT);
Expand All @@ -440,7 +441,7 @@ test.describe('Copilot assistant replacement browser journey', () => {
await submitPrompt(page, 'Recover with valid A2UI JSON for the same selected draft.');

await expect(
page.frameLocator('.workspace-container iframe').getByText(RECOVERY_TEXT),
previewFrame(page.locator('.workspace-container')).getByText(RECOVERY_TEXT),
).toBeVisible();
await expect.poll(() => readRawDraft(page)).toContain(RECOVERY_TEXT);
await expectGeminiRequestForCurrentDraft(page, DRAFT_TEXT);
Expand Down Expand Up @@ -502,7 +503,7 @@ test.describe('Copilot assistant replacement browser journey', () => {
]);
await submitPrompt(page, 'Update the selected text');
await expect(
page.frameLocator('.workspace-container iframe').getByText(MODEL_TEXT, {exact: true}),
previewFrame(page.locator('.workspace-container')).getByText(MODEL_TEXT, {exact: true}),
).toBeVisible();
await expect.poll(() => readRawDraft(page)).toContain('createSurface');
await expectGeminiRequestForCurrentDraft(page, DRAFT_TEXT);
Expand All @@ -525,7 +526,7 @@ test.describe('Copilot assistant replacement browser journey', () => {

await expect(chatHistory(page)).toContainText('You stopped this response');
await expect(
page.frameLocator('.workspace-container iframe').getByText(DRAFT_TEXT),
previewFrame(page.locator('.workspace-container')).getByText(DRAFT_TEXT),
).toBeVisible();
await expect.poll(() => readRawDraft(page)).toBe(originalDraft);
await expectGeminiRequestForCurrentDraft(page, DRAFT_TEXT);
Expand Down
11 changes: 6 additions & 5 deletions shell/e2e/debug-drawer-and-logs.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import {test, expect} from '@playwright/test';
import {PreviewBridgeMessageType} from 'a2ui-bridge';
import {previewFrame} from '../src/app/preview/testing/preview-frame-locators';

test.beforeEach(async ({page}) => {
page.on('pageerror', err => {
Expand Down Expand Up @@ -56,7 +57,7 @@ test.beforeEach(async ({page}) => {

test.describe('Debugging Panels & Diagnostic Logs', () => {
test('verifies diagnostic logs routing', async ({page}) => {
const iframeBody = page.frameLocator('iframe.preview-iframe').locator('body');
const iframeBody = previewFrame(page).locator('body');
await expect(iframeBody).toBeVisible();

const clickMsg = {
Expand Down Expand Up @@ -117,7 +118,7 @@ test.describe('Debugging Panels & Diagnostic Logs', () => {
});

test('verifies console log warning routing from preview frame to Errors tab', async ({page}) => {
const iframeBody = page.frameLocator('iframe.preview-iframe').locator('body');
const iframeBody = previewFrame(page).locator('body');
await expect(iframeBody).toBeVisible();

const logMsg = {
Expand Down Expand Up @@ -145,7 +146,7 @@ test.describe('Debugging Panels & Diagnostic Logs', () => {
const errorsTabLabel = page.locator('.dv-tab', {hasText: /^Errors/});
await expect(errorsTabLabel).not.toContainText('(1)');

const iframeBody = page.frameLocator('iframe.preview-iframe').locator('body');
const iframeBody = previewFrame(page).locator('body');
await expect(iframeBody).toBeVisible();

const unreadClickMsg = {
Expand Down Expand Up @@ -196,7 +197,7 @@ test.describe('Debugging Panels & Diagnostic Logs', () => {
const rawMessagesTabLabel = page.locator('.dv-tab', {hasText: /^Raw Messages/});
const dataModelField = page.locator('.data-model-field textarea');

const iframeBody = page.frameLocator('iframe.preview-iframe').locator('body');
const iframeBody = previewFrame(page).locator('body');
await expect(iframeBody).toBeVisible();

await iframeBody.evaluate(
Expand Down Expand Up @@ -331,7 +332,7 @@ test.describe('Debugging Panels & Diagnostic Logs', () => {
test('hides expanded raw message payload when switching to another debug tab and restores visibility on return', async ({
page,
}) => {
const iframeBody = page.frameLocator('iframe.preview-iframe').locator('body');
const iframeBody = previewFrame(page).locator('body');
await expect(iframeBody).toBeVisible();

const clickMsg = {
Expand Down
7 changes: 4 additions & 3 deletions shell/e2e/demo-card-commit-accuracy.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
type TestInfo,
} from '@playwright/test';
import {MAX_CONTENT_HEIGHT_PX} from '../src/app/preview/content-height';
import {DEMO_CARD_SELECTORS} from '../src/app/demos/test/demo-card-selectors';
import {
COMMIT_TOLERANCE_PX,
DEMO_CARD_COUNT,
Expand Down Expand Up @@ -149,8 +150,8 @@ function cardByKey(page: Page, key: string): Locator {

/** The card's committed frame height and the reports its frames sent. */
function cardState(card: Locator) {
return card.evaluate(host => {
const iframe = host.querySelector<HTMLIFrameElement>('iframe.demo-card-frame');
return card.evaluate((host, iframeSelector) => {
const iframe = host.querySelector<HTMLIFrameElement>(iframeSelector);
const allReports = (window as WindowWithSurfaceReports).__surfaceReports ?? [];
const reports = allReports.filter(
report => iframe !== null && report.source === iframe.contentWindow,
Expand All @@ -177,7 +178,7 @@ function cardState(card: Locator) {
),
error: host.querySelector('.demo-card-error') !== null,
};
});
}, DEMO_CARD_SELECTORS.iframe);
}

function expectedHeight(content: number): number {
Expand Down
26 changes: 12 additions & 14 deletions shell/e2e/demo-card-locked-height.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/

import {test, expect, type Locator, type Page} from '@playwright/test';
import {RENDERER_URLS} from './helpers';
import {DEMO_CARD_SELECTORS} from '../src/app/demos/test/demo-card-selectors';
import {demoCardFrame, demoCardIframe} from '../src/app/preview/testing/preview-frame-locators';
import {RENDERER_URLS} from '../src/app/preview/testing/renderer-urls';
import {
COMMIT_TOLERANCE_PX,
DEMO_RENDERERS,
Expand Down Expand Up @@ -92,21 +94,19 @@ async function settledLayout(page: Page): Promise<Record<string, CardBox>> {

/** The tallest SURFACE_RESIZE height the card's current frame has sent. */
function tallestReport(card: Locator): Promise<number> {
return card.evaluate(host => {
const frame = host.querySelector<HTMLIFrameElement>('iframe.demo-card-frame');
return card.evaluate((host, iframeSelector) => {
const frame = host.querySelector<HTMLIFrameElement>(iframeSelector);
const reports = (window as WindowWithSurfaceReports).__surfaceReports ?? [];
return Math.max(
0,
...reports.filter(report => report.source === frame?.contentWindow).map(r => r.height),
);
});
}, DEMO_CARD_SELECTORS.iframe);
}

/** The guest document's scroll geometry. */
function guestScroll(card: Locator) {
return card
.locator('iframe.demo-card-frame')
.contentFrame()
return demoCardFrame(card)
.locator('html')
.evaluate(root => ({
scrollHeight: root.scrollHeight,
Expand Down Expand Up @@ -147,9 +147,7 @@ for (const renderer of DEMO_RENDERERS) {
// (their validation messages, tabs and modals keep the document's height), so the
// demo grows the way a late image or an expanding section would: content is added
// to its document after the card has committed.
await card
.locator('iframe.demo-card-frame')
.contentFrame()
await demoCardFrame(card)
.locator('body')
.evaluate(body => {
const growth = document.createElement('div');
Expand All @@ -173,7 +171,7 @@ for (const renderer of DEMO_RENDERERS) {
expect(await settledLayout(page)).toEqual(before);

// The demo scrolls inside the card instead.
const frameElement = card.locator('iframe.demo-card-frame');
const frameElement = demoCardIframe(card);
await expect(async () => {
await frameElement.scrollIntoViewIfNeeded();
const box = await frameElement.boundingBox();
Expand All @@ -200,7 +198,7 @@ for (const renderer of DEMO_RENDERERS) {
const scroller = page.locator('.demos-container');
await expect(async () => {
await scroller.evaluate(element => element.scrollTo(0, element.scrollHeight));
await expect(card.locator('iframe.demo-card-frame')).toHaveCount(0, {timeout: 1000});
await expect(demoCardIframe(card)).toHaveCount(0, {timeout: 1000});
}).toPass({timeout: 30_000});
expect((await wallLayout(page))[key]).toEqual(box);

Expand Down Expand Up @@ -235,7 +233,7 @@ test.describe('Demo cards after a renderer change', () => {
const cards = page.locator('a2ui-composer-demo-card');
const first = cards.first();
await revealCard(first);
await expect(first.locator('iframe.demo-card-frame')).toHaveAttribute(
await expect(demoCardIframe(first)).toHaveAttribute(
'src',
new RegExp(`^${RENDERER_URLS.angular}`),
);
Expand All @@ -255,7 +253,7 @@ test.describe('Demo cards after a renderer change', () => {
for (let index = 0; index < 4; index++) {
const card = cards.nth(index);
await revealCard(card);
await expect(card.locator('iframe.demo-card-frame')).toHaveAttribute(
await expect(demoCardIframe(card)).toHaveAttribute(
'src',
new RegExp(`^${RENDERER_URLS.lit}`),
);
Expand Down
Loading
Loading