diff --git a/apps/web/e2e/README.md b/apps/web/e2e/README.md index a1c669e9..b6c3afb6 100644 --- a/apps/web/e2e/README.md +++ b/apps/web/e2e/README.md @@ -47,6 +47,7 @@ apps/web/e2e/ | `image` | `test-file-.png` | | | `video` | `test-file-.mp4` | | | `pdf` | `test-file-.pdf` | | + | `audio` | `test-file-.wav` | | ## Test Cases @@ -76,8 +77,18 @@ apps/web/e2e/ | Owner drags a file onto a file to create a version stack | `tests/project/version-stack-create.spec.ts` | | Owner drags a file onto a version stack to add a new version | `tests/project/version-stack-add-version.spec.ts` | +### file +| Test | File | +|---|---| +| Create a comment on a binary file | `tests/file/binary-comment.spec.ts` | +| Upload a txt file, wait for transcode, and create a comment with draw | `tests/file/txt-draw-comment.spec.ts` | +| Upload an image file, wait for transcode, and create a comment with draw | `tests/file/image-draw-comment.spec.ts` | +| Upload a video file, wait for transcode, and create a comment with draw at a non-zero timestamp | `tests/file/video-draw-comment.spec.ts` | +| Upload an audio file, wait for transcode, and create a comment at a non-zero timestamp | `tests/file/audio-timestamp-comment.spec.ts` | + ## Conventions + - Seed data via fixtures/API/DB; use the UI only for the flow under test. - Each test truncates all tables via the auto `prisma` fixture, so fixtures must create their data per-test. diff --git a/apps/web/e2e/fixtures.ts b/apps/web/e2e/fixtures.ts index b48138b2..4348f5a3 100644 --- a/apps/web/e2e/fixtures.ts +++ b/apps/web/e2e/fixtures.ts @@ -15,9 +15,11 @@ import { uniqueEmail, } from './helpers/auth' import { apiCreateProject, uniqueProjectName } from './helpers/project' +import { apiUploadFile } from './helpers/files' const currentDir = path.dirname(fileURLToPath(import.meta.url)) const envPath = path.resolve(currentDir, '.env.e2e') +const fixturesDir = path.resolve(currentDir, '../../../packages/e2e/fixtures') // Load E2E environment variables if present if (fs.existsSync(envPath)) { @@ -49,7 +51,7 @@ export interface ProjectFixture extends OwnerFixture { } /** The media kind of a seeded test file. */ -export type FileMediaType = 'text' | 'binary' | 'image' | 'video' | 'pdf' +export type FileMediaType = 'text' | 'binary' | 'image' | 'video' | 'pdf' | 'audio' export interface FileFixtureOptions { /** Defaults to `binary` (no extension, never transcoded, no proxy). */ @@ -68,6 +70,27 @@ const FILE_TYPE_MAP: Record = { image: { ext: 'png', mime: 'image/png' }, video: { ext: 'mp4', mime: 'video/mp4' }, pdf: { ext: 'pdf', mime: 'application/pdf' }, + audio: { ext: 'wav', mime: 'audio/wav' }, +} + +function getFileBuffer(mediaType: FileMediaType): Buffer { + switch (mediaType) { + case 'image': + return fs.readFileSync(path.join(fixturesDir, 'small.png')) + case 'video': + return fs.readFileSync(path.join(fixturesDir, 'small.mp4')) + case 'audio': + return fs.readFileSync(path.join(fixturesDir, 'small.wav')) + case 'pdf': + return fs.readFileSync(path.join(fixturesDir, 'test.pdf')) + case 'text': + return Buffer.from( + 'Sample text content for PDF proxy transcode test.\nSecond line of text content.', + ) + case 'binary': + default: + return Buffer.from('binary-file-content-sample') + } } export const test = base.extend<{ @@ -143,32 +166,26 @@ export const test = base.extend<{ await use({ ...owner, projectId: project.id, projectName: name, rootFolderId }) }, /** - * Sets up an owner + project with a seeded processed file asset under the - * project root folder. The media type is configurable per test via + * Sets up an owner + project with an uploaded file asset under the + * project root folder via the API upload task endpoints. The media type is configurable per test via * `fileOptions` (defaults to `binary`). */ - file: async ({ project, prisma, fileOptions }, use) => { + file: async ({ project, fileOptions }, use) => { const mediaType: FileMediaType = fileOptions.mediaType ?? 'binary' const { ext, mime } = FILE_TYPE_MAP[mediaType] const fileName = `test-file-${Date.now()}${ext ? `.${ext}` : ''}` + const buffer = getFileBuffer(mediaType) - const projectRow = await prisma.project.findUnique({ where: { id: project.projectId } }) - const rootFolderId = projectRow?.rootFolderId - if (!rootFolderId) throw new Error('Project has no root folder') + const uploaded = await apiUploadFile( + project.context.request, + project.teamId, + project.rootFolderId, + fileName, + mime, + buffer, + ) - const file = await prisma.asset.create({ - data: { - name: fileName, - type: 'file', - status: 'processed', - sizeByte: 10, - mediaType: mime, - projectId: project.projectId, - parentId: rootFolderId, - }, - }) - - await use({ ...project, fileId: file.id, fileName, fileMediaType: mediaType }) + await use({ ...project, fileId: uploaded.fileId, fileName, fileMediaType: mediaType }) }, }) diff --git a/apps/web/e2e/helpers/files.ts b/apps/web/e2e/helpers/files.ts index 16bf9614..389bb642 100644 --- a/apps/web/e2e/helpers/files.ts +++ b/apps/web/e2e/helpers/files.ts @@ -50,3 +50,72 @@ export async function apiAddAssetsToShare( throw new Error(`Add assets to share API failed (${res.status()}): ${await res.text()}`) } } + +/** Uploads a file asset through the official API upload task endpoints. */ +export async function apiUploadFile( + request: APIRequestContext, + teamId: string, + parentId: string, + fileName: string, + mimeType: string, + buffer: Buffer, +): Promise<{ fileId: string; fileName: string }> { + const tempId = `temp-${Date.now()}` + const createRes = await request.post(`/api/teams/${teamId}/upload/tasks`, { + data: { + parentId, + files: [ + { + id: tempId, + name: fileName, + type: 'file', + size: buffer.length, + mediaType: mimeType, + children: [], + }, + ], + }, + }) + if (!createRes.ok()) { + throw new Error(`Create upload task failed (${createRes.status()}): ${await createRes.text()}`) + } + const taskData = (await createRes.json()) as { + taskId: string + presignedUrls: Array<{ id: string; fileId: string; url: string }> + createdAssets?: Array<{ tempId: string; assetId: string }> + } + const presigned = taskData.presignedUrls.find((p) => p.id === tempId) + const createdAssetId = + taskData.createdAssets?.find((c) => c.tempId === tempId)?.assetId || presigned?.fileId + if (!presigned || !createdAssetId) { + throw new Error('Create upload task did not return presigned URL or asset ID') + } + + // Upload file buffer to presigned URL + const uploadRes = await request.put(presigned.url, { + headers: { + 'Content-Type': mimeType, + }, + data: buffer, + }) + if (!uploadRes.ok()) { + throw new Error( + `Upload to S3 presigned URL failed (${uploadRes.status()}): ${await uploadRes.text()}`, + ) + } + + // Confirm upload task + const confirmRes = await request.patch(`/api/teams/${teamId}/upload/tasks/${taskData.taskId}`, { + data: { + fileId: createdAssetId, + status: 'success', + }, + }) + if (!confirmRes.ok()) { + throw new Error( + `Confirm upload task failed (${confirmRes.status()}): ${await confirmRes.text()}`, + ) + } + + return { fileId: createdAssetId, fileName } +} diff --git a/apps/web/e2e/tests/file/audio-timestamp-comment.spec.ts b/apps/web/e2e/tests/file/audio-timestamp-comment.spec.ts new file mode 100644 index 00000000..b79dcc34 --- /dev/null +++ b/apps/web/e2e/tests/file/audio-timestamp-comment.spec.ts @@ -0,0 +1,71 @@ +import { expect, test } from '../../fixtures' + +test.use({ fileOptions: { mediaType: 'audio' } }) + +test('upload an audio file, create a comment at a non-zero timestamp', async ({ + file, + prisma, +}) => { + const { page, projectId, fileId } = file + const commentText = `Audio timestamp comment ${Date.now()}` + + // Wait for audio transcode completion + await expect + .poll( + async () => { + const asset = await prisma.asset.findUnique({ where: { id: fileId } }) + return asset?.status + }, + { timeout: 30_000 }, + ) + .toBe('processed') + + await page.goto(`/projects/${projectId}/files/${fileId}`) + + // Wait for audio/video media element to be visible + const mediaEl = page.locator('audio, video').first() + await expect(mediaEl).toBeVisible({ timeout: 30_000 }) + + // Seek media element to non-zero timestamp (e.g. 1 second) + await page.evaluate(() => { + const el = document.querySelector('audio, video') as HTMLMediaElement | null + if (el) el.currentTime = 1 + }) + await page.waitForTimeout(500) + + // Type comment text and send + const input = page.locator('[contenteditable="true"]').first() + await input.fill(commentText) + const sendBtn = page.locator('button:has(svg.lucide-arrow-up)').last() + await sendBtn.click() + + // Verify comment card appears in sidebar + await expect(page.getByText(commentText)).toBeVisible() + + // Ensure comment is persisted in DB before page reload + await expect + .poll(async () => { + return prisma.assetComment.findFirst({ + where: { assetId: fileId, message: commentText }, + }) + }) + .not.toBeNull() + + // Reload page + await page.reload() + + // Click the comment in right sidebar + const commentCard = page.getByText(commentText).first() + await expect(commentCard).toBeVisible() + await commentCard.click() + + // Verify media element jumped to timestamp + await expect + .poll(async () => { + return page.evaluate(() => { + const el = document.querySelector('audio, video') as HTMLMediaElement | null + return el ? el.currentTime : 0 + }) + }) + .toBeGreaterThan(0) +}) diff --git a/apps/web/e2e/tests/file/binary-comment.spec.ts b/apps/web/e2e/tests/file/binary-comment.spec.ts new file mode 100644 index 00000000..896fb25a --- /dev/null +++ b/apps/web/e2e/tests/file/binary-comment.spec.ts @@ -0,0 +1,32 @@ +import { expect, test } from '../../fixtures' + +test('create a comment on a binary file', async ({ file, prisma }) => { + const { page, projectId, fileId } = file + const commentText = `Binary comment ${Date.now()}` + + await page.goto(`/projects/${projectId}/files/${fileId}`) + + // Wait for file page & comments sidebar to load + const input = page.locator('[contenteditable="true"]').first() + await expect(input).toBeVisible() + + // Type comment text and send + await input.fill(commentText) + const sendBtn = page.locator('button:has(svg.lucide-arrow-up)').last() + await sendBtn.click() + + // Verify comment card appears in sidebar + await expect(page.getByText(commentText)).toBeVisible() + + // Refresh page and click the comment + await page.reload() + const commentCard = page.getByText(commentText).first() + await expect(commentCard).toBeVisible() + await commentCard.click() + + // DB verification + const commentInDb = await prisma.assetComment.findFirst({ + where: { assetId: fileId, message: commentText }, + }) + expect(commentInDb).not.toBeNull() +}) diff --git a/apps/web/e2e/tests/file/image-draw-comment.spec.ts b/apps/web/e2e/tests/file/image-draw-comment.spec.ts new file mode 100644 index 00000000..70d339aa --- /dev/null +++ b/apps/web/e2e/tests/file/image-draw-comment.spec.ts @@ -0,0 +1,71 @@ +import { expect, test } from '../../fixtures' + +test.use({ fileOptions: { mediaType: 'image' } }) + +test('upload an image file, create a comment with draw', async ({ file, prisma }) => { + const { page, projectId, fileId } = file + const commentText = `Image draw comment ${Date.now()}` + + // Wait for transcode completion + await expect + .poll( + async () => { + const asset = await prisma.asset.findUnique({ where: { id: fileId } }) + return asset?.status + }, + { timeout: 30_000 }, + ) + .toBe('processed') + + await page.goto(`/projects/${projectId}/files/${fileId}`) + + // Verify image is visible + await expect(page.locator('img').first()).toBeVisible({ timeout: 30_000 }) + + // Toggle drawing mode + const drawToggleBtn = page.getByTitle('Toggle Annotation') + await expect(drawToggleBtn).toBeVisible() + await drawToggleBtn.click() + + // Perform drawing gesture on canvas overlay + const canvas = page.locator('.konvajs-content canvas').first() + await expect(canvas).toBeVisible() + const box = await canvas.boundingBox() + if (box) { + const startX = box.x + box.width * 0.3 + const startY = box.y + box.height * 0.3 + const endX = box.x + box.width * 0.6 + const endY = box.y + box.height * 0.6 + await page.mouse.move(startX, startY) + await page.mouse.down() + await page.mouse.move(endX, endY, { steps: 5 }) + await page.mouse.up() + } + + // Type comment text and send + const input = page.locator('[contenteditable="true"]').first() + await input.fill(commentText) + const sendBtn = page.locator('button:has(svg.lucide-arrow-up)').last() + await sendBtn.click() + + // Verify comment card appears in sidebar + await expect(page.getByText(commentText)).toBeVisible() + + // Ensure comment is persisted in DB before page reload + await expect + .poll(async () => { + return prisma.assetComment.findFirst({ + where: { assetId: fileId, message: commentText }, + }) + }) + .not.toBeNull() + + // Reload page and click comment in right sidebar + await page.reload() + const commentCard = page.getByText(commentText).first() + await expect(commentCard).toBeVisible() + await commentCard.click() + + // Verify draw annotation is rendered on canvas + await expect(page.locator('.konvajs-content canvas').first()).toBeVisible() +}) diff --git a/apps/web/e2e/tests/file/txt-draw-comment.spec.ts b/apps/web/e2e/tests/file/txt-draw-comment.spec.ts new file mode 100644 index 00000000..fddcf46a --- /dev/null +++ b/apps/web/e2e/tests/file/txt-draw-comment.spec.ts @@ -0,0 +1,75 @@ +import { expect, test } from '../../fixtures' + +test.use({ fileOptions: { mediaType: 'text' } }) + +test('upload a txt file, create a comment with draw', async ({ file, prisma }) => { + const { page, projectId, fileId } = file + const commentText = `Txt draw comment ${Date.now()}` + + // Wait for background transcode worker to complete (txt -> pdf proxy) + await expect + .poll( + async () => { + const asset = await prisma.asset.findUnique({ where: { id: fileId } }) + return asset?.status + }, + { timeout: 60_000 }, + ) + .toBe('processed') + + await page.goto(`/projects/${projectId}/files/${fileId}`) + + // Verify PDF viewer container or page is loaded + await expect( + page.locator('.pdf-viewer, canvas, [data-testid="pdf-viewer"]').first(), + ).toBeVisible({ + timeout: 30_000, + }) + + // Toggle drawing mode + const drawToggleBtn = page.getByTitle('Toggle Annotation') + await expect(drawToggleBtn).toBeVisible() + await drawToggleBtn.click() + + // Perform drawing gesture on canvas overlay + const canvas = page.locator('.konvajs-content canvas').first() + await expect(canvas).toBeVisible() + const box = await canvas.boundingBox() + if (box) { + const startX = box.x + box.width * 0.3 + const startY = box.y + box.height * 0.3 + const endX = box.x + box.width * 0.6 + const endY = box.y + box.height * 0.6 + await page.mouse.move(startX, startY) + await page.mouse.down() + await page.mouse.move(endX, endY, { steps: 5 }) + await page.mouse.up() + } + + // Type comment text and send + const input = page.locator('[contenteditable="true"]').first() + await input.fill(commentText) + const sendBtn = page.locator('button:has(svg.lucide-arrow-up)').last() + await sendBtn.click() + + // Verify comment card appears in sidebar + await expect(page.getByText(commentText)).toBeVisible() + + // Ensure comment is persisted in DB before page reload + await expect + .poll(async () => { + return prisma.assetComment.findFirst({ + where: { assetId: fileId, message: commentText }, + }) + }) + .not.toBeNull() + + // Reload page and click comment in right sidebar + await page.reload() + const commentCard = page.getByText(commentText).first() + await expect(commentCard).toBeVisible() + await commentCard.click() + + // Verify draw annotation is rendered on canvas + await expect(page.locator('.konvajs-content canvas').first()).toBeVisible() +}) diff --git a/apps/web/e2e/tests/file/video-draw-comment.spec.ts b/apps/web/e2e/tests/file/video-draw-comment.spec.ts new file mode 100644 index 00000000..3ca56ee6 --- /dev/null +++ b/apps/web/e2e/tests/file/video-draw-comment.spec.ts @@ -0,0 +1,93 @@ +import { expect, test } from '../../fixtures' + +test.use({ fileOptions: { mediaType: 'video' } }) + +test('upload a video file, create a comment with draw at a non-zero timestamp', async ({ + file, + prisma, +}) => { + const { page, projectId, fileId } = file + const commentText = `Video draw comment ${Date.now()}` + + // Wait for video transcode completion + await expect + .poll( + async () => { + const asset = await prisma.asset.findUnique({ where: { id: fileId } }) + return asset?.status + }, + { timeout: 60_000 }, + ) + .toBe('processed') + + await page.goto(`/projects/${projectId}/files/${fileId}`) + + // Wait for video element to be visible + const video = page.locator('video').first() + await expect(video).toBeVisible({ timeout: 30_000 }) + + // Seek video to non-zero timestamp (e.g. 1 second) + await page.evaluate(() => { + const v = document.querySelector('video') + if (v) v.currentTime = 1 + }) + await page.waitForTimeout(500) + + // Toggle drawing mode + const drawToggleBtn = page.getByTitle('Toggle Annotation') + await expect(drawToggleBtn).toBeVisible() + await drawToggleBtn.click() + + // Perform drawing gesture on canvas overlay + const canvas = page.locator('.konvajs-content canvas').first() + await expect(canvas).toBeVisible() + const box = await canvas.boundingBox() + if (box) { + const startX = box.x + box.width * 0.3 + const startY = box.y + box.height * 0.3 + const endX = box.x + box.width * 0.6 + const endY = box.y + box.height * 0.6 + await page.mouse.move(startX, startY) + await page.mouse.down() + await page.mouse.move(endX, endY, { steps: 5 }) + await page.mouse.up() + } + + // Type comment text and send + const input = page.locator('[contenteditable="true"]').first() + await input.fill(commentText) + const sendBtn = page.locator('button:has(svg.lucide-arrow-up)').last() + await sendBtn.click() + + // Verify comment card appears in sidebar + await expect(page.getByText(commentText)).toBeVisible() + + // Ensure comment is persisted in DB before page reload + await expect + .poll(async () => { + return prisma.assetComment.findFirst({ + where: { assetId: fileId, message: commentText }, + }) + }) + .not.toBeNull() + + // Reload page + await page.reload() + + // Click the comment in right sidebar + const commentCard = page.getByText(commentText).first() + await expect(commentCard).toBeVisible() + await commentCard.click() + + // Verify video jumped to timestamp and draw annotation is shown on canvas + await expect + .poll(async () => { + return page.evaluate(() => { + const v = document.querySelector('video') + return v ? v.currentTime : 0 + }) + }) + .toBeGreaterThan(0) + + await expect(page.locator('.konvajs-content canvas').first()).toBeVisible() +})