group tests using .describe

This commit is contained in:
MarconLP 2023-04-15 23:21:00 +02:00
parent d3723a3e75
commit 141c3e385c
No known key found for this signature in database
GPG key ID: A08A9C8B623F5EA5
4 changed files with 92 additions and 75 deletions

View file

@ -7,7 +7,7 @@
"dev": "next dev", "dev": "next dev",
"postinstall": "prisma generate", "postinstall": "prisma generate",
"lint": "next lint", "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", "db-seed": "NODE_ENV=development prisma db seed",
"start": "next start" "start": "next start"
}, },

View file

@ -1,10 +1,12 @@
import { test, expect } from "@playwright/test"; import { test, expect } from "@playwright/test";
test("should show logged in state on landing page", async ({ page }) => { test.describe("landing", () => {
await page.goto("http://localhost:3000/"); test("should show logged in state on landing page", async ({ page }) => {
await expect( await page.goto("http://localhost:3000/");
page.locator( await expect(
"div.flex.flex-col.items-center.gap-2 > div > p > span:nth-child(1)" page.locator(
) "div.flex.flex-col.items-center.gap-2 > div > p > span:nth-child(1)"
).toContainText("Logged in as E2E Account"); )
).toContainText("Logged in as E2E Account");
});
}); });

View file

@ -1,32 +1,41 @@
import { test, expect } from "@playwright/test"; import { test, expect } from "@playwright/test";
test("should be able to view videos", async ({ page }) => { test.describe("videos", () => {
await page.goto("http://localhost:3000/"); test("should be able to view videos", async ({ page }) => {
await page await page.goto("http://localhost:3000/");
.getByRole("link", { name: "Go to Videos → The entire videos collection" }) await page
.click(); .getByRole("link", {
await expect(page).toHaveURL("http://localhost:3000/videos"); name: "Go to Videos → The entire videos collection",
}); })
.click();
test("no videos should exist", async ({ page }) => { await expect(page).toHaveURL("http://localhost:3000/videos");
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"]'); test("no videos should exist", async ({ page }) => {
await page.getByText("example_video.webm").click(); await page.goto("http://localhost:3000/videos");
await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/); 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]+/
);
});
}); });

View file

@ -1,44 +1,50 @@
import { expect, test } from "@playwright/test"; import { expect, test } from "@playwright/test";
test("should be able to view video", async ({ page }) => { test.describe("video", () => {
await page.goto("http://localhost:3000/videos"); test("should be able to view video", async ({ page }) => {
await page.locator("div.grid > a:nth-child(1)").click(); await page.goto("http://localhost:3000/videos");
await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/); 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"); const video = page.locator("video");
expect(video).toBeTruthy(); expect(video).toBeTruthy();
await video.evaluate((v: HTMLVideoElement) => v.play()); await video.evaluate((v: HTMLVideoElement) => v.play());
const isPlaying = await video.evaluate((v: HTMLVideoElement) => !v.paused); const isPlaying = await video.evaluate((v: HTMLVideoElement) => !v.paused);
expect(isPlaying).toBe(true); expect(isPlaying).toBe(true);
await video.click(); await video.click();
const isPaused = await video.evaluate((v: HTMLVideoElement) => v.paused); const isPaused = await video.evaluate((v: HTMLVideoElement) => v.paused);
expect(isPaused).toBe(true); expect(isPaused).toBe(true);
}); });
test("should be able to rename video", async ({ page }) => { test("should be able to rename video", async ({ page }) => {
const randomTitle = "Random title " + Math.random().toString(); const randomTitle = "Random title " + Math.random().toString();
await page.goto("http://localhost:3000/videos"); await page.goto("http://localhost:3000/videos");
await page.locator("div.grid > a:nth-child(1)").click(); await page.locator("div.grid > a:nth-child(1)").click();
await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/); 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.locator("button > svg").click();
await page.fill("#title", randomTitle); await page.getByText("Rename").click();
await page.getByText("Save").click(); await page.click("#title");
expect( await page.fill("#title", randomTitle);
await page.locator("div > span.text-lg.font-medium").textContent() await page.getByText("Save").click();
).toBe(randomTitle); 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(); test("should be able to share video", async ({ page }) => {
await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/); await page.goto("http://localhost:3000/videos");
await page.locator("div.grid > a:nth-child(1)").click();
await page.getByText("Share").click(); await expect(page).toHaveURL(
await page.locator('div.mt-6 > button[role="switch"]').click(); /http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/
);
await page.waitForTimeout(5000);
await page.getByText("Share").click();
await page.locator('div.mt-6 > button[role="switch"]').click();
});
}); });