diff --git a/src/redux/map/map.thunks.test.ts b/src/redux/map/map.thunks.test.ts index cd8333b440180b45d7b81d7896d2f27b0321f003..6d5e94a4f207d2e0e176a3a1c18e4744a0bcc893 100644 --- a/src/redux/map/map.thunks.test.ts +++ b/src/redux/map/map.thunks.test.ts @@ -5,7 +5,13 @@ import { BACKGROUNDS_MOCK, BACKGROUND_INITIAL_STATE_MOCK } from '../backgrounds/ import { RootState } from '../store'; import { INITIAL_STORE_STATE_MOCK } from '../root/root.fixtures'; import { MODELS_INITIAL_STATE_MOCK } from '../models/models.mock'; -import { getBackgroundId, getInitMapPosition, getInitMapSizeAndModelId } from './map.thunks'; +import { + getBackgroundId, + getInitMapPosition, + getInitMapSizeAndModelId, + getOpenedMaps, +} from './map.thunks'; +import { initialMapDataFixture, initialMapStateFixture } from './map.fixtures'; const EMPTY_QUERY_DATA: QueryData = { modelId: undefined, @@ -112,4 +118,42 @@ describe('map thunks - utils', () => { }); }); }); + + describe('getOpenedMaps ', () => { + it('should return main map only', () => { + const openedMaps = getOpenedMaps( + { + ...STATE_WITH_MODELS, + map: { ...initialMapStateFixture, data: { ...initialMapDataFixture, modelId: 5053 } }, + }, + EMPTY_QUERY_DATA, + ); + + expect(openedMaps).toEqual([ + { lastPosition: { x: 0, y: 0, z: 0 }, modelId: 5053, modelName: 'Main map' }, + ]); + }); + it('should return main map and opened submap', () => { + const openedMaps = getOpenedMaps( + { + ...STATE_WITH_MODELS, + map: { ...initialMapStateFixture, data: { ...initialMapDataFixture, modelId: 5054 } }, + }, + EMPTY_QUERY_DATA, + ); + + expect(openedMaps).toEqual([ + { lastPosition: { x: 0, y: 0, z: 0 }, modelId: 5053, modelName: 'Main map' }, + { + lastPosition: { + x: 0, + y: 0, + z: 0, + }, + modelId: 5054, + modelName: 'PRKN substrates', + }, + ]); + }); + }); }); diff --git a/src/redux/map/map.thunks.ts b/src/redux/map/map.thunks.ts index f2ea946bf66c0f1086d3e73696fca480d42d1ede..a52a86ca81c5add0e37978fe97890e4141db8fec 100644 --- a/src/redux/map/map.thunks.ts +++ b/src/redux/map/map.thunks.ts @@ -94,7 +94,9 @@ export const getOpenedMaps = (state: RootState, queryData: QueryData): OppenedMa { modelId: mainMapId, modelName: MAIN_MAP, lastPosition: DEFAULT_POSITION }, ]; - if (queryData.modelId !== mainMapId) { + const isMainMapSetAsCurrentModel = currentModel?.idObject !== mainMapId; + + if (isMainMapSetAsCurrentModel) { openedMaps.push({ modelId: currentModel?.idObject || ZERO, modelName: currentModel?.name || '',