Skip to content

Commit adb99fb

Browse files
authored
feat(accounts): add action button to account errors (#2675)
* feat(error): action buttons Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix: test mock for client id Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix: test mock for client id Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix: test mock for client id Signed-off-by: Adam Setch <adam.setch@outlook.com> --------- Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent 57fc2f5 commit adb99fb

21 files changed

Lines changed: 368 additions & 868 deletions

src/renderer/__helpers__/test-utils.tsx

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
11
import { render } from '@testing-library/react';
22
import { type ReactElement, type ReactNode, useMemo } from 'react';
3+
import { MemoryRouter } from 'react-router-dom';
34

45
import { BaseStyles, ThemeProvider } from '@primer/react';
56

67
import { mockAuth, mockSettings } from '../__mocks__/state-mocks';
78

89
import { AppContext, type AppContextState } from '../context/App';
910

11+
export { navigateMock } from './vitest.setup';
1012
export type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> };
1113

14+
const EMPTY_APP_CONTEXT: TestAppContext = {};
15+
16+
interface RenderOptions extends Partial<AppContextState> {
17+
initialEntries?: string[];
18+
}
19+
20+
/**
21+
* Test context
22+
*/
23+
type TestAppContext = Partial<AppContextState>;
24+
1225
/**
1326
* Props for the AppContextProvider wrapper
1427
*/
1528
interface AppContextProviderProps {
1629
readonly children: ReactNode;
17-
readonly value?: Partial<AppContextState>;
30+
readonly value?: TestAppContext;
31+
readonly initialEntries?: string[];
1832
}
1933

2034
/**
2135
* Wrapper component that provides ThemeProvider, BaseStyles, and AppContext
2236
* with sensible defaults for testing.
2337
*/
24-
function AppContextProvider({ children, value = {} }: AppContextProviderProps) {
25-
const defaultValue: AppContextState = useMemo(() => {
38+
function AppContextProvider({
39+
children,
40+
value = EMPTY_APP_CONTEXT,
41+
initialEntries,
42+
}: AppContextProviderProps) {
43+
const defaultValue: TestAppContext = useMemo(() => {
2644
return {
2745
auth: mockAuth,
2846
settings: mockSettings,
@@ -58,17 +76,19 @@ function AppContextProvider({ children, value = {} }: AppContextProviderProps) {
5876
updateFilter: vi.fn(),
5977

6078
...value,
61-
} as AppContextState;
79+
} as TestAppContext;
6280
}, [value]);
6381

6482
return (
65-
<ThemeProvider>
66-
<BaseStyles>
67-
<AppContext.Provider value={defaultValue}>
68-
{children}
69-
</AppContext.Provider>
70-
</BaseStyles>
71-
</ThemeProvider>
83+
<MemoryRouter initialEntries={initialEntries}>
84+
<ThemeProvider>
85+
<BaseStyles>
86+
<AppContext.Provider value={defaultValue}>
87+
{children}
88+
</AppContext.Provider>
89+
</BaseStyles>
90+
</ThemeProvider>
91+
</MemoryRouter>
7292
);
7393
}
7494

@@ -80,11 +100,13 @@ function AppContextProvider({ children, value = {} }: AppContextProviderProps) {
80100
*/
81101
export function renderWithAppContext(
82102
ui: ReactElement,
83-
context: Partial<AppContextState> = {},
103+
{ initialEntries, ...context }: RenderOptions = {},
84104
) {
85105
return render(ui, {
86106
wrapper: ({ children }) => (
87-
<AppContextProvider value={context}>{children}</AppContextProvider>
107+
<AppContextProvider initialEntries={initialEntries} value={context}>
108+
{children}
109+
</AppContextProvider>
88110
),
89111
});
90112
}

src/renderer/__helpers__/vitest.setup.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import '@testing-library/jest-dom/vitest';
22

33
import { useFiltersStore } from '../stores';
44

5+
/**
6+
* Shared navigate mock — import from test-utils in any test that needs to assert on navigation
7+
*/
8+
export const navigateMock = vi.fn();
9+
vi.mock('react-router-dom', async () => ({
10+
...(await vi.importActual('react-router-dom')),
11+
useNavigate: () => navigateMock,
12+
}));
13+
514
// Sets timezone to UTC for consistent date/time in tests and snapshots
615
process.env.TZ = 'UTC';
716

@@ -10,6 +19,7 @@ process.env.TZ = 'UTC';
1019
*/
1120
beforeEach(() => {
1221
useFiltersStore.getState().reset();
22+
navigateMock.mockReset();
1323
});
1424

1525
/**

0 commit comments

Comments
 (0)