Skip to content

Commit 917d78e

Browse files
Merge branch 'develop' into fix-1102-implment-wysiwyg-to-see-article-exactly
2 parents 37a91d2 + 77aa243 commit 917d78e

File tree

3 files changed

+69
-20
lines changed

3 files changed

+69
-20
lines changed

components/ArticlePreview/ArticleLoading.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const ArticleLoading = () => (
2-
<div className="my-4 w-full border-l-4 border-l-pink-600 bg-white p-4 shadow dark:bg-neutral-900">
2+
<div
3+
className="my-4 w-full border-l-4 border-l-pink-600 bg-white p-4 shadow dark:bg-neutral-900"
4+
data-testid="article-loading-indicator"
5+
>
36
<div className="animate-pulse">
47
<div className="flex space-x-4">
58
<div className="h-10 w-10 rounded-full bg-neutral-300 dark:bg-neutral-800"></div>

e2e/articles.spec.ts

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { test, expect } from "playwright/test";
2+
import { randomUUID } from "crypto";
23

34
test.describe("Unauthenticated Articles Page", () => {
45
test.beforeEach(async ({ page }) => {
@@ -16,7 +17,7 @@ test.describe("Unauthenticated Articles Page", () => {
1617
);
1718
});
1819

19-
test("Should not show bookmark article icon", async ({ page }) => {
20+
test("Should show bookmark article icon", async ({ page }) => {
2021
await page.goto("http://localhost:3000/articles");
2122

2223
await expect(
@@ -25,7 +26,7 @@ test.describe("Unauthenticated Articles Page", () => {
2526

2627
await expect(
2728
page.locator("article").first().getByLabel("Bookmark this post"),
28-
).toBeHidden();
29+
).toBeVisible();
2930
});
3031
test("Should load more articles when scrolling to the end of the page", async ({
3132
page,
@@ -57,6 +58,24 @@ test.describe("Unauthenticated Articles Page", () => {
5758
await expect(page.getByText("Sponsorship")).toBeVisible();
5859
await expect(page.getByText("Code Of Conduct")).toBeVisible();
5960
});
61+
62+
test("Should not be able to post a comment on an article", async ({
63+
page,
64+
}) => {
65+
await page.goto("http://localhost:3000");
66+
// Waits for articles to be loaded
67+
await expect(page.getByText("Read Full Article").first()).toBeVisible();
68+
await page.getByText("Read Full Article").first().click();
69+
await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/);
70+
71+
await expect(page.getByPlaceholder("What do you think?")).toBeHidden();
72+
73+
await expect(page.getByText("Hey! 👋")).toBeVisible();
74+
await expect(page.getByText("Got something to say?")).toBeVisible();
75+
await expect(
76+
page.getByText("Sign in or sign up to leave a comment"),
77+
).toBeVisible();
78+
});
6079
});
6180

6281
test.describe("Authenticated Articles Page", () => {
@@ -102,27 +121,36 @@ test.describe("Authenticated Articles Page", () => {
102121
// Waits for articles to be loaded
103122
await page.waitForSelector("article");
104123

105-
const initialArticleCount = await page.$$eval(
106-
"article",
107-
(articles) => articles.length,
108-
);
124+
// This delays the requests by 100ms.
125+
// This is needed as the load more article request was resolving too fast
126+
await page.route("**/*", async (route) => {
127+
await new Promise((f) => setTimeout(f, 100));
128+
await route.continue();
129+
});
109130

110131
if (!isMobile) {
111-
await page.getByText("Code Of Conduct").scrollIntoViewIfNeeded();
112-
await page.waitForTimeout(5000);
113-
const finalArticleCount = await page.$$eval(
114-
"article",
115-
(articles) => articles.length,
116-
);
117-
expect(finalArticleCount).toBeGreaterThan(initialArticleCount);
132+
const articleLocator = page.locator("article");
133+
const initialArticleCount = await articleLocator.count();
134+
135+
await page
136+
.getByRole("link", { name: "Code Of Conduct" })
137+
.scrollIntoViewIfNeeded();
138+
139+
// We expect to see the loading indicator become visible why loading and then hidden when more articles are loaded
140+
await expect(page.getByTestId("article-loading-indicator")).toBeVisible();
141+
await expect(page.getByTestId("article-loading-indicator")).toBeHidden();
142+
143+
expect(await articleLocator.count()).toBeGreaterThan(initialArticleCount);
118144
}
119145

120-
await expect(page.getByText("Home")).toBeVisible();
146+
await expect(page.getByRole("link", { name: "Home" })).toBeVisible();
121147
await expect(
122148
page.getByLabel("Footer").getByRole("link", { name: "Events" }),
123149
).toBeVisible();
124-
await expect(page.getByText("Sponsorship")).toBeVisible();
125-
await expect(page.getByText("Code Of Conduct")).toBeVisible();
150+
await expect(page.getByRole("link", { name: "Sponsorship" })).toBeVisible();
151+
await expect(
152+
page.getByRole("link", { name: "Code Of Conduct" }),
153+
).toBeVisible();
126154
});
127155

128156
test("Should write and publish an article", async ({ page, isMobile }) => {
@@ -155,6 +183,7 @@ test.describe("Authenticated Articles Page", () => {
155183

156184
await expect(page.getByRole("button", { name: "Next" })).toBeVisible();
157185
await page.getByRole("button", { name: "Next" }).click();
186+
158187
await expect(
159188
page.getByRole("button", { name: "Publish now" }),
160189
).toBeVisible();
@@ -176,4 +205,19 @@ test.describe("Authenticated Articles Page", () => {
176205
await expect(page.getByLabel("like-trigger")).toBeVisible();
177206
await expect(page.getByLabel("bookmark-trigger")).toBeVisible();
178207
});
208+
209+
test("Should post a comment on an article", async ({ page }, workerInfo) => {
210+
const commentContent = `This is a great read. Thanks for posting! Sent from ${workerInfo.project.name} + ${randomUUID()}`;
211+
await page.goto("http://localhost:3000");
212+
// Waits for articles to be loaded
213+
await expect(page.getByText("Read Full Article").first()).toBeVisible();
214+
await page.getByText("Read Full Article").first().click();
215+
await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/);
216+
217+
await expect(page.getByPlaceholder("What do you think?")).toBeVisible();
218+
await page.getByPlaceholder("What do you think?").fill(commentContent);
219+
await page.getByRole("button", { name: "Submit" }).click();
220+
221+
await expect(page.getByText(commentContent)).toBeVisible();
222+
});
179223
});

playwright.config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,24 @@ export default defineConfig({
2929
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3030
trace: "on-first-retry",
3131
},
32+
expect: {
33+
timeout: 10000,
34+
},
3235

3336
/* Configure projects for major browsers */
3437
projects: [
3538
{ name: "setup", testMatch: /auth.setup\.ts/ },
3639
{
37-
name: "chromium",
40+
name: "Desktop Chrome",
3841
use: {
39-
...devices["Desktop Chrome"],
4042
storageState: "playwright/.auth/browser.json",
4143
},
4244
dependencies: ["setup"],
4345
},
4446

4547
// Example other browsers
4648
{
47-
name: "firefox",
49+
name: "Desktop Firefox",
4850
use: {
4951
...devices["Desktop Firefox"],
5052
storageState: "playwright/.auth/browser.json",

0 commit comments

Comments
 (0)