diff --git a/browser_tests/fixtures/components/AgentPanel.ts b/browser_tests/fixtures/components/AgentPanel.ts index 2cf1ba647a1..9b2388473f6 100644 --- a/browser_tests/fixtures/components/AgentPanel.ts +++ b/browser_tests/fixtures/components/AgentPanel.ts @@ -139,6 +139,12 @@ export class AgentPanel { ) } + attachmentPreviewPlayer(name: string): Locator { + return this.page + .getByLabel(name, { exact: true }) + .and(this.page.locator('video, audio')) + } + async open(timeout?: number): Promise { if (await this.root.isVisible()) return this.root diff --git a/browser_tests/tests/agent/agentComposerAssetDrop.spec.ts b/browser_tests/tests/agent/agentComposerAssetDrop.spec.ts index 26cf330b2a2..19cf59fd8e7 100644 --- a/browser_tests/tests/agent/agentComposerAssetDrop.spec.ts +++ b/browser_tests/tests/agent/agentComposerAssetDrop.spec.ts @@ -18,7 +18,8 @@ import { assetPath } from '@e2e/fixtures/utils/paths' // The drop side accepts a drop purely on `dataTransfer.types` containing // `application/x-comfy-asset-info` (`AgentPanelRoot` `isAssetDrag`), so it is // view-agnostic by construction; what these cases pin is that every view mode -// actually publishes that payload, and that the chip names the asset dragged. +// actually publishes that payload, that the chip names the asset dragged, and +// that a dropped MP4's chip previews it with a generated poster. const ASSET_NAME = AGENT_VIDEO_ASSET.name test.describe('Agent composer asset drop', { tag: '@cloud' }, () => { @@ -71,6 +72,40 @@ test.describe('Agent composer asset drop', { tag: '@cloud' }, () => { }) } + test( + 'previews a video from the keyboard and restores focus on Escape', + { tag: '@ui' }, + async ({ page }) => { + const agentPanel = new AgentPanel(page) + await agentPanel.open() + + const assets = new AssetsSidebarTab(page) + await assets.open() + await assets.assetCards.first().dragTo(agentPanel.root) + + const chip = agentPanel.attachmentChip(ASSET_NAME) + const trigger = chip.getByRole('button', { name: ASSET_NAME }) + const poster = trigger.getByRole('img', { name: ASSET_NAME }) + await expect(poster).toBeVisible() + await expect(poster).toHaveAttribute('src', /^blob:/) + await expect + .poll(() => + poster.evaluate((image: HTMLImageElement) => image.naturalWidth) + ) + .toBeGreaterThan(0) + + await trigger.press('Enter') + + const player = agentPanel.attachmentPreviewPlayer(ASSET_NAME) + await expect(player).toBeVisible() + await expect(player).toBeFocused() + + await page.keyboard.press('Escape') + await expect(player).toHaveCount(0) + await expect(trigger).toBeFocused() + } + ) + // A filename is user data and may contain a quote or a backslash, which would // break the attribute selector the chip is matched by. Exercised end to end // rather than unit-tested, so a regression in the escaping shows up as the diff --git a/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.test.ts b/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.test.ts index 749e2cbd623..083721062f2 100644 --- a/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.test.ts +++ b/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.test.ts @@ -54,6 +54,9 @@ describe('AttachmentChip', () => { expect(trigger).toHaveFocus() await user.keyboard(key) expect(await screen.findByRole('dialog', { name })).toBeVisible() + await waitFor(() => + expect(trigger).toHaveAttribute('aria-expanded', 'true') + ) const player = screen.getByLabelText(name, { selector }) assert.instanceOf(player, HTMLMediaElement) await waitFor(() => expect(player).toHaveFocus()) @@ -63,6 +66,7 @@ describe('AttachmentChip', () => { await user.keyboard('{Escape}') await waitFor(() => expect(player).not.toBeInTheDocument()) await waitFor(() => expect(trigger).toHaveFocus()) + expect(trigger).toHaveAttribute('aria-expanded', 'false') expect(pause).toHaveBeenCalledOnce() await user.keyboard(key) expect(await screen.findByLabelText(name, { selector })).toHaveAttribute(