Skip to content

Commit 6d9b197

Browse files
committed
chore: removed flaky test from article suite
1 parent d32599b commit 6d9b197

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
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: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,36 @@ test.describe("Authenticated Articles Page", () => {
102102
// Waits for articles to be loaded
103103
await page.waitForSelector("article");
104104

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

110112
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);
113+
const articleLocator = page.locator("article");
114+
const initialArticleCount = await articleLocator.count();
115+
116+
await page
117+
.getByRole("link", { name: "Code Of Conduct" })
118+
.scrollIntoViewIfNeeded();
119+
120+
// We expect to see the loading indicator become visible why loading and then hidden when more articles are loaded
121+
await expect(page.getByTestId("article-loading-indicator")).toBeVisible();
122+
await expect(page.getByTestId("article-loading-indicator")).toBeHidden();
123+
124+
expect(await articleLocator.count()).toBeGreaterThan(initialArticleCount);
118125
}
119126

120-
await expect(page.getByText("Home")).toBeVisible();
127+
await expect(page.getByRole("link", { name: "Home" })).toBeVisible();
121128
await expect(
122129
page.getByLabel("Footer").getByRole("link", { name: "Events" }),
123130
).toBeVisible();
124-
await expect(page.getByText("Sponsorship")).toBeVisible();
125-
await expect(page.getByText("Code Of Conduct")).toBeVisible();
131+
await expect(page.getByRole("link", { name: "Sponsorship" })).toBeVisible();
132+
await expect(
133+
page.getByRole("link", { name: "Code Of Conduct" }),
134+
).toBeVisible();
126135
});
127136

128137
test("Should write and publish an article", async ({ page, isMobile }) => {

playwright.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ 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: [

0 commit comments

Comments
 (0)