forked from Priyanshu-byte-coder/devtrack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.spec.js
More file actions
187 lines (168 loc) · 7.67 KB
/
Copy pathnotifications.spec.js
File metadata and controls
187 lines (168 loc) · 7.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import { expect, test } from "@playwright/test";
import { encode } from "next-auth/jwt";
const authSecret = "playwright-placeholder-secret-that-is-long-enough";
/** Returns a properly-shaped mock response for each metric endpoint. */
function mockMetricResponse(url) {
if (url.includes("/api/metrics/prs"))
return { open: 2, merged: 8, closed: 1, avgReviewHours: 6, avgFirstReviewHours: 3, mergeRate: "80%" };
if (url.includes("/api/metrics/pr-breakdown"))
return { draft: 1, merged: 8, open: 2, closed: 1 };
if (url.includes("/api/metrics/issues"))
return { opened: 4, closed: 3, currentlyOpen: 1, avgCloseTimeDays: 2, trend: 1, mostActiveRepo: "demo/repo" };
if (url.includes("/api/metrics/repos") || url.includes("/api/metrics/pinned-repos"))
return { repos: [{ name: "demo/repo", commits: 12, url: "https://github.com/demo/repo" }] };
if (url.includes("/api/metrics/languages"))
return { languages: [{ language: "TypeScript", count: 12 }] };
if (url.includes("/api/metrics/streak"))
return { current: 3, longest: 9, lastCommitDate: "2026-05-18", totalActiveDays: 12 };
if (url.includes("/api/metrics/weekly-summary"))
return {
commits: { current: 10, previous: 7, delta: 3, trend: "up" },
prs: { thisWeek: { opened: 3, merged: 2 }, lastWeek: { opened: 1, merged: 1 } },
activeDays: { thisWeek: 5, lastWeek: 4 },
streak: 3,
topRepo: "demo/repo",
};
if (url.includes("/api/metrics/compare"))
return { user: { commits: 10 }, friend: { commits: 8 } };
if (url.includes("/api/metrics/repo-health"))
return { repositories: [] };
if (url.includes("/api/metrics/ci"))
return { successRate: 95, averageDurationMinutes: 3, flakiestWorkflow: null, totalRuns: 42, reposChecked: 5 };
if (url.includes("/api/metrics/activity"))
return { data: [] };
if (url.includes("/api/metrics/commit-time"))
return { data: [] };
if (url.includes("/api/metrics/personal-records"))
return { records: [] };
if (url.includes("/api/metrics/discussions"))
return { total: 0, answered: 0 };
if (url.includes("/api/metrics/pr-review-trend"))
return { trend: [] };
if (url.includes("/api/metrics/inactive-repos"))
return { repos: [] };
if (url.includes("/api/metrics/coding-time"))
return { hasData: false, not_configured: true, todaysSeconds: 0, totalSeconds7Days: 0, chartData: [], topLanguage: "", topProject: "" };
if (url.includes("/api/metrics/coding-activity-insights"))
return { hourlyCounts: [], mostActiveHour: { hour: 0, count: 0, label: "" }, leastActiveHour: { hour: 0, count: 0, label: "" }, totalActivities: 0, averageDailyCommits: 0, consistencyScore: 0, productivityLevel: "Low", timezone: "UTC" };
if (url.includes("/api/metrics/contributions"))
return { data: { "2026-05-16": 3, "2026-05-17": 5, "2026-05-18": 2 } };
return {};
}
test.beforeEach(async ({ page }) => {
const token = await encode({
secret: process.env.NEXTAUTH_SECRET ?? authSecret,
token: {
name: "Playwright User",
email: "playwright@example.com",
githubLogin: "playwright-user",
githubId: "12345",
accessToken: "test-token",
expires: "2099-01-01T00:00:00.000Z",
},
});
await page.context().addCookies([
{
name: "next-auth.session-token",
value: String(token ?? ""),
domain: "127.0.0.1",
path: "/",
httpOnly: true,
sameSite: "Lax",
secure: false,
},
]);
await page.route("**/api/auth/session", async (route) => {
await route.fulfill({
contentType: "application/json",
body: JSON.stringify({
user: { name: "Playwright User", email: "playwright@example.com" },
githubLogin: "playwright-user",
githubId: "12345",
accessToken: "test-token",
expires: "2099-01-01T00:00:00.000Z",
}),
});
});
await page.route("**/api/user/settings", async (route) => {
await route.fulfill({ contentType: "application/json", body: JSON.stringify({ is_public: true }) });
});
await page.route("**/api/user/github-accounts", async (route) => {
await route.fulfill({ contentType: "application/json", body: JSON.stringify({ accounts: [] }) });
});
await page.route("**/api/goals/sync", async (route) => {
await route.fulfill({ contentType: "application/json", body: JSON.stringify({ updated: 1, commitCount: 4 }) });
});
await page.route("**/api/goals**", async (route) => {
if (route.request().method() === "POST") {
await route.fulfill({ contentType: "application/json", status: 201, body: JSON.stringify({ ok: true }) });
return;
}
await route.fulfill({
contentType: "application/json",
body: JSON.stringify({
goals: [{ id: "goal-1", title: "Make 10 commits", target: 10, current: 4, unit: "commits", recurrence: "weekly", period_start: "2026-05-18", last_synced_at: new Date().toISOString() }],
}),
});
});
await page.route("**/api/ai-insights**", async (route) => {
await route.fulfill({
contentType: "application/json",
body: JSON.stringify({
data: {
insights: [{ id: "insight-1", type: "productivity", title: "High Consistency", description: "You have coded 5 days this week!", severity: "positive" }],
trend: { direction: "up", percentage: 15 },
aiSummary: "Great job shipping features this week.",
generatedAt: "2026-05-18T12:00:00.000Z",
},
}),
});
});
const metricRoutes = [
"**/api/metrics/prs**", "**/api/metrics/pr-breakdown**", "**/api/metrics/issues**",
"**/api/metrics/repos**", "**/api/metrics/languages**", "**/api/metrics/streak**",
"**/api/metrics/pinned-repos**", "**/api/metrics/weekly-summary**", "**/api/metrics/compare**",
"**/api/metrics/repo-health**", "**/api/metrics/ci**", "**/api/streak/freeze**",
"**/api/metrics/activity**", "**/api/metrics/commit-time**", "**/api/metrics/personal-records**",
"**/api/metrics/discussions**", "**/api/metrics/pr-review-trend**", "**/api/metrics/inactive-repos**",
"**/api/metrics/contributions**", "**/api/metrics/coding-time**", "**/api/metrics/coding-activity-insights**",
"**/api/local-coding/stats**",
];
for (const pattern of metricRoutes) {
await page.route(pattern, async (route) => {
await route.fulfill({
contentType: "application/json",
body: JSON.stringify(mockMetricResponse(route.request().url())),
});
});
}
await page.route("**/api/stream**", async (route) => {
await route.fulfill({ status: 200, contentType: "text/event-stream", body: "data: {}\n\n" });
});
});
test("notification bell opens and closes drawer", async ({ page }) => {
await page.route("**/api/notifications**", async (route) => {
await route.fulfill({
contentType: "application/json",
body: JSON.stringify({
notifications: [
{ id: "1", type: "info", message: "Test notification", read: false, created_at: new Date().toISOString() },
],
unreadCount: 1,
}),
});
});
await page.goto("/dashboard", { waitUntil: "load" });
// Wait for the dashboard to fully render
await expect(page.getByRole("heading", { name: /dashboard/i })).toBeVisible({ timeout: 30000 });
// Find and click the notification bell
const bellButton = page.getByRole("button", { name: /Notifications/ });
await expect(bellButton).toBeVisible({ timeout: 10000 });
await bellButton.click();
const drawerHeading = page.getByRole("heading", { name: "Notifications" });
await expect(drawerHeading).toBeVisible({ timeout: 5000 });
await expect(page.getByText("Test notification")).toBeVisible({ timeout: 5000 });
// Click again to close
await bellButton.click();
await expect(drawerHeading).not.toBeVisible({ timeout: 5000 });
});