Skip to content

Commit

Permalink
chore: added article creation e2e test (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAllenTech authored Oct 17, 2024
1 parent 2dc9bb8 commit a30156b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions e2e/articles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,56 @@ test.describe("Authenticated Articles Page", () => {
await expect(page.getByText("Sponsorship")).toBeVisible();
await expect(page.getByText("Code Of Conduct")).toBeVisible();
});

test("Should write and publish an article", async ({ page, isMobile }) => {
const articleContent =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas vitae ipsum id metus vestibulum rutrum eget a diam. Integer eget vulputate risus, ac convallis nulla. Mauris sed augue nunc. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam congue posuere tempor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut ac augue non libero ullamcorper ornare. Ut commodo ligula vitae malesuada maximus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Etiam sagittis justo non justo placerat, a dapibus sapien volutpat. Nullam ullamcorper sodales justo sed.";
const articleTitle = "Lorem Ipsum";
await page.goto("http://localhost:3000");
// Waits for articles to be loaded
await page.waitForSelector("article");

// Mobile and Desktop have different ways to start writing an article
if (isMobile) {
await expect(
page.getByRole("button", { name: "Open main menu" }),
).toBeVisible();
page.getByRole("button", { name: "Open main menu" }).tap();
await expect(page.getByRole("link", { name: "New Post" })).toBeVisible();
await page.getByRole("link", { name: "New Post" }).tap();
} else {
await expect(page.getByRole("link", { name: "New Post" })).toBeVisible();
await page.getByRole("link", { name: "New Post" }).click();
}
await page.waitForURL("http:/localhost:3000/create");

await page.getByPlaceholder("Article title").fill(articleTitle);

await page
.getByPlaceholder("Enter your content here 💖")
.fill(articleContent);

await expect(page.getByRole("button", { name: "Next" })).toBeVisible();
await page.getByRole("button", { name: "Next" }).click();
await expect(
page.getByRole("button", { name: "Publish now" }),
).toBeVisible();
await page.getByRole("button", { name: "Publish now" }).click();
await page.waitForURL(
/^http:\/\/localhost:3000\/articles\/lorem-ipsum-.*$/,
);

await expect(page.getByText("Lorem ipsum dolor sit amet,")).toBeVisible();
await expect(
page.getByRole("heading", { name: "Lorem Ipsum" }),
).toBeVisible();
await expect(
page.getByRole("heading", { name: "Written by E2E Test User" }),
).toBeVisible();
await expect(
page.getByRole("heading", { name: "Discussion (0)" }),
).toBeVisible();
await expect(page.getByLabel("like-trigger")).toBeVisible();
await expect(page.getByLabel("bookmark-trigger")).toBeVisible();
});
});
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default defineConfig({
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 2 : undefined,
workers: process.env.CI ? 3 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
Expand Down

0 comments on commit a30156b

Please sign in to comment.