Repository navigation
[backport core/1.54] cover reference-only attachment-history previews #19342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cd4d2e6
test: cover reference-only attachment history previews (#18247)
christian-byrne 4dadd80
Merge remote-tracking branch 'origin/core/1.54' into backport/18247-c…
christian-byrne 3f9dbed
test: use stable attachment preview selector
christian-byrne 241e718
test(agent): harden attachment history coverage
christian-byrne a13bf8e
test(agent): share the preview assertion deadline
christian-byrne 5936540
chore: merge core/1.54 into backport branch
christian-byrne ec7893a
fix: keep core 1.54 attachment backport test-only
christian-byrne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import { expect } from '@playwright/test' | ||
| import type { Locator, Page } from '@playwright/test' | ||
|
|
||
| import { MIME_ASSET_INFO } from '@/platform/assets/schemas/mediaAssetSchema' | ||
| import type { | ||
| MediaKind, | ||
| parseAssetInfo | ||
| } from '@/platform/assets/schemas/mediaAssetSchema' | ||
|
|
||
| type DraggedAssetInfo = NonNullable<ReturnType<typeof parseAssetInfo>> | ||
|
|
||
| export interface ExpectedAssetPreview { | ||
| filename: string | ||
| ref?: string | ||
| kind: Extract<MediaKind, 'image' | 'video'> | ||
| width?: number | ||
| height?: number | ||
| } | ||
|
|
||
| export async function dropAssets( | ||
| page: Page, | ||
| target: Locator, | ||
| assets: ExpectedAssetPreview[], | ||
| type: DraggedAssetInfo['type'] = 'output' | ||
| ) { | ||
| for (const { filename, ref = filename, kind } of assets) { | ||
| const payload: DraggedAssetInfo = { | ||
| filename, | ||
| subfolder: '', | ||
| type, | ||
| display_name: filename, | ||
| attachment_ref: ref, | ||
| media_kind: kind | ||
| } | ||
| const dataTransfer = await page.evaluateHandle( | ||
| ({ mime, payload }) => { | ||
| const transfer = new DataTransfer() | ||
| transfer.setData(mime, JSON.stringify(payload)) | ||
| return transfer | ||
| }, | ||
| { mime: MIME_ASSET_INFO, payload } | ||
| ) | ||
| await target.dispatchEvent('drop', { dataTransfer }) | ||
| await dataTransfer.dispose() | ||
| } | ||
| } | ||
|
|
||
| export async function expectAssets( | ||
| panel: Locator, | ||
| assets: ExpectedAssetPreview[], | ||
| timeout = 10_000 | ||
| ) { | ||
| const deadline = Date.now() + timeout | ||
| const remaining = () => Math.max(1, deadline - Date.now()) | ||
| const userMessage = panel | ||
| .getByTestId('user-message-bubble') | ||
| .last() | ||
| .locator('..') | ||
| const previews = userMessage | ||
| .getByTestId('reply-asset-group') | ||
| .locator('img, video') | ||
| await expect(previews).toHaveCount(assets.length, { timeout: remaining() }) | ||
| for (const [index, asset] of assets.entries()) { | ||
| const preview = previews.nth(index) | ||
| await expect(preview).toBeVisible({ timeout: remaining() }) | ||
| await expect(preview.locator('..')).toHaveAccessibleName(asset.filename, { | ||
| timeout: remaining() | ||
| }) | ||
| await expect | ||
| .poll( | ||
| () => | ||
| preview.evaluate((element) => | ||
| element instanceof HTMLImageElement | ||
| ? element.naturalWidth > 0 && element.naturalHeight > 0 | ||
| : element instanceof HTMLVideoElement | ||
| ? element.videoWidth > 0 && element.videoHeight > 0 | ||
| : false | ||
| ), | ||
| { timeout: remaining() } | ||
| ) | ||
| .toBe(true) | ||
| } | ||
| await expect | ||
| .poll( | ||
| () => | ||
| previews.evaluateAll((elements) => | ||
| elements.map((element) => { | ||
| if (element instanceof HTMLImageElement) { | ||
| return { | ||
| kind: 'image', | ||
| label: element.alt, | ||
| ref: new URL( | ||
| element.currentSrc, | ||
| location.href | ||
| ).searchParams.get('filename'), | ||
| width: element.naturalWidth, | ||
| height: element.naturalHeight | ||
| } | ||
| } | ||
| if (element instanceof HTMLVideoElement) { | ||
| return { | ||
| label: element.parentElement?.getAttribute('aria-label'), | ||
| ref: element.currentSrc | ||
| ? new URL(element.currentSrc, location.href).searchParams.get( | ||
| 'filename' | ||
| ) | ||
| : null, | ||
| kind: 'video', | ||
| width: element.videoWidth, | ||
| height: element.videoHeight | ||
| } | ||
| } | ||
| return null | ||
| }) | ||
| ), | ||
| { timeout: remaining() } | ||
| ) | ||
| .toEqual( | ||
| assets.map(({ filename, ref = filename, kind, width, height }) => ({ | ||
| kind, | ||
| label: filename, | ||
| ref, | ||
| width: width ?? expect.any(Number), | ||
| height: height ?? expect.any(Number) | ||
| })) | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.