Skip to content

Commit 91327e3

Browse files
MiodecclaudeCopilot
authored
refactor: solid notifications (@Miodec) (#7576)
Brr --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 65dabdd commit 91327e3

111 files changed

Lines changed: 1618 additions & 1426 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

frontend/__tests__/components/common/AsyncContent.spec.tsx

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
1010
import AsyncContent, {
1111
Props,
1212
} from "../../../src/ts/components/common/AsyncContent";
13-
import * as Notifications from "../../../src/ts/elements/notifications";
13+
import * as Notifications from "../../../src/ts/stores/notifications";
1414

1515
describe("AsyncContent", () => {
16-
const addNotificationMock = vi.spyOn(Notifications, "add");
16+
const notifyErrorMock = vi.spyOn(Notifications, "showErrorNotification");
1717

1818
beforeEach(() => {
19-
addNotificationMock.mockClear();
19+
notifyErrorMock.mockClear();
2020
});
2121

2222
describe("with single query", () => {
@@ -55,30 +55,30 @@ describe("AsyncContent", () => {
5555
});
5656

5757
it("renders default error message on fail", async () => {
58-
renderWithQuery({ result: new Error("Test error") });
58+
const error = new Error("Test error");
59+
renderWithQuery({ result: error });
5960

6061
await waitFor(() => {
6162
expect(screen.getByText(/An error occurred/)).toBeInTheDocument();
6263
});
63-
expect(addNotificationMock).toHaveBeenCalledWith(
64-
"An error occurred: Test error",
65-
-1,
66-
);
64+
expect(notifyErrorMock).toHaveBeenCalledWith("An error occurred", {
65+
error,
66+
});
6767
});
6868

6969
it("renders custom error message on fail", async () => {
70+
const error = new Error("Test error");
7071
renderWithQuery(
71-
{ result: new Error("Test error") },
72+
{ result: error },
7273
{ errorMessage: "Custom error message" },
7374
);
7475

7576
await waitFor(() => {
7677
expect(screen.getByText(/Custom error message/)).toBeInTheDocument();
7778
});
78-
expect(addNotificationMock).toHaveBeenCalledWith(
79-
"Custom error message: Test error",
80-
-1,
81-
);
79+
expect(notifyErrorMock).toHaveBeenCalledWith("Custom error message", {
80+
error,
81+
});
8282
});
8383

8484
it("ignores error on fail if ignoreError is set", async () => {
@@ -89,7 +89,7 @@ describe("AsyncContent", () => {
8989
await waitFor(() => {
9090
expect(screen.getByText(/no data/)).toBeInTheDocument();
9191
});
92-
expect(addNotificationMock).not.toHaveBeenCalled();
92+
expect(notifyErrorMock).not.toHaveBeenCalled();
9393
});
9494

9595
it("renders on pending if alwaysShowContent", async () => {
@@ -111,18 +111,18 @@ describe("AsyncContent", () => {
111111
});
112112

113113
it("renders on fail if alwaysShowContent", async () => {
114+
const error = new Error("Test error");
114115
renderWithQuery(
115-
{ result: new Error("Test error") },
116+
{ result: error },
116117
{ errorMessage: "Custom error message" },
117118
);
118119

119120
await waitFor(() => {
120121
expect(screen.getByText(/Custom error message/)).toBeInTheDocument();
121122
});
122-
expect(addNotificationMock).toHaveBeenCalledWith(
123-
"Custom error message: Test error",
124-
-1,
125-
);
123+
expect(notifyErrorMock).toHaveBeenCalledWith("Custom error message", {
124+
error,
125+
});
126126
});
127127

128128
function renderWithQuery(
@@ -216,30 +216,30 @@ describe("AsyncContent", () => {
216216
});
217217

218218
it("renders default error message on fail", async () => {
219-
renderWithQuery({ first: "data", second: new Error("Test error") });
219+
const error = new Error("Test error");
220+
renderWithQuery({ first: "data", second: error });
220221

221222
await waitFor(() => {
222223
expect(screen.getByText(/An error occurred/)).toBeInTheDocument();
223224
});
224-
expect(addNotificationMock).toHaveBeenCalledWith(
225-
"An error occurred: Test error",
226-
-1,
227-
);
225+
expect(notifyErrorMock).toHaveBeenCalledWith("An error occurred", {
226+
error,
227+
});
228228
});
229229

230230
it("renders custom error message on fail", async () => {
231+
const firstError = new Error("First error");
231232
renderWithQuery(
232-
{ first: new Error("First error"), second: new Error("Second error") },
233+
{ first: firstError, second: new Error("Second error") },
233234
{ errorMessage: "Custom error message" },
234235
);
235236

236237
await waitFor(() => {
237238
expect(screen.getByText(/Custom error message/)).toBeInTheDocument();
238239
});
239-
expect(addNotificationMock).toHaveBeenCalledWith(
240-
"Custom error message: First error",
241-
-1,
242-
);
240+
expect(notifyErrorMock).toHaveBeenCalledWith("Custom error message", {
241+
error: firstError,
242+
});
243243
});
244244

245245
it("ignores error on fail if ignoreError is set", async () => {
@@ -252,7 +252,7 @@ describe("AsyncContent", () => {
252252
expect(screen.getByText(/no data/)).toBeInTheDocument();
253253
});
254254

255-
expect(addNotificationMock).not.toHaveBeenCalled();
255+
expect(notifyErrorMock).not.toHaveBeenCalled();
256256
});
257257

258258
it("renders on pending if alwaysShowContent", async () => {
@@ -287,18 +287,18 @@ describe("AsyncContent", () => {
287287
});
288288

289289
it("renders on fail if alwaysShowContent", async () => {
290+
const error = new Error("Test error");
290291
renderWithQuery(
291-
{ first: "data", second: new Error("Test error") },
292+
{ first: "data", second: error },
292293
{ errorMessage: "Custom error message" },
293294
);
294295

295296
await waitFor(() => {
296297
expect(screen.getByText(/Custom error message/)).toBeInTheDocument();
297298
});
298-
expect(addNotificationMock).toHaveBeenCalledWith(
299-
"Custom error message: Test error",
300-
-1,
301-
);
299+
expect(notifyErrorMock).toHaveBeenCalledWith("Custom error message", {
300+
error,
301+
});
302302
});
303303

304304
function renderWithQuery(

frontend/__tests__/components/core/Theme.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
44

55
import { Theme } from "../../../src/ts/components/core/Theme";
66
import { ThemeWithName } from "../../../src/ts/constants/themes";
7-
import * as Notifications from "../../../src/ts/elements/notifications";
87
import * as Loader from "../../../src/ts/signals/loader-bar";
98
import * as ThemeSignal from "../../../src/ts/signals/theme";
9+
import * as Notifications from "../../../src/ts/stores/notifications";
1010

1111
vi.mock("../../../src/ts/constants/themes", () => ({
1212
themes: {
@@ -24,7 +24,7 @@ describe("Theme component", () => {
2424
const themeSignalMock = vi.spyOn(ThemeSignal, "getTheme");
2525
const loaderShowMock = vi.spyOn(Loader, "showLoaderBar");
2626
const loaderHideMock = vi.spyOn(Loader, "hideLoaderBar");
27-
const notificationAddMock = vi.spyOn(Notifications, "add");
27+
const notificationAddMock = vi.spyOn(Notifications, "showNoticeNotification");
2828

2929
beforeEach(() => {
3030
vi.useFakeTimers();
@@ -99,7 +99,7 @@ describe("Theme component", () => {
9999
expect(loaderShowMock).toHaveBeenCalledOnce();
100100
fireEvent.error(css);
101101
expect(loaderHideMock).toHaveBeenCalledOnce();
102-
expect(notificationAddMock).toHaveBeenCalledWith("Failed to load theme", 0);
102+
expect(notificationAddMock).toHaveBeenCalledWith("Failed to load theme");
103103
});
104104

105105
it("renders favicon", () => {

frontend/__tests__/controllers/preset-controller.spec.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as PresetController from "../../src/ts/controllers/preset-controller";
33
import { Preset } from "@monkeytype/schemas/presets";
44
import * as DB from "../../src/ts/db";
55
import * as UpdateConfig from "../../src/ts/config";
6-
import * as Notifications from "../../src/ts/elements/notifications";
6+
import * as Notifications from "../../src/ts/stores/notifications";
77
import * as TestLogic from "../../src/ts/test/test-logic";
88
import * as TagController from "../../src/ts/controllers/tag-controller";
99

@@ -25,7 +25,10 @@ describe("PresetController", () => {
2525
UpdateConfig,
2626
"getConfigChanges",
2727
);
28-
const notificationAddMock = vi.spyOn(Notifications, "add");
28+
const notificationAddMock = vi.spyOn(
29+
Notifications,
30+
"showSuccessNotification",
31+
);
2932
const testRestartMock = vi.spyOn(TestLogic, "restart");
3033
const tagControllerClearMock = vi.spyOn(TagController, "clear");
3134
const tagControllerSetMock = vi.spyOn(TagController, "set");
@@ -61,8 +64,8 @@ describe("PresetController", () => {
6164
expect(configApplyMock).toHaveBeenCalledWith(preset.config);
6265
expect(tagControllerClearMock).toHaveBeenCalled();
6366
expect(testRestartMock).toHaveBeenCalled();
64-
expect(notificationAddMock).toHaveBeenCalledWith("Preset applied", 1, {
65-
duration: 2,
67+
expect(notificationAddMock).toHaveBeenCalledWith("Preset applied", {
68+
durationMs: 2000,
6669
});
6770
expect(configSaveFullConfigMock).toHaveBeenCalled();
6871
});
@@ -121,8 +124,8 @@ describe("PresetController", () => {
121124
punctuation: true,
122125
});
123126
expect(testRestartMock).toHaveBeenCalled();
124-
expect(notificationAddMock).toHaveBeenCalledWith("Preset applied", 1, {
125-
duration: 2,
127+
expect(notificationAddMock).toHaveBeenCalledWith("Preset applied", {
128+
durationMs: 2000,
126129
});
127130
expect(configSaveFullConfigMock).toHaveBeenCalled();
128131
});

frontend/__tests__/root/config.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as FunboxValidation from "../../src/ts/test/funbox/funbox-validation";
1010
import * as ConfigValidation from "../../src/ts/config-validation";
1111
import * as ConfigEvent from "../../src/ts/observables/config-event";
1212
import * as ApeConfig from "../../src/ts/ape/config";
13-
import * as Notifications from "../../src/ts/elements/notifications";
13+
import * as Notifications from "../../src/ts/stores/notifications";
1414
const { replaceConfig, getConfig } = Config.__testing;
1515

1616
describe("Config", () => {
@@ -31,7 +31,10 @@ describe("Config", () => {
3131
);
3232
const dispatchConfigEventMock = vi.spyOn(ConfigEvent, "dispatch");
3333
const dbSaveConfigMock = vi.spyOn(ApeConfig, "saveConfig");
34-
const notificationAddMock = vi.spyOn(Notifications, "add");
34+
const notificationAddMock = vi.spyOn(
35+
Notifications,
36+
"showNoticeNotification",
37+
);
3538
const miscReloadAfterMock = vi.spyOn(Misc, "reloadAfter");
3639
const miscTriggerResizeMock = vi.spyOn(Misc, "triggerResize");
3740

@@ -89,7 +92,6 @@ describe("Config", () => {
8992
//THEN
9093
expect(notificationAddMock).toHaveBeenCalledWith(
9194
"No quit funbox is active. Please finish the test.",
92-
0,
9395
{
9496
important: true,
9597
},
@@ -269,7 +271,6 @@ describe("Config", () => {
269271
//THEN
270272
expect(notificationAddMock).toHaveBeenCalledWith(
271273
"Ad settings changed. Refreshing...",
272-
0,
273274
);
274275
expect(miscReloadAfterMock).toHaveBeenCalledWith(3);
275276
});

0 commit comments

Comments
 (0)