Skip to content

Commit b508792

Browse files
committed
refactor: streamline error handling and improve test reliability across actions and notifications
1 parent 5a911ec commit b508792

6 files changed

Lines changed: 50 additions & 40 deletions

File tree

app/(app)/alpha/additional-details/_actions.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { getServerAuthSession } from "@/server/auth";
44
import { redirect } from "next/navigation";
5-
import { z } from "zod";
65

76
import {
87
type TypeSlideOneSchema,
@@ -35,12 +34,7 @@ export async function slideOneSubmitAction(dataInput: TypeSlideOneSchema) {
3534
.where(eq(user.id, session.user.id));
3635

3736
return true;
38-
} catch (error) {
39-
if (error instanceof z.ZodError) {
40-
console.error("Validation error:", error.issues);
41-
} else {
42-
console.error("Error updating the User model:", error);
43-
}
37+
} catch {
4438
return false;
4539
}
4640
}
@@ -63,12 +57,7 @@ export async function slideTwoSubmitAction(dataInput: TypeSlideTwoSchema) {
6357
.where(eq(user.id, session.user.id));
6458

6559
return true;
66-
} catch (error) {
67-
if (error instanceof z.ZodError) {
68-
console.error("Validation error:", error.issues);
69-
} else {
70-
console.error("Error updating the User model:", error);
71-
}
60+
} catch {
7261
return false;
7362
}
7463
}
@@ -95,12 +84,7 @@ export async function slideThreeSubmitAction(dataInput: TypeSlideThreeSchema) {
9584
.where(eq(user.id, session.user.id));
9685

9786
return true;
98-
} catch (error) {
99-
if (error instanceof z.ZodError) {
100-
console.error("Validation error:", error.issues);
101-
} else {
102-
console.error("Error updating the User model:", error);
103-
}
87+
} catch {
10488
return false;
10589
}
10690
}

app/(app)/alpha/additional-details/_client.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function SlideOne({ details }: { details: UserDetails }) {
120120
} else {
121121
toast.error("Error, saving was unsuccessful.");
122122
}
123-
} catch (error) {
123+
} catch {
124124
toast.error("An unexpected error occurred.");
125125
}
126126
};
@@ -274,7 +274,7 @@ function SlideTwo({ details }: { details: UserDetails }) {
274274
} else {
275275
toast.error("Error, saving was unsuccessful.");
276276
}
277-
} catch (error) {
277+
} catch {
278278
toast.error("An unexpected error occurred.");
279279
}
280280
};
@@ -441,7 +441,7 @@ function SlideThree({ details }: { details: UserDetails }) {
441441
} else {
442442
toast.error("Error, saving was unsuccessful.");
443443
}
444-
} catch (error) {
444+
} catch {
445445
toast.error("An unexpected error occurred.");
446446
}
447447
}

e2e/admin.spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,19 @@ test.describe("Admin Dashboard", () => {
9292

9393
test("Should navigate to feed sources", async ({ page }) => {
9494
await page.goto("http://localhost:3000/admin");
95+
await page.waitForLoadState("domcontentloaded");
96+
9597
// Use role link to be more specific since "Feed Sources" appears multiple times
96-
await page
97-
.getByRole("link", { name: /Feed Sources.*Manage RSS feed/i })
98-
.click();
98+
const feedSourcesLink = page.getByRole("link", {
99+
name: /Feed Sources.*Manage RSS feed/i,
100+
});
101+
await expect(feedSourcesLink).toBeVisible({ timeout: 10000 });
102+
103+
// Wait for navigation to complete after click
104+
await Promise.all([
105+
page.waitForURL("http://localhost:3000/admin/sources"),
106+
feedSourcesLink.click(),
107+
]);
99108
await expect(page).toHaveURL("http://localhost:3000/admin/sources");
100109
});
101110
});

