From 29847e09453043ab242e049f96e01491df585d84 Mon Sep 17 00:00:00 2001 From: JohnAllenTech <46611809+JohnAllenTech@users.noreply.github.com> Date: Sat, 19 Oct 2024 15:13:21 -0600 Subject: [PATCH 1/3] chore: comment test working for authenticated user --- e2e/articles.spec.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/e2e/articles.spec.ts b/e2e/articles.spec.ts index 48361487..b1defc32 100644 --- a/e2e/articles.spec.ts +++ b/e2e/articles.spec.ts @@ -185,4 +185,28 @@ test.describe("Authenticated Articles Page", () => { await expect(page.getByLabel("like-trigger")).toBeVisible(); await expect(page.getByLabel("bookmark-trigger")).toBeVisible(); }); + + test("Should post a comment on an article", async ({ page, isMobile }) => { + await page.goto("http://localhost:3000"); + // Waits for articles to be loaded + await expect(page.getByText("Read Full Article").first()).toBeVisible(); + page.getByText("Read Full Article").first().click(); + await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/); + + await expect(page.getByPlaceholder("What do you think?")).toBeVisible(); + await page + .getByPlaceholder("What do you think?") + .fill("This is a great article. Thanks for posting it!"); + await page.getByRole("button", { name: "Submit" }).click(); + + await expect( + page.getByRole("link", { name: "E2E Test User", exact: true }), + ).toBeVisible(); + + await expect( + page.locator("div").filter({ + hasText: /^This is a great article\. Thanks for posting it!$/, + }), + ).toBeVisible(); + }); }); From ad97c58c2c60e8c1cd3e10b8b12b93563ebad6ad Mon Sep 17 00:00:00 2001 From: JohnAllenTech <46611809+JohnAllenTech@users.noreply.github.com> Date: Sat, 19 Oct 2024 18:16:06 -0600 Subject: [PATCH 2/3] chore: added test for auth and non auth user article commenting functionality --- e2e/articles.spec.ts | 39 ++++++++++++++++++++++++++------------- playwright.config.ts | 5 ++--- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/e2e/articles.spec.ts b/e2e/articles.spec.ts index b1defc32..1cf27025 100644 --- a/e2e/articles.spec.ts +++ b/e2e/articles.spec.ts @@ -1,4 +1,5 @@ import { test, expect } from "playwright/test"; +import { randomUUID } from "crypto"; test.describe("Unauthenticated Articles Page", () => { test.beforeEach(async ({ page }) => { @@ -57,6 +58,24 @@ test.describe("Unauthenticated Articles Page", () => { await expect(page.getByText("Sponsorship")).toBeVisible(); await expect(page.getByText("Code Of Conduct")).toBeVisible(); }); + + test("Should not be able to post a comment on an article", async ({ + page, + }) => { + await page.goto("http://localhost:3000"); + // Waits for articles to be loaded + await expect(page.getByText("Read Full Article").first()).toBeVisible(); + page.getByText("Read Full Article").first().click(); + await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/); + + await expect(page.getByPlaceholder("What do you think?")).toBeHidden(); + + await expect(page.getByText("Hey! 👋")).toBeVisible(); + await expect(page.getByText("Got something to say?")).toBeVisible(); + await expect( + page.getByText("Sign in or sign up to leave a comment"), + ).toBeVisible(); + }); }); test.describe("Authenticated Articles Page", () => { @@ -186,7 +205,11 @@ test.describe("Authenticated Articles Page", () => { await expect(page.getByLabel("bookmark-trigger")).toBeVisible(); }); - test("Should post a comment on an article", async ({ page, isMobile }) => { + test("Should post a comment on an article", async ({ + page, + browserName, + }, workerInfo) => { + const commentContent = `This is a great read. Thanks for posting! Sent from ${workerInfo.project.name} + ${randomUUID()}`; await page.goto("http://localhost:3000"); // Waits for articles to be loaded await expect(page.getByText("Read Full Article").first()).toBeVisible(); @@ -194,19 +217,9 @@ test.describe("Authenticated Articles Page", () => { await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/); await expect(page.getByPlaceholder("What do you think?")).toBeVisible(); - await page - .getByPlaceholder("What do you think?") - .fill("This is a great article. Thanks for posting it!"); + await page.getByPlaceholder("What do you think?").fill(commentContent); await page.getByRole("button", { name: "Submit" }).click(); - await expect( - page.getByRole("link", { name: "E2E Test User", exact: true }), - ).toBeVisible(); - - await expect( - page.locator("div").filter({ - hasText: /^This is a great article\. Thanks for posting it!$/, - }), - ).toBeVisible(); + await expect(page.getByText(commentContent)).toBeVisible(); }); }); diff --git a/playwright.config.ts b/playwright.config.ts index 6cbc7811..98edcf90 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -37,9 +37,8 @@ export default defineConfig({ projects: [ { name: "setup", testMatch: /auth.setup\.ts/ }, { - name: "chromium", + name: "Desktop Chrome", use: { - ...devices["Desktop Chrome"], storageState: "playwright/.auth/browser.json", }, dependencies: ["setup"], @@ -47,7 +46,7 @@ export default defineConfig({ // Example other browsers { - name: "firefox", + name: "Desktop Firefox", use: { ...devices["Desktop Firefox"], storageState: "playwright/.auth/browser.json", From 3fda823af00393f86dd3b5660d432740cb1adcf9 Mon Sep 17 00:00:00 2001 From: JohnAllenTech <46611809+JohnAllenTech@users.noreply.github.com> Date: Sat, 19 Oct 2024 19:17:28 -0600 Subject: [PATCH 3/3] chore: addressing pr comments --- e2e/articles.spec.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/e2e/articles.spec.ts b/e2e/articles.spec.ts index 1cf27025..0facf1f7 100644 --- a/e2e/articles.spec.ts +++ b/e2e/articles.spec.ts @@ -65,7 +65,7 @@ test.describe("Unauthenticated Articles Page", () => { await page.goto("http://localhost:3000"); // Waits for articles to be loaded await expect(page.getByText("Read Full Article").first()).toBeVisible(); - page.getByText("Read Full Article").first().click(); + await page.getByText("Read Full Article").first().click(); await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/); await expect(page.getByPlaceholder("What do you think?")).toBeHidden(); @@ -205,15 +205,12 @@ test.describe("Authenticated Articles Page", () => { await expect(page.getByLabel("bookmark-trigger")).toBeVisible(); }); - test("Should post a comment on an article", async ({ - page, - browserName, - }, workerInfo) => { + test("Should post a comment on an article", async ({ page }, workerInfo) => { const commentContent = `This is a great read. Thanks for posting! Sent from ${workerInfo.project.name} + ${randomUUID()}`; await page.goto("http://localhost:3000"); // Waits for articles to be loaded await expect(page.getByText("Read Full Article").first()).toBeVisible(); - page.getByText("Read Full Article").first().click(); + await page.getByText("Read Full Article").first().click(); await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/); await expect(page.getByPlaceholder("What do you think?")).toBeVisible();