From 1f1c7eb84bf170701181fe7b2a89986aa315058a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadeusz=20Miesi=C4=85c?= <tadeusz.miesiac@gmail.com> Date: Wed, 29 Nov 2023 13:30:23 +0100 Subject: [PATCH] fix(submaps tabs): fixed duplicated mainmap tab on app init --- src/redux/map/map.thunks.test.ts | 46 +++++++++++++++++++++++++++++++- src/redux/map/map.thunks.ts | 4 ++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/redux/map/map.thunks.test.ts b/src/redux/map/map.thunks.test.ts index cd8333b4..6d5e94a4 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 f2ea946b..a52a86ca 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 || '', -- GitLab