Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding e2e test for article commenting #1158

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions e2e/articles.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test, expect } from "playwright/test";
import { randomUUID } from "crypto";

test.describe("Unauthenticated Articles Page", () => {
test.beforeEach(async ({ page }) => {
Expand Down Expand Up @@ -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();
await 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", () => {
Expand Down Expand Up @@ -185,4 +204,19 @@ 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 }, 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();
await 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(commentContent);
await page.getByRole("button", { name: "Submit" }).click();

await expect(page.getByText(commentContent)).toBeVisible();
});
Comment on lines +209 to +222
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

LGTM: New test case for authenticated users

The new test case effectively verifies that authenticated users can post comments on articles. The use of randomUUID() for generating unique comments is a good practice.

There's a missing await before the click() method on line 213. This issue was flagged in a previous review. Please apply the following fix:

-    await page.getByText("Read Full Article").first().click();
+    await page.getByText("Read Full Article").first().click();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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();
await 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(commentContent);
await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText(commentContent)).toBeVisible();
});
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();
await 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(commentContent);
await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText(commentContent)).toBeVisible();
});

});
5 changes: 2 additions & 3 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ 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"],
},

// Example other browsers
{
name: "firefox",
name: "Desktop Firefox",
use: {
...devices["Desktop Firefox"],
storageState: "playwright/.auth/browser.json",
Expand Down
Loading