Skip to content

Commit f59e30e

Browse files
committed
Unit test added
1 parent 2ec760f commit f59e30e

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
import {
3+
initialStoreState,
4+
mockElectronStore
5+
} from '../../../test/mockElectronStore';
6+
import { configureMockStore } from '../../../test/testUtils';
7+
8+
describe('Store Initialization and Sync with electronStore', () => {
9+
let store;
10+
const mockedStore = mockElectronStore(initialStoreState());
11+
12+
13+
jest.mock('@nuclear/core', () => ({
14+
store: mockedStore
15+
}));
16+
17+
beforeEach(() => {
18+
mockedStore.set('queue.queueItems', [{ uuid: 1, title: 'Initial Song' }]);
19+
mockedStore.set('queue.currentSong', 0);
20+
mockedStore.set('nuclear.identity', { userId: '123' });
21+
22+
store = configureMockStore();
23+
});
24+
25+
it('loads initial state from electronStore correctly', () => {
26+
const state = store.getState();
27+
expect(state.queue.queueItems).toEqual([
28+
{ uuid: 1, title: 'Initial Song' }
29+
]);
30+
expect(state.queue.currentSong).toEqual(0);
31+
expect(state.nuclear.identity).toEqual({ userId: '123' });
32+
});
33+
34+
it('updates electronStore when state changes', () => {
35+
store.dispatch({
36+
type: 'UPDATE_QUEUE_ITEMS',
37+
payload: [{ uuid: 2, title: 'New Song' }]
38+
});
39+
store.dispatch({
40+
type: 'UPDATE_CURRENT_SONG',
41+
payload: 1
42+
});
43+
44+
expect(mockedStore.get('queue.queueItems')).toEqual([
45+
{ uuid: 2, title: 'New Song' }
46+
]);
47+
expect(mockedStore.get('queue.currentSong')).toEqual(1);
48+
});
49+
});

packages/app/test/mockElectronStore.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ export const initialStoreState = () => ({
77
albums: [],
88
tracks: []
99
},
10-
playlists: []
10+
playlists: [],
11+
queue: {
12+
queueItems: [],
13+
currentSong: null
14+
}
1115
});
1216

1317
export type MockStore = ReturnType<typeof initialStoreState>;

packages/app/test/storeBuilders.ts

+4
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,10 @@ export const buildElectronStoreState = (overrides?: AnyProps) => {
957957
albums: [],
958958
tracks: []
959959
},
960+
queue: {
961+
queueItems: [],
962+
currentSong: 0
963+
},
960964
playlists: [],
961965
...overrides
962966
};

packages/app/test/testUtils.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ export const configureMockStore = (initialState?: AnyProps) => createStore(
3636
initialState,
3737
compose(
3838
applyMiddleware(ReduxPromise, thunk),
39-
syncStore(['downloads'])
39+
syncStore([
40+
'downloads',
41+
'queue.queueItems',
42+
'queue.currentSong'
43+
])
4044
)
4145
);
4246

0 commit comments

Comments
 (0)