Skip to content

Commit 9c40ea3

Browse files
committed
test: enhance e2e tests with load state waits and improve visibility checks
1 parent f500011 commit 9c40ea3

File tree

7 files changed

+51
-20
lines changed

7 files changed

+51
-20
lines changed

e2e/admin.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ test.describe("Admin Dashboard", () => {
4343
// Should show Published Posts stat
4444
await expect(page.getByText("Published Posts")).toBeVisible();
4545

46-
// Should show Aggregated Articles stat
47-
await expect(page.getByText("Aggregated Articles")).toBeVisible();
48-
4946
// Should show Active Feed Sources stat
5047
await expect(page.getByText("Active Feed Sources")).toBeVisible();
48+
49+
// Should show Total Reports stat
50+
await expect(page.getByText("Total Reports")).toBeVisible();
5151
});
5252

5353
test("Should show moderation section", async ({ page }) => {

e2e/articles.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ test.describe("Authenticated Feed Page (Articles)", () => {
334334
await page.goto(
335335
"http://localhost:3000/e2e-test-user-one-111/e2e-test-slug-published",
336336
);
337+
await page.waitForLoadState("domcontentloaded");
337338

338339
// Wait for action bar to load - bookmark button has text "Save"
339340
await expect(page.getByRole("button", { name: "Save" })).toBeVisible({
@@ -343,9 +344,12 @@ test.describe("Authenticated Feed Page (Articles)", () => {
343344
// Click bookmark button
344345
await page.getByRole("button", { name: "Save" }).click();
345346

347+
// Wait for network request to complete
348+
await page.waitForTimeout(1000);
349+
346350
// Button text should change to "Saved" - add explicit timeout for slow mobile browsers
347351
await expect(page.getByRole("button", { name: "Saved" })).toBeVisible({
348-
timeout: 10000,
352+
timeout: 15000,
349353
});
350354
});
351355
});

e2e/editor.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,12 @@ test.describe("Publish Flow", () => {
795795

796796
test("Should show confirmation modal for write tab", async ({ page }) => {
797797
await page.goto(CREATE_URL);
798+
await page.waitForLoadState("domcontentloaded");
799+
800+
// Wait for title input to be visible
801+
await expect(page.locator(SELECTORS.titleInput)).toBeVisible({
802+
timeout: 15000,
803+
});
798804

799805
// Enter valid content
800806
await page.locator(SELECTORS.titleInput).fill("Article to Publish");
@@ -870,13 +876,14 @@ test.describe("Publish Flow", () => {
870876
page,
871877
}) => {
872878
await page.goto(`${CREATE_URL}?tab=link`);
879+
await page.waitForLoadState("domcontentloaded");
873880

874881
// Enter a URL and wait for metadata to auto-populate title
875882
await page.locator(SELECTORS.linkUrlInput).fill("https://example.com");
876883

877884
// Wait for metadata to be fetched and title to auto-populate
878885
const titleInput = page.locator(SELECTORS.linkTitleInput);
879-
await expect(titleInput).not.toHaveValue("", { timeout: 10000 });
886+
await expect(titleInput).not.toHaveValue("", { timeout: 15000 });
880887

881888
// Verify the title was auto-populated
882889
const titleValue = await titleInput.inputValue();

e2e/my-posts.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type TabName = "Drafts" | "Scheduled" | "Published";
77

88
async function openTab(page: Page, tabName: TabName) {
99
await page.goto("http://localhost:3000/my-posts");
10+
await page.waitForLoadState("domcontentloaded");
1011
await page.getByRole("link", { name: tabName }).click();
1112
const slug = tabName.toLowerCase();
1213
await page.waitForURL(`http://localhost:3000/my-posts?tab=${slug}`);
@@ -17,7 +18,8 @@ async function openTab(page: Page, tabName: TabName) {
1718
timeout: 20000,
1819
});
1920

20-
// Wait for at least one article to be visible (instead of hardcoded timeout)
21+
// Wait for network to settle and at least one article to be visible
22+
await page.waitForLoadState("domcontentloaded");
2123
await expect(page.locator("article").first()).toBeVisible({
2224
timeout: 15000,
2325
});

e2e/notifications.spec.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ test.describe("Notifications Page", () => {
2121

2222
test.describe("Authenticated - No Notifications", () => {
2323
test.beforeEach(async ({ page }) => {
24+
// Clear notifications for user two before testing empty state
25+
await clearNotifications(E2E_USER_TWO_ID);
2426
await loggedInAsUserTwo(page);
2527
});
2628

@@ -30,12 +32,14 @@ test.describe("Notifications Page", () => {
3032
page.getByRole("heading", { name: "Notifications" }),
3133
).toBeVisible();
3234
// Should show empty state message
33-
await expect(page.getByText("No new notifications")).toBeVisible();
35+
await expect(page.getByText(/No new notifications/)).toBeVisible();
3436
});
3537
});
3638

3739
test.describe("Authenticated - With Notifications", () => {
3840
test.beforeEach(async ({ page }) => {
41+
// Clear notifications before each test to ensure clean state
42+
await clearNotifications(E2E_USER_ONE_ID);
3943
await loggedInAsUserOne(page);
4044
});
4145

@@ -75,9 +79,11 @@ test.describe("Notifications Page", () => {
7579
});
7680

7781
await page.goto("http://localhost:3000/notifications");
82+
// Wait for notifications to load
83+
await page.waitForLoadState("domcontentloaded");
7884
await expect(
7985
page.getByRole("button", { name: "Mark all as read" }),
80-
).toBeVisible();
86+
).toBeVisible({ timeout: 15000 });
8187
});
8288

8389
test("Should be able to mark individual notification as read", async ({
@@ -91,10 +97,12 @@ test.describe("Notifications Page", () => {
9197
});
9298

9399
await page.goto("http://localhost:3000/notifications");
100+
// Wait for notifications to load
101+
await page.waitForLoadState("domcontentloaded");
94102

95103
// Wait for notification to appear
96104
await page.waitForSelector('button[title="Mark as read"]', {
97-
timeout: 10000,
105+
timeout: 15000,
98106
});
99107

100108
// Click mark as read button
@@ -216,13 +224,14 @@ test.describe("Notifications Page", () => {
216224
// Log back in as user one and check for notification
217225
await loggedInAsUserOne(page);
218226
await page.goto("http://localhost:3000/notifications");
227+
await page.waitForLoadState("domcontentloaded");
219228

220229
await expect(page.getByText("E2E Test User Two").first()).toBeVisible({
221230
timeout: 15000,
222231
});
223232
await expect(
224-
page.getByText("replied to your comment").first(),
225-
).toBeVisible();
233+
page.getByText(/replied to your comment/).first(),
234+
).toBeVisible({ timeout: 10000 });
226235
});
227236
});
228237
});

e2e/saved.spec.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,45 @@ test.describe("Authenticated Saved Page", () => {
3131
});
3232

3333
test("Should bookmark and appear in saved items", async ({ page }) => {
34-
// First, bookmark an article
34+
// First, bookmark an article from the feed (where bookmark-button testid exists)
3535
await page.goto("http://localhost:3000/feed?type=article");
36+
await page.waitForLoadState("domcontentloaded");
37+
38+
// Wait for articles to load
3639
await expect(page.locator("article").first()).toBeVisible({
3740
timeout: 15000,
3841
});
3942

4043
// Get the title of the first article before bookmarking
41-
const articleHeading = page.locator("article").first().locator("h2");
42-
await expect(articleHeading).toBeVisible();
44+
const firstArticle = page.locator("article").first();
45+
const articleHeading = firstArticle.locator("h2");
46+
await expect(articleHeading).toBeVisible({ timeout: 10000 });
4347
const articleTitle = await articleHeading.textContent();
4448

45-
// Click bookmark on first item and wait for it to complete
46-
const bookmarkButton = page.getByTestId("bookmark-button").first();
47-
await expect(bookmarkButton).toBeVisible();
49+
// Click bookmark on this specific article
50+
const bookmarkButton = firstArticle.getByTestId("bookmark-button");
51+
await expect(bookmarkButton).toBeVisible({ timeout: 10000 });
4852
await bookmarkButton.click();
4953

5054
// Wait for bookmark mutation to complete
51-
await page.waitForTimeout(1000);
55+
await page.waitForTimeout(2000);
5256

5357
// Navigate to saved page
5458
await page.goto("http://localhost:3000/saved");
5559
await page.waitForLoadState("domcontentloaded");
5660

57-
// The bookmarked article should appear - use filter for more resilient matching
61+
// The bookmarked article should appear - use the captured title
5862
if (articleTitle) {
5963
await expect(
6064
page.locator("article").filter({ hasText: articleTitle.trim() }),
6165
).toBeVisible({
6266
timeout: 15000,
6367
});
68+
} else {
69+
// Fallback - just check that an article is visible
70+
await expect(page.locator("article").first()).toBeVisible({
71+
timeout: 15000,
72+
});
6473
}
6574
});
6675

next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
import "./.next/types/routes.d.ts";
3+
import "./.next/dev/types/routes.d.ts";
44

55
// NOTE: This file should not be edited
66
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

0 commit comments

Comments
 (0)