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
6 changes: 6 additions & 0 deletions browser_tests/fixtures/components/AgentPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Locator> {
if (await this.root.isVisible()) return this.root

Expand Down
37 changes: 36 additions & 1 deletion browser_tests/tests/agent/agentComposerAssetDrop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }, () => {
Expand Down Expand Up @@ -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:/)
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
expect(await screen.findByLabelText(name, { selector })).toHaveAttribute(
Expand Down
Loading