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 2 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
37 changes: 37 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();
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,22 @@ 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,
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();
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