Skip to content

Commit

Permalink
Unit test added
Browse files Browse the repository at this point in the history
  • Loading branch information
demiNoseda committed May 13, 2024
1 parent 2ec760f commit f59e30e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
49 changes: 49 additions & 0 deletions packages/app/app/store/enhancers/syncStorage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

import {
initialStoreState,
mockElectronStore
} from '../../../test/mockElectronStore';
import { configureMockStore } from '../../../test/testUtils';

describe('Store Initialization and Sync with electronStore', () => {
let store;
const mockedStore = mockElectronStore(initialStoreState());


jest.mock('@nuclear/core', () => ({
store: mockedStore
}));

beforeEach(() => {
mockedStore.set('queue.queueItems', [{ uuid: 1, title: 'Initial Song' }]);
mockedStore.set('queue.currentSong', 0);
mockedStore.set('nuclear.identity', { userId: '123' });

store = configureMockStore();
});

it('loads initial state from electronStore correctly', () => {
const state = store.getState();
expect(state.queue.queueItems).toEqual([
{ uuid: 1, title: 'Initial Song' }
]);
expect(state.queue.currentSong).toEqual(0);
expect(state.nuclear.identity).toEqual({ userId: '123' });
});

it('updates electronStore when state changes', () => {
store.dispatch({
type: 'UPDATE_QUEUE_ITEMS',
payload: [{ uuid: 2, title: 'New Song' }]
});
store.dispatch({
type: 'UPDATE_CURRENT_SONG',
payload: 1
});

expect(mockedStore.get('queue.queueItems')).toEqual([
{ uuid: 2, title: 'New Song' }
]);
expect(mockedStore.get('queue.currentSong')).toEqual(1);
});
});
6 changes: 5 additions & 1 deletion packages/app/test/mockElectronStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export const initialStoreState = () => ({
albums: [],
tracks: []
},
playlists: []
playlists: [],
queue: {
queueItems: [],
currentSong: null
}
});

export type MockStore = ReturnType<typeof initialStoreState>;
Expand Down
4 changes: 4 additions & 0 deletions packages/app/test/storeBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,10 @@ export const buildElectronStoreState = (overrides?: AnyProps) => {
albums: [],
tracks: []
},
queue: {
queueItems: [],
currentSong: 0
},
playlists: [],
...overrides
};
Expand Down
6 changes: 5 additions & 1 deletion packages/app/test/testUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export const configureMockStore = (initialState?: AnyProps) => createStore(
initialState,
compose(
applyMiddleware(ReduxPromise, thunk),
syncStore(['downloads'])
syncStore([
'downloads',
'queue.queueItems',
'queue.currentSong'
])
)
);

Expand Down

0 comments on commit f59e30e

Please sign in to comment.