Skip to content

Commit a30156b

Browse files
chore: added article creation e2e test (#1139)
1 parent 2dc9bb8 commit a30156b

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

e2e/articles.spec.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,56 @@ test.describe("Authenticated Articles Page", () => {
124124
await expect(page.getByText("Sponsorship")).toBeVisible();
125125
await expect(page.getByText("Code Of Conduct")).toBeVisible();
126126
});
127+
128+
test("Should write and publish an article", async ({ page, isMobile }) => {
129+
const articleContent =
130+
"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.";
131+
const articleTitle = "Lorem Ipsum";
132+
await page.goto("http://localhost:3000");
133+
// Waits for articles to be loaded
134+
await page.waitForSelector("article");
135+
136+
// Mobile and Desktop have different ways to start writing an article
137+
if (isMobile) {
138+
await expect(
139+
page.getByRole("button", { name: "Open main menu" }),
140+
).toBeVisible();
141+
page.getByRole("button", { name: "Open main menu" }).tap();
142+
await expect(page.getByRole("link", { name: "New Post" })).toBeVisible();
143+
await page.getByRole("link", { name: "New Post" }).tap();
144+
} else {
145+
await expect(page.getByRole("link", { name: "New Post" })).toBeVisible();
146+
await page.getByRole("link", { name: "New Post" }).click();
147+
}
148+
await page.waitForURL("http:/localhost:3000/create");
149+
150+
await page.getByPlaceholder("Article title").fill(articleTitle);
151+
152+
await page
153+
.getByPlaceholder("Enter your content here 💖")
154+
.fill(articleContent);
155+
156+
await expect(page.getByRole("button", { name: "Next" })).toBeVisible();
157+
await page.getByRole("button", { name: "Next" }).click();
158+
await expect(
159+
page.getByRole("button", { name: "Publish now" }),
160+
).toBeVisible();
161+
await page.getByRole("button", { name: "Publish now" }).click();
162+
await page.waitForURL(
163+
/^http:\/\/localhost:3000\/articles\/lorem-ipsum-.*$/,
164+
);
165+
166+
await expect(page.getByText("Lorem ipsum dolor sit amet,")).toBeVisible();
167+
await expect(
168+
page.getByRole("heading", { name: "Lorem Ipsum" }),
169+
).toBeVisible();
170+
await expect(
171+
page.getByRole("heading", { name: "Written by E2E Test User" }),
172+
).toBeVisible();
173+
await expect(
174+
page.getByRole("heading", { name: "Discussion (0)" }),
175+
).toBeVisible();
176+
await expect(page.getByLabel("like-trigger")).toBeVisible();
177+
await expect(page.getByLabel("bookmark-trigger")).toBeVisible();
178+
});
127179
});

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default defineConfig({
1818
/* Retry on CI only */
1919
retries: process.env.CI ? 2 : 0,
2020
/* Opt out of parallel tests on CI. */
21-
workers: process.env.CI ? 2 : undefined,
21+
workers: process.env.CI ? 3 : undefined,
2222
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
2323
reporter: "html",
2424
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */

0 commit comments

Comments
 (0)