mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2026-06-10 11:16:48 +00:00
fix test
This commit is contained in:
+42
-38
@@ -1,64 +1,68 @@
|
|||||||
import { test, expect } from '@playwright/test'
|
import { expect, test } from "@playwright/test";
|
||||||
import { readFile } from 'node:fs/promises'
|
import { readFile } from "node:fs/promises";
|
||||||
import { getFileChecksum } from '../../files'
|
import { getFileChecksum } from "../../files";
|
||||||
import { checkLinkForDownload } from '../../utils'
|
|
||||||
|
|
||||||
const IMG_PATH = 'test/assets/image.jpg'
|
const IMG_PATH = "test/assets/image.jpg";
|
||||||
|
|
||||||
test.describe('@web', () => {
|
test.describe("@web", () => {
|
||||||
test('paste image', async ({ page, browserName }) => {
|
test("paste image", async ({ page, browserName }) => {
|
||||||
test.skip(browserName !== 'chromium', 'DataTransfer.items.add(File) is only supported in Chromium')
|
test.skip(
|
||||||
const checksum = await getFileChecksum(IMG_PATH)
|
browserName !== "chromium",
|
||||||
const imgBuffer = await readFile(IMG_PATH)
|
"DataTransfer.items.add(File) is only supported in Chromium",
|
||||||
const imgBase64 = imgBuffer.toString('base64')
|
);
|
||||||
|
const checksum = await getFileChecksum(IMG_PATH);
|
||||||
|
const imgBuffer = await readFile(IMG_PATH);
|
||||||
|
const imgBase64 = imgBuffer.toString("base64");
|
||||||
|
|
||||||
await page.goto('/')
|
await page.goto("/");
|
||||||
await page.waitForSelector('form')
|
await page.waitForSelector("form");
|
||||||
|
|
||||||
// Create a paste event with clipboardData containing the image file
|
// Create a paste event with clipboardData containing the image file
|
||||||
await page.evaluate(
|
await page.evaluate(
|
||||||
async ({ base64, mimeType }) => {
|
async ({ base64, mimeType }) => {
|
||||||
const response = await fetch(`data:${mimeType};base64,${base64}`)
|
const response = await fetch(`data:${mimeType};base64,${base64}`);
|
||||||
const blob = await response.blob()
|
const blob = await response.blob();
|
||||||
const file = new File([blob], 'image.jpg', { type: mimeType })
|
const file = new File([blob], "image.jpg", { type: mimeType });
|
||||||
|
|
||||||
const dt = new DataTransfer()
|
const dt = new DataTransfer();
|
||||||
dt.items.add(file)
|
dt.items.add(file);
|
||||||
|
|
||||||
const event = new ClipboardEvent('paste', {
|
const event = new ClipboardEvent("paste", {
|
||||||
bubbles: true,
|
bubbles: true,
|
||||||
cancelable: true,
|
cancelable: true,
|
||||||
clipboardData: dt,
|
clipboardData: dt,
|
||||||
})
|
});
|
||||||
|
|
||||||
document.querySelector('form')?.dispatchEvent(event)
|
document.querySelector("form")?.dispatchEvent(event);
|
||||||
},
|
},
|
||||||
{ base64: imgBase64, mimeType: 'image/jpeg' },
|
{ base64: imgBase64, mimeType: "image/jpeg" },
|
||||||
)
|
);
|
||||||
|
|
||||||
// Wait for the paste to process and preview to appear
|
// Wait for the paste to process and preview to appear
|
||||||
await expect(page.locator('.pasted-images-preview')).toBeVisible({ timeout: 5000 })
|
await expect(page.locator(".pasted-files-preview")).toBeVisible({
|
||||||
|
timeout: 5000,
|
||||||
|
});
|
||||||
|
|
||||||
// Create the note
|
// Create the note
|
||||||
await page.locator('button:has-text("create")').click()
|
await page.locator('button:has-text("create")').click();
|
||||||
const link = await page.getByTestId('share-link').inputValue()
|
const link = await page.getByTestId("share-link").inputValue();
|
||||||
|
|
||||||
// Navigate to the note and reveal it
|
// Navigate to the note and reveal it
|
||||||
await page.goto('/')
|
await page.goto("/");
|
||||||
await page.goto(link)
|
await page.goto(link);
|
||||||
await page.getByTestId('show-note-button').click()
|
await page.getByTestId("show-note-button").click();
|
||||||
|
|
||||||
// Verify image preview is visible
|
// Verify image preview is visible
|
||||||
await expect(page.locator('img.preview')).toBeVisible({ timeout: 5000 })
|
await expect(page.locator("img.preview")).toBeVisible({ timeout: 5000 });
|
||||||
|
|
||||||
// Download and verify checksum
|
// Download and verify checksum
|
||||||
const [download] = await Promise.all([
|
const [download] = await Promise.all([
|
||||||
page.waitForEvent('download'),
|
page.waitForEvent("download"),
|
||||||
page.locator('[data-testid="result"] button').first().click(),
|
page.locator('[data-testid="result"] button').first().click(),
|
||||||
])
|
]);
|
||||||
const path = await download.path()
|
const path = await download.path();
|
||||||
if (!path) throw new Error('Download failed')
|
if (!path) throw new Error("Download failed");
|
||||||
const cs = await getFileChecksum(path)
|
const cs = await getFileChecksum(path);
|
||||||
expect(cs).toBe(checksum)
|
expect(cs).toBe(checksum);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user