-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreviewDrafts.spec.ts
More file actions
71 lines (54 loc) · 2.46 KB
/
reviewDrafts.spec.ts
File metadata and controls
71 lines (54 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { test, expect } from "@playwright/test";
import { populateDummyData } from "./helpers/db";
import { loginAsUserA } from "./helpers/login";
test.beforeEach(async ({ page }) => {
await populateDummyData(page);
await loginAsUserA(page);
});
test("auto-saves a draft and lets the user resume", async ({ page }) => {
await page.getByRole("button", { name: "Add Rating" }).click();
await page.getByPlaceholder("Search").pressSequentially("slow lear");
await page.getByText("Slow Learners (2015)").click();
await page.getByLabel("When did you watch?").fill("2024-10-10");
const draftResponse = page.waitForResponse(
(response) =>
response.url().includes("/reviews/drafts") &&
response.request().method() === "POST" &&
response.status() === 201
);
await page.getByLabel("Other thoughts?").fill("Draft thoughts");
await draftResponse;
await page.getByRole("menuitem", { name: "Account" }).click();
await page.getByRole("menuitem", { name: "Drafts" }).click();
await expect(page).toHaveURL("/reviews/drafts");
const draftCard = page.getByTestId("draft-card").first();
await expect(draftCard.getByText("Slow Learners")).toBeVisible();
await draftCard.getByRole("link", { name: "Continue" }).click();
await expect(page.getByLabel("Other thoughts?")).toHaveValue(
"Draft thoughts"
);
await page.getByRole("button", { name: "Publish" }).click();
await expect(page).toHaveURL(/\/movies\/3(#review\d+)?/);
});
test("redirects to an existing draft when starting the same review", async ({
page,
}) => {
await page.getByRole("button", { name: "Add Rating" }).click();
await page.getByPlaceholder("Search").pressSequentially("slow lear");
await page.getByText("Slow Learners (2015)").click();
await page.getByLabel("When did you watch?").fill("2024-10-10");
const draftResponse = page.waitForResponse(
(response) =>
response.url().includes("/reviews/drafts") &&
response.request().method() === "POST" &&
response.status() === 201
);
await page.getByLabel("Other thoughts?").fill("Second draft");
await draftResponse;
await page.getByRole("menuitem", { name: "Home" }).click();
await page.getByRole("button", { name: "Add Rating" }).click();
await page.getByPlaceholder("Search").pressSequentially("slow lear");
await page.getByText("Slow Learners (2015)").click();
await expect(page).toHaveURL(/\/reviews\/\d+\/edit/);
await expect(page.locator("h2 .badge", { hasText: "Draft" })).toBeVisible();
});