Skip to content

Commit 6e92942

Browse files
committed
fix: comprehensive tests and correct slice/test typing for uiSlice (Zustand/Immer)
1 parent b4cc125 commit 6e92942

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

app/store/uiSlice.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { create } from 'zustand';
2+
import { immer } from 'zustand/middleware/immer';
3+
import { createUISlice, UISlice } from './uiSlice';
4+
import type { StateCreator } from 'zustand';
5+
6+
interface MockTextGeneratorState extends UISlice {}
7+
8+
const createMockUISlice: StateCreator<
9+
MockTextGeneratorState,
10+
[['zustand/immer', never]],
11+
[],
12+
UISlice
13+
> = (...args: [any, any, any?]) => createUISlice(...args);
14+
15+
describe('uiSlice', () => {
16+
let store: ReturnType<typeof setupStore>;
17+
18+
const setupStore = () =>
19+
create<MockTextGeneratorState>()(
20+
immer((...args: [any, any, any?]) => ({
21+
...createMockUISlice(...args),
22+
}))
23+
);
24+
25+
beforeEach(() => {
26+
store = setupStore();
27+
});
28+
29+
it('should have initial state', () => {
30+
expect(store.getState().showLoginPrompt).toBe(true);
31+
expect(store.getState().showContent).toBe(false);
32+
expect(store.getState().showQuestionSection).toBe(false);
33+
expect(store.getState().showExplanation).toBe(false);
34+
});
35+
36+
it('setShowLoginPrompt updates showLoginPrompt', () => {
37+
store.getState().setShowLoginPrompt(false);
38+
expect(store.getState().showLoginPrompt).toBe(false);
39+
store.getState().setShowLoginPrompt(true);
40+
expect(store.getState().showLoginPrompt).toBe(true);
41+
});
42+
43+
it('setShowContent updates showContent', () => {
44+
store.getState().setShowContent(true);
45+
expect(store.getState().showContent).toBe(true);
46+
store.getState().setShowContent(false);
47+
expect(store.getState().showContent).toBe(false);
48+
});
49+
50+
it('setShowQuestionSection updates showQuestionSection', () => {
51+
store.getState().setShowQuestionSection(true);
52+
expect(store.getState().showQuestionSection).toBe(true);
53+
store.getState().setShowQuestionSection(false);
54+
expect(store.getState().showQuestionSection).toBe(false);
55+
});
56+
57+
it('setShowExplanation updates showExplanation', () => {
58+
store.getState().setShowExplanation(true);
59+
expect(store.getState().showExplanation).toBe(true);
60+
store.getState().setShowExplanation(false);
61+
expect(store.getState().showExplanation).toBe(false);
62+
});
63+
});

0 commit comments

Comments
 (0)