Skip to content

Commit

Permalink
Set up custom navigation history for component test
Browse files Browse the repository at this point in the history
  • Loading branch information
sferra committed Mar 21, 2024
1 parent c35949a commit 8fe1c39
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { createMemoryHistory } from 'history';
import { store as electronStore } from '@nuclear/core';

import { buildElectronStoreState, buildStoreState } from '../../../test/storeBuilders';
import { AnyProps, configureMockStore, setupI18Next, TestRouterProvider, TestStoreProvider } from '../../../test/testUtils';
import {
AnyProps,
configureMockStore,
setupI18Next,
TestRouterProvider,
TestStoreProvider
} from '../../../test/testUtils';
import MainContentContainer from '../MainContentContainer';
import { onReorder } from '.';

Expand Down Expand Up @@ -185,7 +191,13 @@ describe('Playlist view container', () => {
});

it('should delete a single track from the playlist', async () => {
const { component, store } = mountComponent();
const { component, history, store } = mountComponent(
undefined,
[
'/playlist/test-playlist-id',
'/previous-location'
]
);
await waitFor(() => component.getAllByTestId('delete-button')[0].click());

const state = store.getState();
Expand All @@ -196,6 +208,9 @@ describe('Playlist view container', () => {
name: 'test track 22'
})
]);
// FIXME: the expectations below don't work because the history instance is only the initial state, and not the modified state
expect(history.length).toBe(1);
expect(history.location).toBe('/previous-location');
});

it('should delete a single track from the playlist when there are its duplicates', async () => {
Expand Down Expand Up @@ -242,7 +257,7 @@ describe('Playlist view container', () => {
]);
});

const mountComponent = (initialStore?: AnyProps, initStore = true) => {
const mountComponent = (initialStore?: AnyProps, initialHistory?: string[], initStore = true) => {
const initialState = initialStore ||
buildStoreState()
.withPlugins()
Expand All @@ -257,7 +272,7 @@ describe('Playlist view container', () => {
});

const history = createMemoryHistory({
initialEntries: ['/playlist/test-playlist-id']
initialEntries: initialHistory || ['/playlist/test-playlist-id']
});

const store = configureMockStore(initialState);
Expand Down

0 comments on commit 8fe1c39

Please sign in to comment.