Skip to content

Commit 838fcf1

Browse files
committed
Add playwright test for image upload from clipboard
1 parent ae593bd commit 838fcf1

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

src/frontend/tests/pages/pui_part.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,54 @@ test('Parts - Details', async ({ browser }) => {
344344
await page.getByText('Latest Serial Number').waitFor();
345345
});
346346

347+
test('Parts - Details - Upload image modal accepts pasted clipboard image', async ({
348+
browser
349+
}) => {
350+
const page = await doCachedLogin(browser, { url: 'part/113/details' });
351+
352+
await page
353+
.getByRole('tabpanel', { name: 'Part Details' })
354+
.locator('img')
355+
.hover();
356+
await page.getByLabel('action-button-upload-new-image').first().click();
357+
await page.getByText('Upload Image', { exact: true }).waitFor();
358+
359+
await page.evaluate((pngBase64: string) => {
360+
const binary = atob(pngBase64);
361+
const bytes = new Uint8Array(binary.length);
362+
363+
for (let i = 0; i < binary.length; i++) {
364+
bytes[i] = binary.charCodeAt(i);
365+
}
366+
367+
const imageFile = new File([bytes], 'pasted.png', { type: 'image/png' });
368+
const dataTransfer = new DataTransfer();
369+
dataTransfer.items.add(imageFile);
370+
371+
const pasteEvent = new ClipboardEvent('paste', {
372+
bubbles: true,
373+
cancelable: true,
374+
clipboardData: dataTransfer
375+
});
376+
377+
document.dispatchEvent(pasteEvent);
378+
}, 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/w8AAusB9Y9x8WcAAAAASUVORK5CYII=');
379+
380+
await page.getByRole('button', { name: 'Submit' }).click();
381+
await page.getByText('The image has been uploaded successfully').waitFor();
382+
383+
// Now remove the associated image
384+
await page
385+
.getByRole('tabpanel', { name: 'Part Details' })
386+
.locator('img')
387+
.hover();
388+
await page
389+
.getByRole('button', { name: 'action-button-delete-image' })
390+
.click();
391+
await page.getByRole('button', { name: 'Remove' }).click();
392+
await page.getByText('The image has been removed successfully').waitFor();
393+
});
394+
347395
test('Parts - Requirements', async ({ browser }) => {
348396
// Navigate to the "Widget Assembly" part detail page
349397
// This part has multiple "variants"

0 commit comments

Comments
 (0)