diff --git a/packages/app/app/store/enhancers/syncStorage.test.js b/packages/app/app/store/enhancers/syncStorage.test.js new file mode 100644 index 0000000000..8216c1aa5f --- /dev/null +++ b/packages/app/app/store/enhancers/syncStorage.test.js @@ -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); + }); +}); diff --git a/packages/app/test/mockElectronStore.ts b/packages/app/test/mockElectronStore.ts index 3cf9a88047..aa738f6192 100644 --- a/packages/app/test/mockElectronStore.ts +++ b/packages/app/test/mockElectronStore.ts @@ -7,7 +7,11 @@ export const initialStoreState = () => ({ albums: [], tracks: [] }, - playlists: [] + playlists: [], + queue: { + queueItems: [], + currentSong: null + } }); export type MockStore = ReturnType; diff --git a/packages/app/test/storeBuilders.ts b/packages/app/test/storeBuilders.ts index 7264d9db59..bbfb9c846e 100644 --- a/packages/app/test/storeBuilders.ts +++ b/packages/app/test/storeBuilders.ts @@ -957,6 +957,10 @@ export const buildElectronStoreState = (overrides?: AnyProps) => { albums: [], tracks: [] }, + queue: { + queueItems: [], + currentSong: 0 + }, playlists: [], ...overrides }; diff --git a/packages/app/test/testUtils.tsx b/packages/app/test/testUtils.tsx index 4a22fb68cb..d760262b55 100644 --- a/packages/app/test/testUtils.tsx +++ b/packages/app/test/testUtils.tsx @@ -36,7 +36,11 @@ export const configureMockStore = (initialState?: AnyProps) => createStore( initialState, compose( applyMiddleware(ReduxPromise, thunk), - syncStore(['downloads']) + syncStore([ + 'downloads', + 'queue.queueItems', + 'queue.currentSong' + ]) ) );