Skip to content

Commit b12c86c

Browse files
committed
feat(toast): Add toast for API error handling in the frontend, page error
1 parent 2d48166 commit b12c86c

23 files changed

+244
-12
lines changed

frontend/__mocks__/hooks/api/aliases.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,28 @@ function getReturnValue(
134134
};
135135
}
136136

137+
function getErrorRandomReturnValue(): ReturnType<typeof useAliases> {
138+
return {
139+
randomAliasData: {
140+
isValidating: false,
141+
isLoading: false,
142+
error: { some_error_key: "some_error_val" },
143+
mutate: jest.fn(),
144+
data: undefined,
145+
},
146+
customAliasData: {
147+
isValidating: false,
148+
isLoading: false,
149+
error: { some_error_key: "some_error_val" },
150+
mutate: jest.fn(),
151+
data: undefined,
152+
},
153+
create: jest.fn(() => Promise.resolve({ ok: true } as unknown as Response)),
154+
update: jest.fn(() => Promise.resolve({ ok: true } as unknown as Response)),
155+
delete: jest.fn(() => Promise.resolve({ ok: true } as unknown as Response)),
156+
};
157+
}
158+
137159
export const setMockAliasesData = (
138160
aliasesData?: MockData,
139161
callbacks?: Callbacks,
@@ -147,3 +169,10 @@ export const setMockAliasesDataOnce = (
147169
) => {
148170
mockedUseAliases.mockReturnValueOnce(getReturnValue(aliasesData, callbacks));
149171
};
172+
173+
export const setMockAliasesErrorOnce = (
174+
aliasesData?: MockData,
175+
callbacks?: Callbacks,
176+
) => {
177+
mockedUseAliases.mockReturnValueOnce(getErrorRandomReturnValue());
178+
};

frontend/__mocks__/hooks/api/profile.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ function getReturnValue(
6262
};
6363
}
6464

65+
function getErrorReturnValue(): ReturnType<typeof useProfiles> {
66+
return {
67+
isValidating: false,
68+
mutate: jest.fn(),
69+
update: jest.fn(),
70+
data: undefined,
71+
setSubdomain: jest.fn(),
72+
isLoading: false,
73+
error: { some_error_key: "some_error_val" },
74+
};
75+
}
76+
6577
export const setMockProfileData = (
6678
profileData?: MockData | null,
6779
callbacks?: Callbacks,
@@ -75,3 +87,7 @@ export const setMockProfileDataOnce = (
7587
) => {
7688
mockedUseProfiles.mockReturnValueOnce(getReturnValue(profileData, callbacks));
7789
};
90+
91+
export const setMockProfileErrorOnce = () => {
92+
mockedUseProfiles.mockReturnValueOnce(getErrorReturnValue());
93+
};

frontend/__mocks__/hooks/api/relayNumber.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ function getReturnValue(
6060
};
6161
}
6262

63+
function getErrorReturnValue(): ReturnType<typeof useRelayNumber> {
64+
return {
65+
isValidating: false,
66+
isLoading: false,
67+
error: { some_error_key: "some_error_val" },
68+
mutate: jest.fn(),
69+
data: undefined,
70+
registerRelayNumber: jest.fn(() =>
71+
Promise.resolve({ ok: true } as unknown as Response),
72+
),
73+
setForwardingState: jest.fn(() =>
74+
Promise.resolve({ ok: true } as unknown as Response),
75+
),
76+
};
77+
}
78+
6379
export const setMockRelayNumberData = (
6480
relayNumbers?: Array<Partial<RelayNumber>>,
6581
callbacks?: Callbacks,
@@ -76,4 +92,8 @@ export const setMockRelayNumberDataOnce = (
7692
);
7793
};
7894

95+
export const setMockRelayNumberErrorOnce = () => {
96+
mockedUseRelayNumber.mockReturnValueOnce(getErrorReturnValue());
97+
};
98+
7999
export { useRelayNumber };

frontend/__mocks__/hooks/api/runtimeData.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,24 @@ function getReturnValue(
152152
};
153153
}
154154

155+
function getErrorReturnValue(): ReturnType<typeof useRuntimeData> {
156+
return {
157+
isValidating: false,
158+
mutate: jest.fn(),
159+
data: undefined,
160+
isLoading: false,
161+
error: { some_error_key: "some_error_val" },
162+
};
163+
}
164+
155165
export const setMockRuntimeData = (runtimeData?: Partial<RuntimeData>) => {
156166
mockedUseRuntimeData.mockReturnValue(getReturnValue(runtimeData));
157167
};
158168

159169
export const setMockRuntimeDataOnce = (runtimeData?: Partial<RuntimeData>) => {
160170
mockedUseRuntimeData.mockReturnValueOnce(getReturnValue(runtimeData));
161171
};
172+
173+
export const setMockRuntimeErrorOnce = (runtimeData?: Partial<RuntimeData>) => {
174+
mockedUseRuntimeData.mockReturnValueOnce(getErrorReturnValue());
175+
};

