|
1 | 1 | import { test, expect } from "playwright/test"; |
| 2 | +import { randomUUID } from "crypto"; |
2 | 3 |
|
3 | 4 | test.describe("Unauthenticated Articles Page", () => { |
4 | 5 | test.beforeEach(async ({ page }) => { |
@@ -57,6 +58,24 @@ test.describe("Unauthenticated Articles Page", () => { |
57 | 58 | await expect(page.getByText("Sponsorship")).toBeVisible(); |
58 | 59 | await expect(page.getByText("Code Of Conduct")).toBeVisible(); |
59 | 60 | }); |
| 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 | + }); |
60 | 79 | }); |
61 | 80 |
|
62 | 81 | test.describe("Authenticated Articles Page", () => { |
@@ -186,27 +205,21 @@ test.describe("Authenticated Articles Page", () => { |
186 | 205 | await expect(page.getByLabel("bookmark-trigger")).toBeVisible(); |
187 | 206 | }); |
188 | 207 |
|
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()}`; |
190 | 213 | await page.goto("http://localhost:3000"); |
191 | 214 | // Waits for articles to be loaded |
192 | 215 | await expect(page.getByText("Read Full Article").first()).toBeVisible(); |
193 | 216 | page.getByText("Read Full Article").first().click(); |
194 | 217 | await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/); |
195 | 218 |
|
196 | 219 | 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); |
200 | 221 | await page.getByRole("button", { name: "Submit" }).click(); |
201 | 222 |
|
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(); |
211 | 224 | }); |
212 | 225 | }); |
0 commit comments