e2e/articles.spec.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ test.describe("Authenticated Feed Page (Articles)", () => {
337337
await page.waitForLoadState("domcontentloaded");
338338

339339
// Wait for action bar to load - bookmark button has text "Save"
340-
await expect(page.getByRole("button", { name: "Save" })).toBeVisible({
341-
timeout: 15000,
342-
});
340+
const saveButton = page.getByRole("button", { name: "Save" });
341+
await expect(saveButton).toBeVisible({ timeout: 15000 });
342+
await expect(saveButton).toBeEnabled({ timeout: 5000 });
343343

344344
// Wait for TRPC bookmark mutation response
345345
const bookmarkResponsePromise = page.waitForResponse(
@@ -348,12 +348,15 @@ test.describe("Authenticated Feed Page (Articles)", () => {
348348
response.url().includes("bookmark") &&
349349
response.status() === 200,
350350
);
351-
await page.getByRole("button", { name: "Save" }).click();
351+
await saveButton.click();
352352
await bookmarkResponsePromise;
353353

354-
// Button text should change to "Saved" - add explicit timeout for slow mobile browsers
354+
// Wait for DOM to update after TRPC response
355+
await page.waitForLoadState("domcontentloaded");
356+
357+
// Button text should change to "Saved" - use toHaveText with polling for reliability
355358
await expect(page.getByRole("button", { name: "Saved" })).toBeVisible({
356-
timeout: 15000,
359+
timeout: 20000,
357360
});
358361
});
359362
});

e2e/my-posts.spec.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,31 @@ async function openTab(
1717
if (isMobile) {
1818
const tabSelect = page.locator("select#tabs");
1919
await expect(tabSelect).toBeVisible({ timeout: 10000 });
20+
await expect(tabSelect).toBeEnabled({ timeout: 5000 });
2021
await tabSelect.selectOption({ label: tabName });
22+
// Wait for mobile navigation to settle
23+
await page.waitForLoadState("domcontentloaded");
2124
} else {
2225
await page.getByRole("link", { name: tabName }).click();
2326
}
2427

2528
const slug = tabName.toLowerCase();
26-
await page.waitForURL(`http://localhost:3000/my-posts?tab=${slug}`);
29+
await page.waitForURL(`http://localhost:3000/my-posts?tab=${slug}`, {
30+
timeout: 15000,
31+
});
2732
await expect(page).toHaveURL(new RegExp(`\\/my-posts\\?tab=${slug}`));
2833

2934
// Wait for loading state to complete
3035
await expect(page.getByText("Fetching your posts...")).toBeHidden({
3136
timeout: 20000,
3237
});
3338

34-
// Wait for network to settle and at least one article to be visible
39+
// Wait for network to settle and content to load
3540
await page.waitForLoadState("domcontentloaded");
41+
42+
// Wait for at least one article to be visible with increased timeout for mobile
3643
await expect(page.locator("article").first()).toBeVisible({
37-
timeout: 15000,
44+
timeout: 20000,
3845
});
3946
}
4047

@@ -74,7 +81,9 @@ test.describe("Authenticated my-posts Page", () => {
7481
const tabSelect = page.locator("select#tabs");
7582
await expect(tabSelect).toBeVisible({ timeout: 10000 });
7683
// Verify the select has the correct options
77-
await expect(tabSelect.locator('option:has-text("Drafts")')).toBeVisible();
84+
await expect(
85+
tabSelect.locator('option:has-text("Drafts")'),
86+
).toBeVisible();
7887
await expect(
7988
tabSelect.locator('option:has-text("Scheduled")'),
8089
).toBeVisible();

e2e/notifications.spec.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,15 @@ test.describe("Notifications Page", () => {
113113
await page.goto("http://localhost:3000/notifications");
114114
await responsePromise;
115115

116-
// Wait for notification to appear
117-
await page.waitForSelector('button[title="Mark as read"]', {
118-
timeout: 15000,
119-
});
116+
// Wait for page to stabilize after TRPC response
117+
await page.waitForLoadState("domcontentloaded");
118+
119+
// Wait for the mark as read button to be visible and enabled
120+
const markAsReadButton = page
121+
.locator('button[title="Mark as read"]')
122+
.first();
123+
await expect(markAsReadButton).toBeVisible({ timeout: 15000 });
124+
await expect(markAsReadButton).toBeEnabled({ timeout: 5000 });
120125

121126
// Click mark as read button and wait for mutation response
122127
const markReadResponsePromise = page.waitForResponse(
@@ -125,7 +130,7 @@ test.describe("Notifications Page", () => {
125130
response.url().includes("notification") &&
126131
response.status() === 200,
127132
);
128-
await page.locator('button[title="Mark as read"]').first().click();
133+
await markAsReadButton.click();
129134
await markReadResponsePromise;
130135
});
131136
});

0 commit comments

Comments
 (0)