frontend/next-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference path="./.next/types/routes.d.ts" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.

frontend/src/components/dashboard/aliases/AliasDeletionButton.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { render, screen, within, waitFor } from "@testing-library/react";
22
import userEvent from "@testing-library/user-event";
33
import { mockConfigModule } from "../../../../__mocks__/configMock";
4+
import { mockUseL10nModule } from "../../../../__mocks__/hooks/l10n";
45
import { mockLocalizedModule } from "../../../../__mocks__/components/Localized";
56
import { getMockRandomAlias } from "../../../../__mocks__/hooks/api/aliases";
6-
import { mockUseL10nModule } from "../../../../__mocks__/hooks/l10n";
77

88
import * as aliasApi from "../../../hooks/api/aliases";
99
import { AliasDeletionButton } from "./AliasDeletionButton";

frontend/src/components/dashboard/aliases/AliasGenerationButton.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { render, screen } from "@testing-library/react";
22
import userEvent from "@testing-library/user-event";
33
import { mockConfigModule } from "../../../../__mocks__/configMock";
4+
import { mockUseL10nModule } from "../../../../__mocks__/hooks/l10n";
45
import { getMockRandomAlias } from "../../../../__mocks__/hooks/api/aliases";
56
import { getMockProfileData } from "../../../../__mocks__/hooks/api/profile";
67
import {
78
getMockRuntimeDataWithoutPremium,
89
getMockRuntimeDataWithPeriodicalPremium,
910
} from "../../../../__mocks__/hooks/api/runtimeData";
10-
import { mockUseL10nModule } from "../../../../__mocks__/hooks/l10n";
1111

1212
import { AliasGenerationButton } from "./AliasGenerationButton";
1313

frontend/src/components/dashboard/aliases/AliasList.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { render, screen } from "@testing-library/react";
33
import userEvent from "@testing-library/user-event";
44
import { mockLocalizedModule } from "../../../../__mocks__/components/Localized";
55
import { mockConfigModule } from "../../../../__mocks__/configMock";
6+
import { mockUseL10nModule } from "../../../../__mocks__/hooks/l10n";
67
import { getMockRandomAlias } from "../../../../__mocks__/hooks/api/aliases";
78
import { getMockProfileData } from "../../../../__mocks__/hooks/api/profile";
8-
import { mockUseL10nModule } from "../../../../__mocks__/hooks/l10n";
99
import * as LocalLabelsMock from "../../../../__mocks__/hooks/localLabels";
1010
import { AliasList } from "./AliasList";
1111

frontend/src/components/landing/PlanMatrix.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { render, screen } from "@testing-library/react";
22

33
import { mockLocalizedModule } from "../../../__mocks__/components/Localized";
44
import { mockConfigModule } from "../../../__mocks__/configMock";
5+
import { mockUseL10nModule } from "../../../__mocks__/hooks/l10n";
56
import { setMockProfileData } from "../../../__mocks__/hooks/api/profile";
67
import {
78
setMockRuntimeDataOnce,
@@ -10,7 +11,6 @@ import {
1011
getMockRuntimeDataWithoutPremium,
1112
} from "../../../__mocks__/hooks/api/runtimeData";
1213
import { mockUseFxaFlowTrackerModule } from "../../../__mocks__/hooks/fxaFlowTracker";
13-
import { mockUseL10nModule } from "../../../__mocks__/hooks/l10n";
1414
import { mockNextRouter } from "../../../__mocks__/modules/next__router";
1515
import { mockReactGa } from "../../../__mocks__/modules/react-ga";
1616

frontend/src/components/layout/navigation/Navigation.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { render, screen } from "@testing-library/react";
22
import { mockConfigModule } from "../../../../__mocks__/configMock";
3+
import { mockUseL10nModule } from "../../../../__mocks__/hooks/l10n";
34
import { setMockProfileData } from "../../../../__mocks__/hooks/api/profile";
45
import {
56
getMockRuntimeDataWithPeriodicalPremium,
@@ -8,7 +9,6 @@ import {
89
} from "../../../../__mocks__/hooks/api/runtimeData";
910
import { setMockUserData } from "../../../../__mocks__/hooks/api/user";
1011
import { mockUseFxaFlowTrackerModule } from "../../../../__mocks__/hooks/fxaFlowTracker";
11-
import { mockUseL10nModule } from "../../../../__mocks__/hooks/l10n";
1212
import { mockNextRouter } from "../../../../__mocks__/modules/next__router";
1313
import { mockReactIntersectionObsever } from "../../../../__mocks__/modules/react-intersection-observer";
1414

0 commit comments

Comments
 (0)