Skip to content

Commit ad97c58

Browse files
committed
chore: added test for auth and non auth user article commenting functionality
1 parent 29847e0 commit ad97c58

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

e2e/articles.spec.ts

Lines changed: 26 additions & 13 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+
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,27 +205,21 @@ test.describe("Authenticated Articles Page", () => {
186205
await expect(page.getByLabel("bookmark-trigger")).toBeVisible();
187206
});
188207

189-
test("Should post a comment on an article", async ({ page, isMobile }) => {
208+
test("Should post a comment on an article", async ({
209+
page,
210+
browserName,
211+
}, workerInfo) => {
212+
const commentContent = `This is a great read. Thanks for posting! Sent from ${workerInfo.project.name} + ${randomUUID()}`;
190213
await page.goto("http://localhost:3000");
191214
// Waits for articles to be loaded
192215
await expect(page.getByText("Read Full Article").first()).toBeVisible();
193216
page.getByText("Read Full Article").first().click();
194217
await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/);
195218

196219
await expect(page.getByPlaceholder("What do you think?")).toBeVisible();
197-
await page
198-
.getByPlaceholder("What do you think?")
199-
.fill("This is a great article. Thanks for posting it!");
220+
await page.getByPlaceholder("What do you think?").fill(commentContent);
200221
await page.getByRole("button", { name: "Submit" }).click();
201222

202-
await expect(
203-
page.getByRole("link", { name: "E2E Test User", exact: true }),
204-
).toBeVisible();
205-
206-
await expect(
207-
page.locator("div").filter({
208-
hasText: /^This is a great article\. Thanks for posting it!$/,
209-
}),
210-
).toBeVisible();
223+
await expect(page.getByText(commentContent)).toBeVisible();
211224
});
212225
});

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)