Skip to content

Commit 0bf9f73

Browse files
committed
refactor: tanstack & zustand overhaul
Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent 136e7e8 commit 0bf9f73

40 files changed

Lines changed: 486 additions & 657 deletions

biome.json

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
22
"$schema": "https://biomejs.dev/schemas/2.4.3/schema.json",
33
"files": {
4-
"includes": [
5-
"**",
6-
"!**/generated/**/*"
7-
]
4+
"includes": ["**", "!**/generated/**/*"]
85
},
96
"assist": {
107
"actions": {
@@ -15,33 +12,21 @@
1512
"groups": [
1613
":NODE:",
1714
":BLANK_LINE:",
18-
[
19-
"react*",
20-
"@testing-library/**"
21-
],
15+
["react*", "@testing-library/**"],
2216
":BLANK_LINE:",
23-
[
24-
"*electron*",
25-
"menubar"
26-
],
17+
["*electron*", "menubar"],
2718
":BLANK_LINE:",
2819
"@primer/**",
2920
":BLANK_LINE:",
3021
"@octokit/**",
3122
":BLANK_LINE:",
3223
":PACKAGE:",
3324
":BLANK_LINE:",
34-
[
35-
"**/__mocks__/**",
36-
"**/__helpers__/**"
37-
],
25+
["**/__mocks__/**", "**/__helpers__/**"],
3826
":BLANK_LINE:",
3927
"**/shared/**",
4028
":BLANK_LINE:",
41-
[
42-
"**/constants",
43-
"**/constants/**"
44-
],
29+
["**/constants", "**/constants/**"],
4530
":BLANK_LINE:",
4631
[
4732
"**/context/**",
@@ -95,10 +80,7 @@
9580
"useHookAtTopLevel": {
9681
"level": "error",
9782
"options": {
98-
"ignore": [
99-
"useAlternateIdleIcon",
100-
"useUnreadActiveIcon"
101-
]
83+
"ignore": ["useAlternateIdleIcon", "useUnreadActiveIcon"]
10284
}
10385
}
10486
},
@@ -151,4 +133,4 @@
151133
"clientKind": "git",
152134
"useIgnoreFile": true
153135
}
154-
}
136+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@
143143
"*": "biome check --no-errors-on-unmatched",
144144
"*.{js,ts,tsx}": "pnpm test --changed --passWithNoTests --update"
145145
}
146-
}
146+
}

src/renderer/__helpers__/test-utils.tsx

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,37 @@ import { type ReactElement, type ReactNode, useMemo } from 'react';
33

44
import { BaseStyles, ThemeProvider } from '@primer/react';
55

6-
import { mockAuth, mockSettings } from '../__mocks__/state-mocks';
6+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
77

88
import { AppContext, type AppContextState } from '../context/App';
99

1010
export type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> };
1111

12+
const EMPTY_APP_CONTEXT: Partial<AppContextState> = {};
13+
14+
/**
15+
* Test context (settings removed as it's no longer in context)
16+
*/
17+
type TestAppContext = Partial<AppContextState>;
18+
1219
/**
1320
* Props for the AppContextProvider wrapper
1421
*/
1522
interface AppContextProviderProps {
1623
readonly children: ReactNode;
17-
readonly value?: Partial<AppContextState>;
24+
readonly value?: TestAppContext;
1825
}
1926

2027
/**
2128
* Wrapper component that provides ThemeProvider, BaseStyles, and AppContext
2229
* with sensible defaults for testing.
2330
*/
24-
function AppContextProvider({ children, value = {} }: AppContextProviderProps) {
31+
function AppContextProvider({
32+
children,
33+
value = EMPTY_APP_CONTEXT,
34+
}: AppContextProviderProps) {
2535
const defaultValue: AppContextState = useMemo(() => {
2636
return {
27-
auth: mockAuth,
28-
settings: mockSettings,
29-
isLoggedIn: true,
30-
3137
notifications: [],
3238
notificationCount: 0,
3339
unreadNotificationCount: 0,
@@ -52,11 +58,6 @@ function AppContextProvider({ children, value = {} }: AppContextProviderProps) {
5258
markNotificationsAsDone: vi.fn(),
5359
unsubscribeNotification: vi.fn(),
5460

55-
clearFilters: vi.fn(),
56-
resetSettings: vi.fn(),
57-
updateSetting: vi.fn(),
58-
updateFilter: vi.fn(),
59-
6061
...value,
6162
} as AppContextState;
6263
}, [value]);
@@ -82,9 +83,21 @@ export function renderWithAppContext(
8283
ui: ReactElement,
8384
context: Partial<AppContextState> = {},
8485
) {
86+
const queryClient = new QueryClient({
87+
defaultOptions: {
88+
queries: {
89+
retry: false,
90+
refetchOnWindowFocus: false,
91+
refetchInterval: false,
92+
},
93+
},
94+
});
95+
8596
return render(ui, {
8697
wrapper: ({ children }) => (
87-
<AppContextProvider value={context}>{children}</AppContextProvider>
98+
<QueryClientProvider client={queryClient}>
99+
<AppContextProvider value={context}>{children}</AppContextProvider>
100+
</QueryClientProvider>
88101
),
89102
});
90103
}

src/renderer/components/AllRead.test.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {
44
ensureStableEmojis,
55
renderWithAppContext,
66
} from '../__helpers__/test-utils';
7-
import { mockSettings } from '../__mocks__/state-mocks';
87

98
import { useFiltersStore } from '../stores';
9+
1010
import { AllRead } from './AllRead';
1111

1212
describe('renderer/components/AllRead.tsx', () => {
@@ -18,11 +18,7 @@ describe('renderer/components/AllRead.tsx', () => {
1818
let tree: ReturnType<typeof renderWithAppContext> | null = null;
1919

2020
await act(async () => {
21-
tree = renderWithAppContext(<AllRead />, {
22-
settings: {
23-
...mockSettings,
24-
},
25-
});
21+
tree = renderWithAppContext(<AllRead />);
2622
});
2723

2824
expect(tree.container).toMatchSnapshot();
@@ -34,11 +30,7 @@ describe('renderer/components/AllRead.tsx', () => {
3430
let tree: ReturnType<typeof renderWithAppContext> | null = null;
3531

3632
await act(async () => {
37-
tree = renderWithAppContext(<AllRead />, {
38-
settings: {
39-
...mockSettings,
40-
},
41-
});
33+
tree = renderWithAppContext(<AllRead />);
4234
});
4335

4436
expect(tree.container).toMatchSnapshot();

src/renderer/components/AllRead.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { type FC, useMemo } from 'react';
22

33
import { Constants } from '../constants';
44

5-
import { EmojiSplash } from './layout/EmojiSplash';
6-
75
import { useFiltersStore } from '../stores';
86

7+
import { EmojiSplash } from './layout/EmojiSplash';
8+
99
interface AllReadProps {
1010
fullHeight?: boolean;
1111
}

0 commit comments

Comments
 (0)