Skip to content

Commit 77aa243

Browse files
feat: adding e2e test for article commenting (#1158)
1 parent 3bb1ee4 commit 77aa243

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

e2e/articles.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { test, expect } from "playwright/test";
2+
import { randomUUID } from "crypto";
23

34
test.describe("Unauthenticated Articles Page", () => {
45
test.beforeEach(async ({ page }) => {
@@ -57,6 +58,24 @@ test.describe("Unauthenticated Articles Page", () => {
5758
await expect(page.getByText("Sponsorship")).toBeVisible();
5859
await expect(page.getByText("Code Of Conduct")).toBeVisible();
5960
});
61+
62+
test("Should not be able to post a comment on an article", async ({
63+
page,
64+
}) => {
65+
await page.goto("http://localhost:3000");
66+
// Waits for articles to be loaded
67+
await expect(page.getByText("Read Full Article").first()).toBeVisible();
68+
await page.getByText("Read Full Article").first().click();
69+
await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/);
70+
71+
await expect(page.getByPlaceholder("What do you think?")).toBeHidden();
72+
73+
await expect(page.getByText("Hey! 👋")).toBeVisible();
74+
await expect(page.getByText("Got something to say?")).toBeVisible();
75+
await expect(
76+
page.getByText("Sign in or sign up to leave a comment"),
77+
).toBeVisible();
78+
});
6079
});
6180

6281
test.describe("Authenticated Articles Page", () => {
@@ -186,4 +205,19 @@ test.describe("Authenticated Articles Page", () => {
186205
await expect(page.getByLabel("like-trigger")).toBeVisible();
187206
await expect(page.getByLabel("bookmark-trigger")).toBeVisible();
188207
});
208+
209+
test("Should post a comment on an article", async ({ page }, workerInfo) => {
210+
const commentContent = `This is a great read. Thanks for posting! Sent from ${workerInfo.project.name} + ${randomUUID()}`;
211+
await page.goto("http://localhost:3000");
212+
// Waits for articles to be loaded
213+
await expect(page.getByText("Read Full Article").first()).toBeVisible();
214+
await page.getByText("Read Full Article").first().click();
215+
await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/);
216+
217+
await expect(page.getByPlaceholder("What do you think?")).toBeVisible();
218+
await page.getByPlaceholder("What do you think?").fill(commentContent);
219+
await page.getByRole("button", { name: "Submit" }).click();
220+
221+
await expect(page.getByText(commentContent)).toBeVisible();
222+
});
189223
});

playwright.config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,16 @@ export default defineConfig({
3737
projects: [
3838
{ name: "setup", testMatch: /auth.setup\.ts/ },
3939
{
40-
name: "chromium",
40+
name: "Desktop Chrome",
4141
use: {
42-
...devices["Desktop Chrome"],
4342
storageState: "playwright/.auth/browser.json",
4443
},
4544
dependencies: ["setup"],
4645
},
4746

4847
// Example other browsers
4948
{
50-
name: "firefox",
49+
name: "Desktop Firefox",
5150
use: {
5251
...devices["Desktop Firefox"],
5352
storageState: "playwright/.auth/browser.json",

0 commit comments

Comments
 (0)