diff --git a/package.json b/package.json index 6318466..c5dcace 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dev": "next dev", "postinstall": "prisma generate", "lint": "next lint", - "test:e2e": "npm run db-seed && playwright test --workers 1 --headed", + "test:e2e": "npm run db-seed && playwright test --headed", "db-seed": "NODE_ENV=development prisma db seed", "start": "next start" }, diff --git a/tests/000-landing.spec.ts b/tests/000-landing.spec.ts index 1bb6b02..8eab16a 100644 --- a/tests/000-landing.spec.ts +++ b/tests/000-landing.spec.ts @@ -1,10 +1,12 @@ import { test, expect } from "@playwright/test"; -test("should show logged in state on landing page", async ({ page }) => { - await page.goto("http://localhost:3000/"); - await expect( - page.locator( - "div.flex.flex-col.items-center.gap-2 > div > p > span:nth-child(1)" - ) - ).toContainText("Logged in as E2E Account"); +test.describe("landing", () => { + test("should show logged in state on landing page", async ({ page }) => { + await page.goto("http://localhost:3000/"); + await expect( + page.locator( + "div.flex.flex-col.items-center.gap-2 > div > p > span:nth-child(1)" + ) + ).toContainText("Logged in as E2E Account"); + }); }); diff --git a/tests/001-videos.spec.ts b/tests/001-videos.spec.ts index e34439e..7ceb02e 100644 --- a/tests/001-videos.spec.ts +++ b/tests/001-videos.spec.ts @@ -1,32 +1,41 @@ import { test, expect } from "@playwright/test"; -test("should be able to view videos", async ({ page }) => { - await page.goto("http://localhost:3000/"); - await page - .getByRole("link", { name: "Go to Videos → The entire videos collection" }) - .click(); - await expect(page).toHaveURL("http://localhost:3000/videos"); -}); - -test("no videos should exist", async ({ page }) => { - await page.goto("http://localhost:3000/videos"); - await expect(page.locator("div.flex-start > div > span")).toContainText( - "You do not have any recordings." - ); -}); - -test("can upload video", async ({ page }) => { - await page.goto("http://localhost:3000/videos"); - await page.getByText("New video").click(); - await page - .getByText("Drop files to Attach, or browse") - .setInputFiles("tests/assets/example_video.webm"); - await page.getByRole("button", { name: "Upload" }).click(); - await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/, { - timeout: 30000, +test.describe("videos", () => { + test("should be able to view videos", async ({ page }) => { + await page.goto("http://localhost:3000/"); + await page + .getByRole("link", { + name: "Go to Videos → The entire videos collection", + }) + .click(); + await expect(page).toHaveURL("http://localhost:3000/videos"); }); - await page.click('[href="/videos"]'); - await page.getByText("example_video.webm").click(); - await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/); + test("no videos should exist", async ({ page }) => { + await page.goto("http://localhost:3000/videos"); + await expect(page.locator("div.flex-start > div > span")).toContainText( + "You do not have any recordings." + ); + }); + + test("can upload video", async ({ page }) => { + await page.goto("http://localhost:3000/videos"); + await page.getByText("New video").click(); + await page + .getByText("Drop files to Attach, or browse") + .setInputFiles("tests/assets/example_video.webm"); + await page.getByRole("button", { name: "Upload" }).click(); + await expect(page).toHaveURL( + /http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/, + { + timeout: 30000, + } + ); + + await page.click('[href="/videos"]'); + await page.getByText("example_video.webm").click(); + await expect(page).toHaveURL( + /http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/ + ); + }); }); diff --git a/tests/002-video.spec.ts b/tests/002-video.spec.ts index 547a292..f764702 100644 --- a/tests/002-video.spec.ts +++ b/tests/002-video.spec.ts @@ -1,44 +1,50 @@ import { expect, test } from "@playwright/test"; -test("should be able to view video", async ({ page }) => { - await page.goto("http://localhost:3000/videos"); - await page.locator("div.grid > a:nth-child(1)").click(); - await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/); +test.describe("video", () => { + test("should be able to view video", async ({ page }) => { + await page.goto("http://localhost:3000/videos"); + await page.locator("div.grid > a:nth-child(1)").click(); + await expect(page).toHaveURL( + /http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/ + ); - const video = page.locator("video"); - expect(video).toBeTruthy(); - await video.evaluate((v: HTMLVideoElement) => v.play()); - const isPlaying = await video.evaluate((v: HTMLVideoElement) => !v.paused); - expect(isPlaying).toBe(true); - await video.click(); - const isPaused = await video.evaluate((v: HTMLVideoElement) => v.paused); - expect(isPaused).toBe(true); -}); - -test("should be able to rename video", async ({ page }) => { - const randomTitle = "Random title " + Math.random().toString(); - - await page.goto("http://localhost:3000/videos"); - await page.locator("div.grid > a:nth-child(1)").click(); - await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/); - - await page.locator("button > svg").click(); - await page.getByText("Rename").click(); - await page.click("#title"); - await page.fill("#title", randomTitle); - await page.getByText("Save").click(); - expect( - await page.locator("div > span.text-lg.font-medium").textContent() - ).toBe(randomTitle); -}); - -test("should be able to share video", async ({ page }) => { - await page.goto("http://localhost:3000/videos"); - await page.locator("div.grid > a:nth-child(1)").click(); - await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/); - - await page.getByText("Share").click(); - await page.locator('div.mt-6 > button[role="switch"]').click(); - - await page.waitForTimeout(5000); + const video = page.locator("video"); + expect(video).toBeTruthy(); + await video.evaluate((v: HTMLVideoElement) => v.play()); + const isPlaying = await video.evaluate((v: HTMLVideoElement) => !v.paused); + expect(isPlaying).toBe(true); + await video.click(); + const isPaused = await video.evaluate((v: HTMLVideoElement) => v.paused); + expect(isPaused).toBe(true); + }); + + test("should be able to rename video", async ({ page }) => { + const randomTitle = "Random title " + Math.random().toString(); + + await page.goto("http://localhost:3000/videos"); + await page.locator("div.grid > a:nth-child(1)").click(); + await expect(page).toHaveURL( + /http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/ + ); + + await page.locator("button > svg").click(); + await page.getByText("Rename").click(); + await page.click("#title"); + await page.fill("#title", randomTitle); + await page.getByText("Save").click(); + expect( + await page.locator("div > span.text-lg.font-medium").textContent() + ).toBe(randomTitle); + }); + + test("should be able to share video", async ({ page }) => { + await page.goto("http://localhost:3000/videos"); + await page.locator("div.grid > a:nth-child(1)").click(); + await expect(page).toHaveURL( + /http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/ + ); + + await page.getByText("Share").click(); + await page.locator('div.mt-6 > button[role="switch"]').click(); + }); });