Skip to content

Commit 0807ad5

Browse files
committed
chore: added tests for my posts page
1 parent c2a4968 commit 0807ad5

File tree

3 files changed

+97
-14
lines changed

3 files changed

+97
-14
lines changed

e2e/articles.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ test.describe("Unauthenticated Articles Page", () => {
1717
test("Should be able to navigate directly to an article", async ({
1818
page,
1919
}) => {
20-
await page.goto("http://localhost:3000/articles/e2e-test-slug-eqj0ozor");
20+
await page.goto("http://localhost:3000/articles/e2e-test-slug-published");
2121
await expect(page.getByText("Lorem ipsum dolor sit amet,")).toBeVisible();
2222
await expect(
23-
page.getByRole("heading", { name: "Test Article" }),
23+
page.getByRole("heading", { name: "Published Article" }),
2424
).toBeVisible();
2525
await expect(
2626
page.getByRole("heading", { name: "Written by E2E Test User One" }),
@@ -291,14 +291,14 @@ test.describe("Authenticated Articles Page", () => {
291291
});
292292

293293
test("Should be able reply to a comment", async ({ page }) => {
294-
await page.goto("http://localhost:3000/articles/e2e-test-slug-eqj0ozor");
294+
await page.goto("http://localhost:3000/articles/e2e-test-slug-published");
295295
const numberOfCommentsIntially = await page
296296
.locator("div")
297297
.filter({ hasText: /^Thanks for the positive feedback!$/ })
298298
.count();
299299
await expect(page.getByText("Lorem ipsum dolor sit amet,")).toBeVisible();
300300
await expect(
301-
page.getByRole("heading", { name: "Test Article" }),
301+
page.getByRole("heading", { name: "Published Article" }),
302302
).toBeVisible();
303303
await expect(
304304
page.getByRole("heading", { name: "Written by E2E Test User One" }),

e2e/my-posts.spec.ts

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,58 @@
1-
import test from "@playwright/test";
1+
import test, { expect } from "@playwright/test";
22
import { loggedInAsUserOne } from "./utils";
33

44
test.describe("Unauthenticated my-posts Page", () => {
5-
//
6-
// Replace with tests for unauthenticated users
5+
test("Unauthenticed users should be redirected to get-started page if they access my-posts directly", async ({
6+
page,
7+
}) => {
8+
await page.goto("http://localhost:3000/my-posts");
9+
await page.waitForURL("http://localhost:3000/get-started");
10+
expect(page.url()).toEqual("http://localhost:3000/get-started");
11+
});
712
});
813

914
test.describe("Authenticated my-posts Page", () => {
1015
test.beforeEach(async ({ page }) => {
1116
await loggedInAsUserOne(page);
1217
});
13-
//
14-
// Replace with tests for authenticated users
18+
19+
test("Tabs for different type of posts should be visible", async ({
20+
page,
21+
}) => {
22+
await page.goto("http://localhost:3000/my-posts");
23+
24+
await expect(page.getByRole("link", { name: "Drafts" })).toBeVisible();
25+
await expect(page.getByRole("link", { name: "Scheduled" })).toBeVisible();
26+
await expect(page.getByRole("link", { name: "Published" })).toBeVisible();
27+
});
28+
29+
test("Different article tabs should correctly display articles matching that type", async ({
30+
page,
31+
}) => {
32+
await page.goto("http://localhost:3000/my-posts");
33+
34+
await expect(page.getByRole("link", { name: "Drafts" })).toBeVisible();
35+
await expect(page.getByRole("link", { name: "Scheduled" })).toBeVisible();
36+
await expect(page.getByRole("link", { name: "Published" })).toBeVisible();
37+
38+
await page.getByRole("link", { name: "Drafts" }).click();
39+
await expect(
40+
page.getByRole("heading", { name: "Draft Article" }),
41+
).toBeVisible();
42+
await expect(page.getByText("Lorem ipsum dolor sit amet")).toBeVisible();
43+
44+
await page.getByRole("link", { name: "Scheduled" }).click();
45+
await expect(
46+
page.getByRole("heading", { name: "Scheduled Article" }),
47+
).toBeVisible();
48+
await expect(page.getByText("Lorem ipsum dolor sit amet")).toBeVisible();
49+
50+
await page.getByRole("link", { name: "Published" }).click();
51+
await expect(
52+
page.getByRole("heading", { name: "Published Article" }),
53+
).toBeVisible();
54+
await expect(
55+
page.getByText("Lorem ipsum dolor sit amet", { exact: true }),
56+
).toBeVisible();
57+
});
1558
});

e2e/setup.ts

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,59 @@ export const setup = async () => {
1919
authorId: string,
2020
commenterId: string,
2121
) => {
22-
const postId = "1nFnMmN5";
22+
const publishedPostId = "1nFnMmN1";
23+
const scheduledPostId = "1nFnMmN2";
24+
const draftPostId = "1nFnMmN3";
2325
const now = new Date().toISOString();
26+
27+
const oneYearFromToday = new Date(now);
28+
oneYearFromToday.setFullYear(oneYearFromToday.getFullYear() + 1);
29+
2430
await db
2531
.insert(post)
2632
.values({
27-
id: postId,
33+
id: publishedPostId,
2834
published: now,
2935
excerpt: "Lorem ipsum dolor sit amet",
3036
updatedAt: now,
31-
slug: "e2e-test-slug-eqj0ozor",
37+
slug: "e2e-test-slug-published",
38+
likes: 10,
39+
readTimeMins: 3,
40+
title: "Published Article",
41+
body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas vitae ipsum id metus vestibulum rutrum eget a diam. Integer eget vulputate risus, ac convallis nulla. Mauris sed augue nunc. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam congue posuere tempor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut ac augue non libero ullamcorper ornare. Ut commodo ligula vitae malesuada maximus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Etiam sagittis justo non justo placerat, a dapibus sapien volutpat. Nullam ullamcorper sodales justo sed.",
42+
userId: authorId,
43+
})
44+
.onConflictDoNothing()
45+
.returning();
46+
47+
await db
48+
.insert(post)
49+
.values({
50+
id: scheduledPostId,
51+
published: null,
52+
excerpt: "Lorem ipsum dolor sit amet",
53+
updatedAt: now,
54+
slug: "e2e-test-slug-draft",
55+
likes: 10,
56+
readTimeMins: 3,
57+
title: "Draft Article",
58+
body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas vitae ipsum id metus vestibulum rutrum eget a diam. Integer eget vulputate risus, ac convallis nulla. Mauris sed augue nunc. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam congue posuere tempor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut ac augue non libero ullamcorper ornare. Ut commodo ligula vitae malesuada maximus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Etiam sagittis justo non justo placerat, a dapibus sapien volutpat. Nullam ullamcorper sodales justo sed.",
59+
userId: authorId,
60+
})
61+
.onConflictDoNothing()
62+
.returning();
63+
64+
await db
65+
.insert(post)
66+
.values({
67+
id: draftPostId,
68+
published: oneYearFromToday.toISOString(),
69+
excerpt: "Lorem ipsum dolor sit amet",
70+
updatedAt: now,
71+
slug: "e2e-test-slug-scheduled",
3272
likes: 10,
3373
readTimeMins: 3,
34-
title: "Test Article",
74+
title: "Scheduled Article",
3575
body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas vitae ipsum id metus vestibulum rutrum eget a diam. Integer eget vulputate risus, ac convallis nulla. Mauris sed augue nunc. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam congue posuere tempor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut ac augue non libero ullamcorper ornare. Ut commodo ligula vitae malesuada maximus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Etiam sagittis justo non justo placerat, a dapibus sapien volutpat. Nullam ullamcorper sodales justo sed.",
3676
userId: authorId,
3777
})
@@ -41,7 +81,7 @@ export const setup = async () => {
4181
await db
4282
.insert(comment)
4383
.values({
44-
postId,
84+
postId: publishedPostId,
4585
body: "What a great article! Thanks for sharing",
4686
userId: commenterId,
4787
})

0 commit comments

Comments
 (0)