From 70e005fb87496d34a39ce7128ae49b8d6f62212c Mon Sep 17 00:00:00 2001 From: Piotr Gawron <p.gawron@atcomp.pl> Date: Tue, 31 Dec 2024 12:15:37 +0100 Subject: [PATCH] use top map from project endpoint --- .../MapNavigation.component.test.tsx | 57 ++++++++++++++++--- .../EditOverlayModal.component.test.tsx | 2 - .../LicenseModal/LicenseModal.component.tsx | 1 + .../utils/useOverviewImageLinkActions.test.ts | 21 +++---- .../PublicationsSearch.component.tsx | 2 +- .../AssociatedSubmap.component.test.tsx | 4 +- .../BioEntityDrawer.component.tsx | 1 + .../ExportCompound.component.tsx | 12 +++- .../OverlayListItem.component.test.tsx | 9 ++- .../hooks/useUserOverlayForm.ts | 16 ------ .../ProjectInfoDrawer.component.test.tsx | 9 ++- .../ReactionDrawer.component.tsx | 1 + ...BioEntitiesPinsListItem.component.test.tsx | 9 +-- .../BioEntitiesSubmapItem.component.test.tsx | 13 ++--- .../ChemicalsAccordion.component.tsx | 2 +- .../DrugsAccordion.component.tsx | 2 +- .../PinsListItem.component.test.tsx | 3 +- .../useVisiblePinsPolygonCoordinates.test.ts | 11 ++-- .../DownloadSubmap.component.test.tsx | 3 +- .../DownloadSubmap.component.tsx | 4 +- .../utils/useGetSubmapDownloadUrl.test.ts | 5 +- .../SubmapsDrawer/SubmapsDrawer.test.tsx | 4 +- ...sibleBioEntitiesPolygonCoordinates.test.ts | 19 ++++--- src/models/mocks/modelsMock.ts | 11 ++-- src/models/mocks/overviewImageMocks.ts | 3 +- src/models/projectSchema.ts | 4 ++ src/redux/bioEntity/bioEntity.mock.ts | 3 +- .../compartmentPathways.mock.ts | 3 +- .../compartmentPathways.reducers.test.ts | 5 +- .../compartmentPathways.thunks.test.ts | 3 +- src/redux/map/map.fixtures.ts | 9 ++- src/redux/map/map.thunks.test.ts | 29 ++++++++-- src/redux/map/map.thunks.ts | 8 +-- src/redux/models/models.selectors.ts | 16 ++++-- src/redux/overlays/overlays.thunks.ts | 25 -------- src/redux/project/project.mock.ts | 7 ++- .../pluginsManager/map/openMap.test.ts | 17 +++--- ...sibleBioEntitiesPolygonCoordinates.test.ts | 3 +- .../map/triggerSearch/searchByQuery.test.ts | 3 +- 39 files changed, 213 insertions(+), 146 deletions(-) diff --git a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx index 35c89a0c..e1839e66 100644 --- a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx +++ b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx @@ -1,7 +1,6 @@ /* eslint-disable no-magic-numbers */ import { MODELS_MOCK } from '@/redux/compartmentPathways/compartmentPathways.mock'; import { initialMapDataFixture, openedMapsThreeSubmapsFixture } from '@/redux/map/map.fixtures'; -import { MODELS_DATA_MOCK_WITH_MAIN_MAP } from '@/redux/models/models.mock'; import { StoreType } from '@/redux/store'; import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; import { @@ -11,8 +10,48 @@ import { import { act, render, screen, within } from '@testing-library/react'; import { HISTAMINE_MAP_ID, MAIN_MAP_ID } from '@/constants/mocks'; import MapBackgroundsEnum from '@/redux/map/map.enums'; +import { Project } from '@/types/models'; +import { projectFixture } from '@/models/fixtures/projectFixture'; +import { ProjectState } from '@/redux/project/project.types'; +import { PROJECT_STATE_INITIAL_MOCK } from '@/redux/project/project.mock'; +import { ModelsState } from '@/redux/models/models.types'; +import { DEFAULT_ERROR } from '@/constants/errors'; import { MapNavigation } from './MapNavigation.component'; +export const MODELS_DATA: ModelsState = { + data: [ + { + id: MAIN_MAP_ID, + width: 26779.25, + height: 13503, + defaultCenterX: null, + defaultCenterY: null, + description: '', + name: 'Core PD map', + defaultZoomLevel: null, + tileSize: 256, + references: [], + authors: [], + creationDate: null, + modificationDates: [], + minZoom: 2, + maxZoom: 9, + }, + ], + loading: 'idle', + error: DEFAULT_ERROR, +}; + +const PROJECT: Project = { + ...projectFixture, + topMap: { id: MAIN_MAP_ID }, +}; + +const PROJECT_STATE: ProjectState = { + ...PROJECT_STATE_INITIAL_MOCK, + data: PROJECT, +}; + const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => { const { Wrapper, store } = getReduxWrapperWithStore(initialStoreState); @@ -109,6 +148,7 @@ describe('MapNavigation - component', () => { it('should close currently selected map map and open main map', async () => { const { store } = renderComponent({ + project: PROJECT_STATE, map: { data: { ...initialMapDataFixture, @@ -155,7 +195,8 @@ describe('MapNavigation - component', () => { const dispatchEventMock = jest.spyOn(PluginsEventBus, 'dispatchEvent'); renderComponent({ - models: MODELS_DATA_MOCK_WITH_MAIN_MAP, + project: { ...PROJECT_STATE }, + models: MODELS_DATA, map: { data: { ...initialMapDataFixture, @@ -175,14 +216,15 @@ describe('MapNavigation - component', () => { }); expect(dispatchEventMock).toHaveBeenCalledTimes(2); - expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapClose', 5052); - expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapOpen', 52); + expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapClose', HISTAMINE_MAP_ID); + expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapOpen', MAIN_MAP_ID); }); it('should not dispatch event if it closes not active map', async () => { const dispatchEventMock = jest.spyOn(PluginsEventBus, 'dispatchEvent'); renderComponent({ - models: MODELS_DATA_MOCK_WITH_MAIN_MAP, + project: PROJECT_STATE, + models: MODELS_DATA, map: { data: { ...initialMapDataFixture, @@ -207,7 +249,8 @@ describe('MapNavigation - component', () => { const dispatchEventMock = jest.spyOn(PluginsEventBus, 'dispatchEvent'); renderComponent({ - models: MODELS_DATA_MOCK_WITH_MAIN_MAP, + project: PROJECT_STATE, + models: MODELS_DATA, map: { data: { ...initialMapDataFixture, @@ -227,7 +270,7 @@ describe('MapNavigation - component', () => { }); expect(dispatchEventMock).toHaveBeenCalledTimes(2); - expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapClose', 5052); + expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapClose', HISTAMINE_MAP_ID); expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapOpen', 5054); }); }); diff --git a/src/components/FunctionalArea/Modal/EditOverlayModal/EditOverlayModal.component.test.tsx b/src/components/FunctionalArea/Modal/EditOverlayModal/EditOverlayModal.component.test.tsx index aef70523..b06a5fe7 100644 --- a/src/components/FunctionalArea/Modal/EditOverlayModal/EditOverlayModal.component.test.tsx +++ b/src/components/FunctionalArea/Modal/EditOverlayModal/EditOverlayModal.component.test.tsx @@ -184,8 +184,6 @@ describe('EditOverlayModal - component', () => { .onGet(apiPath.getAllUserOverlaysByCreatorQuery({ creator: 'test', publicOverlay: false })) .reply(HttpStatusCode.Ok, page); - // eslint-disable-next-line no-console - console.log(overlayFixture); const saveButton = screen.getByTestId('save-button'); expect(saveButton).toBeVisible(); await act(() => { diff --git a/src/components/FunctionalArea/Modal/LicenseModal/LicenseModal.component.tsx b/src/components/FunctionalArea/Modal/LicenseModal/LicenseModal.component.tsx index bdb79d2d..d537b587 100644 --- a/src/components/FunctionalArea/Modal/LicenseModal/LicenseModal.component.tsx +++ b/src/components/FunctionalArea/Modal/LicenseModal/LicenseModal.component.tsx @@ -13,6 +13,7 @@ export const LicenseModal = (): React.ReactNode => { } return ( <div className="w-full overflow-auto border border-t-[#E1E0E6] bg-white p-[24px]"> + {/* eslint-disable-next-line react/no-danger */} <div dangerouslySetInnerHTML={{ __html: licenseDescription }} /> </div> ); diff --git a/src/components/FunctionalArea/Modal/OverviewImagesModal/utils/useOverviewImageLinkActions.test.ts b/src/components/FunctionalArea/Modal/OverviewImagesModal/utils/useOverviewImageLinkActions.test.ts index 2df46d7c..33e0afd0 100644 --- a/src/components/FunctionalArea/Modal/OverviewImagesModal/utils/useOverviewImageLinkActions.test.ts +++ b/src/components/FunctionalArea/Modal/OverviewImagesModal/utils/useOverviewImageLinkActions.test.ts @@ -18,6 +18,7 @@ import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreA import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; import { renderHook } from '@testing-library/react'; import MapBackgroundsEnum from '@/redux/map/map.enums'; +import { MAIN_MAP_ID } from '@/constants/mocks'; import { FIRST_ARRAY_ELEMENT, NOOP, @@ -55,7 +56,7 @@ describe('useOverviewImageLinkActions - hook', () => { map: { data: { ...initialMapDataFixture, - modelId: 5053, + modelId: MAIN_MAP_ID, }, loading: 'succeeded', error: { name: '', message: '' }, @@ -106,7 +107,7 @@ describe('useOverviewImageLinkActions - hook', () => { map: { data: { ...initialMapDataFixture, - modelId: 5053, + modelId: MAIN_MAP_ID, }, loading: 'succeeded', error: { name: '', message: '' }, @@ -164,7 +165,7 @@ describe('useOverviewImageLinkActions - hook', () => { map: { data: { ...initialMapDataFixture, - modelId: 5053, + modelId: MAIN_MAP_ID, }, loading: 'succeeded', error: { name: '', message: '' }, @@ -191,7 +192,7 @@ describe('useOverviewImageLinkActions - hook', () => { const actions = store.getActions(); expect(actions[FIRST_ARRAY_ELEMENT]).toStrictEqual({ payload: { - modelId: 5053, + modelId: MAIN_MAP_ID, }, type: 'map/setActiveMap', }); @@ -243,7 +244,7 @@ describe('useOverviewImageLinkActions - hook', () => { map: { data: { ...initialMapDataFixture, - modelId: 5053, + modelId: MAIN_MAP_ID, }, loading: 'succeeded', error: { name: '', message: '' }, @@ -270,7 +271,7 @@ describe('useOverviewImageLinkActions - hook', () => { const actions = store.getActions(); expect(actions[FIRST_ARRAY_ELEMENT]).toStrictEqual({ payload: { - modelId: 5053, + modelId: MAIN_MAP_ID, modelName: 'Core PD map', }, type: 'map/openMapAndSetActive', @@ -348,7 +349,7 @@ describe('useOverviewImageLinkActions - hook', () => { map: { data: { ...initialMapDataFixture, - modelId: 5053, + modelId: MAIN_MAP_ID, }, loading: 'succeeded', error: { name: '', message: '' }, @@ -394,7 +395,7 @@ describe('useOverviewImageLinkActions - hook', () => { map: { data: { ...initialMapDataFixture, - modelId: 5053, + modelId: MAIN_MAP_ID, position: { initial: { x: 15570.0, @@ -496,7 +497,7 @@ describe('useOverviewImageLinkActions - hook', () => { expect(dispatchEventMock).toHaveBeenCalledTimes(2); expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapClose', 5054); - expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapOpen', 5053); + expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapOpen', MAIN_MAP_ID); }); it('should not dispatch event if provided submap to open is already opened', () => { const dispatchEventMock = jest.spyOn(PluginsEventBus, 'dispatchEvent'); @@ -520,7 +521,7 @@ describe('useOverviewImageLinkActions - hook', () => { map: { data: { ...initialMapDataFixture, - modelId: 5053, + modelId: MAIN_MAP_ID, position: { initial: { x: 15570.0, diff --git a/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsSearch/PublicationsSearch.component.tsx b/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsSearch/PublicationsSearch.component.tsx index 1c3f838d..dd90e7d2 100644 --- a/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsSearch/PublicationsSearch.component.tsx +++ b/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsSearch/PublicationsSearch.component.tsx @@ -42,7 +42,7 @@ export const PublicationsSearch = (): JSX.Element => { modelId: selectedId, }), ); - }, [debouncedValue, dispatch]); + }, [debouncedValue, dispatch, selectedId, sortColumn, sortOrder]); useEffect(() => { dispatch(setPublicationSearchValue(debouncedValue)); diff --git a/src/components/Map/Drawer/BioEntityDrawer/AssociatedSubmap/AssociatedSubmap.component.test.tsx b/src/components/Map/Drawer/BioEntityDrawer/AssociatedSubmap/AssociatedSubmap.component.test.tsx index 4cc91adc..267ad439 100644 --- a/src/components/Map/Drawer/BioEntityDrawer/AssociatedSubmap/AssociatedSubmap.component.test.tsx +++ b/src/components/Map/Drawer/BioEntityDrawer/AssociatedSubmap/AssociatedSubmap.component.test.tsx @@ -19,6 +19,7 @@ import { } from '@/utils/testing/getReduxWrapperWithStore'; import { act, render, screen } from '@testing-library/react'; import MapBackgroundsEnum from '@/redux/map/map.enums'; +import { HISTAMINE_MAP_ID, MAIN_MAP_ID } from '@/constants/mocks'; import { AssociatedSubmap } from './AssociatedSubmap.component'; const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => { @@ -36,9 +37,6 @@ const renderComponent = (initialStoreState: InitialStoreState = {}): { store: St ); }; -const MAIN_MAP_ID = 5053; -const HISTAMINE_MAP_ID = 5052; - describe('AssociatedSubmap - component', () => { it('should not display component when can not find asociated map model', () => { renderComponent({ diff --git a/src/components/Map/Drawer/BioEntityDrawer/BioEntityDrawer.component.tsx b/src/components/Map/Drawer/BioEntityDrawer/BioEntityDrawer.component.tsx index 4c360073..7b3e3ba1 100644 --- a/src/components/Map/Drawer/BioEntityDrawer/BioEntityDrawer.component.tsx +++ b/src/components/Map/Drawer/BioEntityDrawer/BioEntityDrawer.component.tsx @@ -77,6 +77,7 @@ export const BioEntityDrawer = (): React.ReactNode => { <hr className="border-b border-b-divide" /> <div className="text-sm font-normal" + /* eslint-disable-next-line react/no-danger */ dangerouslySetInnerHTML={{ __html: bioEntityData.notes }} /> </span> diff --git a/src/components/Map/Drawer/ExportDrawer/ExportCompound/ExportCompound.component.tsx b/src/components/Map/Drawer/ExportDrawer/ExportCompound/ExportCompound.component.tsx index d380b1c0..906dd9ee 100644 --- a/src/components/Map/Drawer/ExportDrawer/ExportCompound/ExportCompound.component.tsx +++ b/src/components/Map/Drawer/ExportDrawer/ExportCompound/ExportCompound.component.tsx @@ -93,7 +93,7 @@ export const Export = ({ children }: ExportProps): JSX.Element => { if (url) { window.open(url); } - }, [models, imageFormats, currentBackground, currentModels, imageSize.width]); + }, [models, imageFormats, currentBackground, currentModels, imageSize.width, overlays]); const handleDownloadCurrentView = useCallback(async () => { const url = getGraphicsDownloadUrl({ @@ -108,7 +108,7 @@ export const Export = ({ children }: ExportProps): JSX.Element => { if (url) { window.open(url); } - }, [selectedModelId, imageFormats, currentBackground]); + }, [selectedModelId, imageFormats, currentBackground, overlays]); const globalContextDataValue = useMemo( () => ({ @@ -143,7 +143,13 @@ export const Export = ({ children }: ExportProps): JSX.Element => { handleDownloadCurrentView, data: globalContextDataValue, }), - [handleDownloadElements, handleDownloadNetwork, globalContextDataValue, handleDownloadGraphics], + [ + handleDownloadElements, + handleDownloadNetwork, + globalContextDataValue, + handleDownloadGraphics, + handleDownloadCurrentView, + ], ); return <ExportContext.Provider value={globalContextValue}>{children}</ExportContext.Provider>; diff --git a/src/components/Map/Drawer/OverlaysDrawer/GeneralOverlays/OverlayListItem/OverlayListItem.component.test.tsx b/src/components/Map/Drawer/OverlaysDrawer/GeneralOverlays/OverlayListItem/OverlayListItem.component.test.tsx index 71349615..d1080df9 100644 --- a/src/components/Map/Drawer/OverlaysDrawer/GeneralOverlays/OverlayListItem/OverlayListItem.component.test.tsx +++ b/src/components/Map/Drawer/OverlaysDrawer/GeneralOverlays/OverlayListItem/OverlayListItem.component.test.tsx @@ -18,6 +18,7 @@ import { CORE_PD_MODEL_MOCK } from '@/models/mocks/modelsMock'; import { MODELS_INITIAL_STATE_MOCK } from '@/redux/models/models.mock'; import { parseOverlayBioEntityToOlRenderingFormat } from '@/redux/overlayBioEntity/overlayBioEntity.utils'; import { BASE_API_URL } from '@/constants'; +import { MAIN_MAP_ID } from '@/constants/mocks'; import { OverlayListItem } from './OverlayListItem.component'; const mockedAxiosNewClient = mockNetworkNewAPIResponse(); @@ -51,7 +52,6 @@ describe('OverlayListItem - component', () => { describe('view overlays', () => { it('should trigger view overlays on view button click and switch background to Empty if available', async () => { const OVERLAY_ID = 21; - const MODEL_ID = 5053; const { store } = renderComponent({ map: initialMapStateFixture, backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, @@ -59,7 +59,7 @@ describe('OverlayListItem - component', () => { models: { ...MODELS_INITIAL_STATE_MOCK, data: [CORE_PD_MODEL_MOCK] }, }); mockedAxiosNewClient - .onGet(apiPath.getOverlayBioEntity({ overlayId: OVERLAY_ID, modelId: MODEL_ID })) + .onGet(apiPath.getOverlayBioEntity({ overlayId: OVERLAY_ID, modelId: MAIN_MAP_ID })) .reply(HttpStatusCode.Ok, overlayBioEntityFixture); expect(store.getState().map.data.backgroundId).toBe(DEFAULT_BACKGROUND_ID); @@ -72,7 +72,10 @@ describe('OverlayListItem - component', () => { expect(store.getState().map.data.backgroundId).toBe(EMPTY_BACKGROUND_ID); expect(store.getState().overlayBioEntity.data).toEqual({ [OVERLAY_ID]: { - [MODEL_ID]: parseOverlayBioEntityToOlRenderingFormat(overlayBioEntityFixture, OVERLAY_ID), + [MAIN_MAP_ID]: parseOverlayBioEntityToOlRenderingFormat( + overlayBioEntityFixture, + OVERLAY_ID, + ), }, }); }); diff --git a/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/hooks/useUserOverlayForm.ts b/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/hooks/useUserOverlayForm.ts index 7e2bb34e..5229c9fa 100644 --- a/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/hooks/useUserOverlayForm.ts +++ b/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/hooks/useUserOverlayForm.ts @@ -100,12 +100,8 @@ export const useUserOverlayForm = (): ReturnType => { filename = 'unknown.txt'; // Elements list is sent to the backend as a file, so we need to create a filename for the elements list. } - // eslint-disable-next-line no-console - console.log('x1'); if (!overlayContent || !projectId || !name) return; - // eslint-disable-next-line no-console - console.log('x2'); dispatch( addOverlay({ content: overlayContent, @@ -116,24 +112,12 @@ export const useUserOverlayForm = (): ReturnType => { type: type.id, }), ); - // eslint-disable-next-line no-console - console.log('x3'); setName(''); - // eslint-disable-next-line no-console - console.log('x3'); setDescription(''); - // eslint-disable-next-line no-console - console.log('x4'); setElementsList(''); - // eslint-disable-next-line no-console - console.log('x5'); setOverlayContent(''); - // eslint-disable-next-line no-console - console.log('x6'); setUploadedFile(null); - // eslint-disable-next-line no-console - console.log('x7'); }; return { diff --git a/src/components/Map/Drawer/ProjectInfoDrawer/ProjectInfoDrawer.component.test.tsx b/src/components/Map/Drawer/ProjectInfoDrawer/ProjectInfoDrawer.component.test.tsx index 1c24ab14..e887c747 100644 --- a/src/components/Map/Drawer/ProjectInfoDrawer/ProjectInfoDrawer.component.test.tsx +++ b/src/components/Map/Drawer/ProjectInfoDrawer/ProjectInfoDrawer.component.test.tsx @@ -9,9 +9,16 @@ import { StoreType } from '@/redux/store'; import { MODEL_WITH_DESCRIPTION } from '@/models/mocks/modelsMock'; import { ProjectInfoDrawer } from './ProjectInfoDrawer.component'; +const PROJECT = { + ...projectFixture, + topMap: { + id: MODEL_WITH_DESCRIPTION.id, + }, +}; + const MOCKED_STORE: InitialStoreState = { project: { - data: { ...projectFixture }, + data: PROJECT, loading: 'idle', error: new Error(), projectId: '', diff --git a/src/components/Map/Drawer/ReactionDrawer/ReactionDrawer.component.tsx b/src/components/Map/Drawer/ReactionDrawer/ReactionDrawer.component.tsx index 3ab0e0df..00d2128e 100644 --- a/src/components/Map/Drawer/ReactionDrawer/ReactionDrawer.component.tsx +++ b/src/components/Map/Drawer/ReactionDrawer/ReactionDrawer.component.tsx @@ -40,6 +40,7 @@ export const ReactionDrawer = (): React.ReactNode => { {reaction.notes && ( <div className="text-sm font-normal" + /* eslint-disable-next-line react/no-danger */ dangerouslySetInnerHTML={{ __html: reaction.notes }} /> )} diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.test.tsx index 61c33f6c..f5f24509 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.test.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.test.tsx @@ -14,6 +14,7 @@ import { act } from 'react-dom/test-utils'; import { MockStoreEnhanced } from 'redux-mock-store'; import { getTypeBySBOTerm } from '@/utils/bioEntity/getTypeBySBOTerm'; import { newReactionsFixture } from '@/models/fixtures/newReactionsFixture'; +import { HISTAMINE_MAP_ID } from '@/constants/mocks'; import { BioEntitiesPinsListItem } from './BioEntitiesPinsListItem.component'; import { PinListBioEntity } from './BioEntitiesPinsListItem.types'; @@ -131,7 +132,7 @@ describe('BioEntitiesPinsListItem - component ', () => { ...MAP_INITIAL_STATE, data: { ...MAP_INITIAL_STATE.data, - modelId: 5052, + modelId: HISTAMINE_MAP_ID, size: { width: 256, height: 256, @@ -182,7 +183,7 @@ describe('BioEntitiesPinsListItem - component ', () => { ...MAP_INITIAL_STATE, data: { ...MAP_INITIAL_STATE.data, - modelId: 5052, + modelId: HISTAMINE_MAP_ID, size: { width: 256, height: 256, @@ -234,7 +235,7 @@ describe('BioEntitiesPinsListItem - component ', () => { ...MAP_INITIAL_STATE, data: { ...MAP_INITIAL_STATE.data, - modelId: 5052, + modelId: HISTAMINE_MAP_ID, size: { width: 256, height: 256, @@ -308,7 +309,7 @@ describe('BioEntitiesPinsListItem - component ', () => { ...MAP_INITIAL_STATE, data: { ...MAP_INITIAL_STATE.data, - modelId: 5052, + modelId: HISTAMINE_MAP_ID, size: { width: 256, height: 256, diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesSubmapItem/BioEntitiesSubmapItem.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesSubmapItem/BioEntitiesSubmapItem.component.test.tsx index d6561b95..62654f69 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesSubmapItem/BioEntitiesSubmapItem.component.test.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesSubmapItem/BioEntitiesSubmapItem.component.test.tsx @@ -14,10 +14,9 @@ import { openedMapsThreeSubmapsFixture, } from '@/redux/map/map.fixtures'; import MapBackgroundsEnum from '@/redux/map/map.enums'; +import { MAIN_MAP_ID } from '@/constants/mocks'; import { BioEntitiesSubmapItem } from './BioEntitiesSubmapItem.component'; -const CORE_MAP_ID = 5053; - const SECOND_STEP = 2; const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => { @@ -112,7 +111,7 @@ describe('BioEntitiesSubmapItem - component', () => { expect(modelId).toBe(0); expect(openedMaps).not.toContainEqual({ - modelId: CORE_MAP_ID, + modelId: MAIN_MAP_ID, modelName: 'Core PD map', lastPosition: { x: 0, y: 0, z: 0 }, }); @@ -128,12 +127,12 @@ describe('BioEntitiesSubmapItem - component', () => { } = store.getState().map; expect(newOpenedMaps).toContainEqual({ - modelId: CORE_MAP_ID, + modelId: MAIN_MAP_ID, modelName: 'Core PD map', lastPosition: { x: 0, y: 0, z: 0 }, }); - expect(newModelId).toBe(CORE_MAP_ID); + expect(newModelId).toBe(MAIN_MAP_ID); }); it("should set map active if it's already opened", async () => { const { store } = renderComponent({ @@ -154,7 +153,7 @@ describe('BioEntitiesSubmapItem - component', () => { map: { data: { ...initialMapDataFixture, - modelId: CORE_MAP_ID, + modelId: MAIN_MAP_ID, }, loading: 'succeeded', error: { name: '', message: '' }, @@ -179,6 +178,6 @@ describe('BioEntitiesSubmapItem - component', () => { // eslint-disable-next-line no-magic-numbers expect(histamineMap.length).toBe(1); - expect(modelId).toBe(CORE_MAP_ID); + expect(modelId).toBe(MAIN_MAP_ID); }); }); diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/ChemicalsAccordion/ChemicalsAccordion.component.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/ChemicalsAccordion/ChemicalsAccordion.component.tsx index b4d479e5..9b9e97a4 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/ChemicalsAccordion/ChemicalsAccordion.component.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/ChemicalsAccordion/ChemicalsAccordion.component.tsx @@ -33,7 +33,7 @@ export const ChemicalsAccordion = (): JSX.Element => { ); let existingChemicalTargets = 0; - list.forEach(function (drugTargetList) { + list.forEach(drugTargetList => { existingChemicalTargets += drugTargetList.length; }); diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/DrugsAccordion/DrugsAccordion.component.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/DrugsAccordion/DrugsAccordion.component.tsx index 289dfffe..53d1807c 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/DrugsAccordion/DrugsAccordion.component.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/DrugsAccordion/DrugsAccordion.component.tsx @@ -33,7 +33,7 @@ export const DrugsAccordion = (): JSX.Element => { drug.targets.filter(target => target.targetElements.length > ZERO), ); let existingDrugTargets = 0; - list.forEach(function (drugTargetList) { + list.forEach(drugTargetList => { existingDrugTargets += drugTargetList.length; }); diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx index 9cfb68d8..23c0490f 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx @@ -12,6 +12,7 @@ import { MODELS_DATA_MOCK_WITH_MAIN_MAP } from '@/redux/models/models.mock'; import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreActionsListener'; import { MockStoreEnhanced } from 'redux-mock-store'; import MapBackgroundsEnum from '@/redux/map/map.enums'; +import { MAIN_MAP_ID } from '@/constants/mocks'; import { PinTypeWithNone } from '../PinsList.types'; import { PinsListItem } from './PinsListItem.component'; @@ -33,7 +34,7 @@ const INITIAL_STORE_STATE: InitialStoreState = { map: { data: { ...initialMapDataFixture, - modelId: 5053, + modelId: MAIN_MAP_ID, }, loading: 'succeeded', error: { message: '', name: '' }, diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/hooks/useVisiblePinsPolygonCoordinates.test.ts b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/hooks/useVisiblePinsPolygonCoordinates.test.ts index f4582609..56cee949 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/hooks/useVisiblePinsPolygonCoordinates.test.ts +++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/hooks/useVisiblePinsPolygonCoordinates.test.ts @@ -3,6 +3,7 @@ import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithSto import { renderHook } from '@testing-library/react'; import { MAP_INITIAL_STATE } from '@/redux/map/map.constants'; import { bioEntityContentFixture } from '@/models/fixtures/bioEntityContentsFixture'; +import { HISTAMINE_MAP_ID } from '@/constants/mocks'; import { useVisiblePinsPolygonCoordinates } from './useVisiblePinsPolygonCoordinates'; describe('useVisiblePinsPolygonCoordinates - hook', () => { @@ -12,7 +13,7 @@ describe('useVisiblePinsPolygonCoordinates - hook', () => { ...MAP_INITIAL_STATE, data: { ...MAP_INITIAL_STATE.data, - modelId: 5052, + modelId: HISTAMINE_MAP_ID, size: { width: 256, height: 256, @@ -36,7 +37,7 @@ describe('useVisiblePinsPolygonCoordinates - hook', () => { ...MAP_INITIAL_STATE, data: { ...MAP_INITIAL_STATE.data, - modelId: 5052, + modelId: HISTAMINE_MAP_ID, size: { width: 256, height: 256, @@ -73,7 +74,7 @@ describe('useVisiblePinsPolygonCoordinates - hook', () => { ...MAP_INITIAL_STATE, data: { ...MAP_INITIAL_STATE.data, - modelId: 5052, + modelId: HISTAMINE_MAP_ID, size: { width: 256, height: 256, @@ -97,14 +98,14 @@ describe('useVisiblePinsPolygonCoordinates - hook', () => { }, { ...bioEntityContentFixture.bioEntity, - model: 5052, + model: HISTAMINE_MAP_ID, x: 12, y: 25, z: 1, }, { ...bioEntityContentFixture.bioEntity, - model: 5052, + model: HISTAMINE_MAP_ID, x: 16, y: 16, z: 1, diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.test.tsx b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.test.tsx index 23e1eef1..4789c9c5 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.test.tsx +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.test.tsx @@ -13,10 +13,11 @@ import { getReduxWrapperWithStore, } from '@/utils/testing/getReduxWrapperWithStore'; import { act, render, renderHook, screen } from '@testing-library/react'; +import { HISTAMINE_MAP_ID } from '@/constants/mocks'; import { DownloadSubmap } from './DownloadSubmap.component'; import { GetSubmapDownloadUrl, useGetSubmapDownloadUrl } from './utils/useGetSubmapDownloadUrl'; -const VALID_MODEL_ID = 5052; +const VALID_MODEL_ID = HISTAMINE_MAP_ID; const VALID_BACKGROUND_ID = 53; const VALID_MAX_ZOOM = 9; diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.tsx b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.tsx index a498e16e..12d1f665 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.tsx +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.tsx @@ -22,10 +22,10 @@ export const DownloadSubmap = (): React.ReactNode => { }); const downloadSubmap = (handler: string) => { - return function () { + return () => { closeMenu(); setIsDownloading(true); - downloadFileFromUrl(getSubmapDownloadUrl({ handler })).finally(function () { + downloadFileFromUrl(getSubmapDownloadUrl({ handler })).finally(() => { setIsDownloading(false); }); }; diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.test.ts b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.test.ts index 704176d2..8bb6e92d 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.test.ts +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.test.ts @@ -6,10 +6,11 @@ import { INITIAL_STORE_STATE_MOCK } from '@/redux/root/root.fixtures'; import { RootState } from '@/redux/store'; import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; import { renderHook } from '@testing-library/react'; +import { HISTAMINE_MAP_ID } from '@/constants/mocks'; import { useGetSubmapDownloadUrl } from './useGetSubmapDownloadUrl'; const VALID_HANDLER = 'lcsb.mapviewer.wikipathway.GpmlParser'; -const VALID_MODEL_ID = 5052; +const VALID_MODEL_ID = HISTAMINE_MAP_ID; const VALID_BACKGROUND_ID = 53; const VALID_MAX_ZOOM = 9; @@ -110,7 +111,7 @@ describe('useGetSubmapDownloadUrl - hook', () => { } = renderHook(() => useGetSubmapDownloadUrl(), { wrapper: Wrapper }); expect(getSubmapDownloadUrl({ handler: VALID_HANDLER })).toBe( - `${BASE_API_URL}/projects/${PROJECT_ID}/models/5052:downloadModel?backgroundOverlayId=53&handlerClass=lcsb.mapviewer.wikipathway.GpmlParser&zoomLevel=9`, + `${BASE_API_URL}/projects/${PROJECT_ID}/models/${HISTAMINE_MAP_ID}:downloadModel?backgroundOverlayId=53&handlerClass=lcsb.mapviewer.wikipathway.GpmlParser&zoomLevel=9`, ); }); }); diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.test.tsx b/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.test.tsx index 825bccfd..492be6cb 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.test.tsx +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.test.tsx @@ -12,11 +12,9 @@ import { openedMapsThreeSubmapsFixture, } from '@/redux/map/map.fixtures'; import MapBackgroundsEnum from '@/redux/map/map.enums'; +import { HISTAMINE_MAP_ID, MAIN_MAP_ID } from '@/constants/mocks'; import { SubmapsDrawer } from './SubmapsDrawer'; -const MAIN_MAP_ID = 5053; -const HISTAMINE_MAP_ID = 5052; - const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => { const { Wrapper, store } = getReduxWrapperWithStore(initialStoreState); diff --git a/src/components/Map/MapAdditionalActions/utils/useVisibleBioEntitiesPolygonCoordinates.test.ts b/src/components/Map/MapAdditionalActions/utils/useVisibleBioEntitiesPolygonCoordinates.test.ts index 331d5e98..7cfb9304 100644 --- a/src/components/Map/MapAdditionalActions/utils/useVisibleBioEntitiesPolygonCoordinates.test.ts +++ b/src/components/Map/MapAdditionalActions/utils/useVisibleBioEntitiesPolygonCoordinates.test.ts @@ -9,6 +9,7 @@ import { INITIAL_STORE_STATE_MOCK } from '@/redux/root/root.fixtures'; import { RootState } from '@/redux/store'; import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; import { renderHook } from '@testing-library/react'; +import { HISTAMINE_MAP_ID } from '@/constants/mocks'; import { CHEMICALS_INITIAL_STATE_MOCK } from '../../../../redux/chemicals/chemicals.mock'; import { DRUGS_INITIAL_STATE_MOCK } from '../../../../redux/drugs/drugs.mock'; import { DEFAULT_POSITION, MAIN_MAP, MAP_INITIAL_STATE } from '../../../../redux/map/map.constants'; @@ -43,7 +44,7 @@ const getInitalState = ( data: [ { ...modelsFixture[0], - id: 5052, + id: HISTAMINE_MAP_ID, }, ], }, @@ -51,7 +52,7 @@ const getInitalState = ( ...MAP_INITIAL_STATE, data: { ...MAP_INITIAL_STATE.data, - modelId: 5052, + modelId: HISTAMINE_MAP_ID, size: { width: 256, height: 256, @@ -60,7 +61,9 @@ const getInitalState = ( maxZoom: 1, }, }, - openedMaps: [{ modelId: 5052, modelName: MAIN_MAP, lastPosition: DEFAULT_POSITION }], + openedMaps: [ + { modelId: HISTAMINE_MAP_ID, modelName: MAIN_MAP, lastPosition: DEFAULT_POSITION }, + ], }, bioEntity: { ...BIOENTITY_INITIAL_STATE_MOCK, @@ -72,7 +75,7 @@ const getInitalState = ( ...bioEntityContentFixture, bioEntity: { ...bioEntityContentFixture.bioEntity, - model: 5052, + model: HISTAMINE_MAP_ID, x: 16, y: 16, z: 1, @@ -98,7 +101,7 @@ const getInitalState = ( targetElements: [ { ...chemicalsFixture[0].targets[0].targetElements[0], - model: 5052, + model: HISTAMINE_MAP_ID, x: 32, y: 32, z: 1, @@ -122,7 +125,7 @@ const getInitalState = ( targetElements: [ { ...chemicalsFixture[0].targets[0].targetElements[0], - model: 5052, + model: HISTAMINE_MAP_ID, x: 8, y: 2, z: 9, @@ -151,7 +154,7 @@ const getInitalState = ( targetElements: [ { ...drugsFixture[0].targets[0].targetElements[0], - model: 5052, + model: HISTAMINE_MAP_ID, x: 128, y: 128, z: 1, @@ -175,7 +178,7 @@ const getInitalState = ( targetElements: [ { ...drugsFixture[0].targets[0].targetElements[0], - model: 5052, + model: HISTAMINE_MAP_ID, x: 100, y: 50, z: 4, diff --git a/src/models/mocks/modelsMock.ts b/src/models/mocks/modelsMock.ts index 7166e45f..85e29299 100644 --- a/src/models/mocks/modelsMock.ts +++ b/src/models/mocks/modelsMock.ts @@ -1,8 +1,9 @@ import { MapModel } from '@/types/models'; +import { HISTAMINE_MAP_ID, MAIN_MAP_ID } from '@/constants/mocks'; export const MODELS_MOCK: MapModel[] = [ { - id: 5053, + id: MAIN_MAP_ID, width: 26779.25, height: 13503.0, defaultCenterX: null, @@ -19,7 +20,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 9, }, { - id: 5052, + id: HISTAMINE_MAP_ID, width: 3511.09375, height: 1312.125, defaultCenterX: null, @@ -406,7 +407,7 @@ export const MODELS_MOCK: MapModel[] = [ export const MODELS_MOCK_SHORT: MapModel[] = [ { - id: 5053, + id: MAIN_MAP_ID, width: 26779.25, height: 13503.0, defaultCenterX: null, @@ -423,7 +424,7 @@ export const MODELS_MOCK_SHORT: MapModel[] = [ maxZoom: 9, }, { - id: 5052, + id: HISTAMINE_MAP_ID, width: 3511.09375, height: 1312.125, defaultCenterX: null, @@ -459,7 +460,7 @@ export const MODELS_MOCK_SHORT: MapModel[] = [ ]; export const CORE_PD_MODEL_MOCK: MapModel = { - id: 5053, + id: MAIN_MAP_ID, width: 26779.25, height: 13503.0, defaultCenterX: null, diff --git a/src/models/mocks/overviewImageMocks.ts b/src/models/mocks/overviewImageMocks.ts index 21571fc1..9d2b67cc 100644 --- a/src/models/mocks/overviewImageMocks.ts +++ b/src/models/mocks/overviewImageMocks.ts @@ -1,5 +1,6 @@ import { PROJECT_OVERVIEW_IMAGE_MOCK } from '@/redux/project/project.mock'; import { OverviewImageLinkImage, OverviewImageLinkModel } from '@/types/models'; +import { MAIN_MAP_ID } from '@/constants/mocks'; export const OVERVIEW_LINK_IMAGE_MOCK: OverviewImageLinkImage = { id: 1, @@ -14,6 +15,6 @@ export const OVERVIEW_LINK_MODEL_MOCK: OverviewImageLinkModel = { zoomLevel: 5, xCoord: 15570.0, yCoord: 3016.0, - linkedModel: 5053, + linkedModel: MAIN_MAP_ID, // type: 'OverviewImageLink', }; diff --git a/src/models/projectSchema.ts b/src/models/projectSchema.ts index 39862947..eeb1f6f3 100644 --- a/src/models/projectSchema.ts +++ b/src/models/projectSchema.ts @@ -5,6 +5,7 @@ import { organism } from './organism'; import { overviewImageView } from './overviewImageView'; export const projectSchema = z.object({ + id: z.number().int().nonnegative(), version: z.string(), disease: disease.nullable(), diseaseName: z.string().nullable(), @@ -27,4 +28,7 @@ export const projectSchema = z.object({ license: z.optional(licenseSchema).nullable(), customLicenseName: z.string(), customLicenseUrl: z.string(), + topMap: z.object({ + id: z.number().int().nonnegative(), + }), }); diff --git a/src/redux/bioEntity/bioEntity.mock.ts b/src/redux/bioEntity/bioEntity.mock.ts index dbc164d2..929790fa 100644 --- a/src/redux/bioEntity/bioEntity.mock.ts +++ b/src/redux/bioEntity/bioEntity.mock.ts @@ -2,6 +2,7 @@ import { DEFAULT_ERROR } from '@/constants/errors'; import { bioEntityContentFixture } from '@/models/fixtures/bioEntityContentsFixture'; import { MultiSearchData } from '@/types/fetchDataState'; import { BioEntity, BioEntityContent } from '@/types/models'; +import { HISTAMINE_MAP_ID } from '@/constants/mocks'; import { BioEntityContentsState } from './bioEntity.types'; export const BIOENTITY_INITIAL_STATE_MOCK: BioEntityContentsState = { @@ -18,7 +19,7 @@ export const BIOENTITY_INITIAL_STATE_MOCK: BioEntityContentsState = { export const BIO_ENTITY_LINKING_TO_SUBMAP: BioEntity = { ...bioEntityContentFixture.bioEntity, submodel: { - mapId: 5052, + mapId: HISTAMINE_MAP_ID, type: 'DONWSTREAM_TARGETS', }, }; diff --git a/src/redux/compartmentPathways/compartmentPathways.mock.ts b/src/redux/compartmentPathways/compartmentPathways.mock.ts index a8c7fdb9..8d088c4c 100644 --- a/src/redux/compartmentPathways/compartmentPathways.mock.ts +++ b/src/redux/compartmentPathways/compartmentPathways.mock.ts @@ -1,4 +1,5 @@ import { MapModel } from '@/types/models'; +import { MAIN_MAP_ID } from '@/constants/mocks'; import { CompartmentPathwaysState } from './compartmentPathways.types'; export const COMPARTMENT_PATHWAYS_INITIAL_STATE_MOCK: CompartmentPathwaysState = { @@ -8,7 +9,7 @@ export const COMPARTMENT_PATHWAYS_INITIAL_STATE_MOCK: CompartmentPathwaysState = }; export const MODELS_MOCK: MapModel[] = [ { - id: 5053, + id: MAIN_MAP_ID, width: 26779.25, height: 13503.0, defaultCenterX: null, diff --git a/src/redux/compartmentPathways/compartmentPathways.reducers.test.ts b/src/redux/compartmentPathways/compartmentPathways.reducers.test.ts index 1df36392..8cfdf6ee 100644 --- a/src/redux/compartmentPathways/compartmentPathways.reducers.test.ts +++ b/src/redux/compartmentPathways/compartmentPathways.reducers.test.ts @@ -12,6 +12,7 @@ import { } from '@/models/fixtures/compartmentPathways'; import { getModelsIds } from '@/components/Map/Drawer/ExportDrawer/ExportDrawer.component.utils'; import { unwrapResult } from '@reduxjs/toolkit'; +import { MAIN_MAP_ID } from '@/constants/mocks'; import { apiPath } from '../apiPath'; import compartmentPathwaysReducer from './compartmentPathways.slice'; import { CompartmentPathwaysState } from './compartmentPathways.types'; @@ -62,7 +63,7 @@ describe('compartmentPathways reducer', () => { it('should update store after succesful getCompartmentPathways query', async () => { mockedAxiosClient - .onGet(apiPath.getCompartmentPathwaysIds(5053)) + .onGet(apiPath.getCompartmentPathwaysIds(MAIN_MAP_ID)) .reply(HttpStatusCode.Ok, compartmentPathwaysFixture); mockedAxiosClient .onGet(apiPath.getCompartmentPathwaysIds(5054)) @@ -98,7 +99,7 @@ describe('compartmentPathways reducer', () => { it('should update store after failed getCompartmentPathways query', async () => { mockedAxiosClient - .onGet(apiPath.getCompartmentPathwaysIds(5053)) + .onGet(apiPath.getCompartmentPathwaysIds(MAIN_MAP_ID)) .reply(HttpStatusCode.NotFound, []); mockedAxiosClient .onGet(apiPath.getCompartmentPathwayDetails([])) diff --git a/src/redux/compartmentPathways/compartmentPathways.thunks.test.ts b/src/redux/compartmentPathways/compartmentPathways.thunks.test.ts index 517b8fec..891eeb38 100644 --- a/src/redux/compartmentPathways/compartmentPathways.thunks.test.ts +++ b/src/redux/compartmentPathways/compartmentPathways.thunks.test.ts @@ -11,6 +11,7 @@ import { compartmentPathwaysOverLimitFixture, } from '@/models/fixtures/compartmentPathways'; import { getModelsIds } from '@/components/Map/Drawer/ExportDrawer/ExportDrawer.component.utils'; +import { MAIN_MAP_ID } from '@/constants/mocks'; import { apiPath } from '../apiPath'; import compartmentPathwaysReducer from './compartmentPathways.slice'; import { CompartmentPathwaysState } from './compartmentPathways.types'; @@ -57,7 +58,7 @@ describe('compartmentPathways thunk', () => { }); it('should handle sendCompartmentPathwaysIds request properly if it is more than 100 ids', async () => { mockedAxiosClient - .onGet(apiPath.getCompartmentPathwaysIds(5053)) + .onGet(apiPath.getCompartmentPathwaysIds(MAIN_MAP_ID)) .reply(HttpStatusCode.Ok, compartmentPathwaysFixture); mockedAxiosClient .onGet(apiPath.getCompartmentPathwaysIds(5054)) diff --git a/src/redux/map/map.fixtures.ts b/src/redux/map/map.fixtures.ts index 268b7f9d..21674c65 100644 --- a/src/redux/map/map.fixtures.ts +++ b/src/redux/map/map.fixtures.ts @@ -1,6 +1,7 @@ import { DEFAULT_ERROR } from '@/constants/errors'; import { MODEL_ID_DEFAULT } from '@/redux/map/map.constants'; import MapBackgroundsEnum from '@/redux/map/map.enums'; +import { HISTAMINE_MAP_ID, MAIN_MAP_ID } from '@/constants/mocks'; import { MapData, MapState, OppenedMap } from './map.types'; export const openedMapsInitialValueFixture: OppenedMap[] = [ @@ -8,8 +9,12 @@ export const openedMapsInitialValueFixture: OppenedMap[] = [ ]; export const openedMapsThreeSubmapsFixture: OppenedMap[] = [ - { modelId: 5053, modelName: 'Main map', lastPosition: { x: 0, y: 0, z: 0 } }, - { modelId: 5052, modelName: 'Histamine signaling', lastPosition: { x: 0, y: 0, z: 0 } }, + { modelId: MAIN_MAP_ID, modelName: 'Main map', lastPosition: { x: 0, y: 0, z: 0 } }, + { + modelId: HISTAMINE_MAP_ID, + modelName: 'Histamine signaling', + lastPosition: { x: 0, y: 0, z: 0 }, + }, { modelId: 5054, modelName: 'PRKN substrates', lastPosition: { x: 0, y: 0, z: 0 } }, ]; diff --git a/src/redux/map/map.thunks.test.ts b/src/redux/map/map.thunks.test.ts index c8bd15b1..b44d0fd8 100644 --- a/src/redux/map/map.thunks.test.ts +++ b/src/redux/map/map.thunks.test.ts @@ -1,6 +1,11 @@ import { MODELS_MOCK } from '@/models/mocks/modelsMock'; /* eslint-disable no-magic-numbers */ import { QueryData } from '@/types/query'; +import { projectFixture } from '@/models/fixtures/projectFixture'; +import { Project } from '@/types/models'; +import { PROJECT_STATE_INITIAL_MOCK } from '@/redux/project/project.mock'; +import { ProjectState } from '@/redux/project/project.types'; +import { MAIN_MAP_ID } from '@/constants/mocks'; import { BACKGROUNDS_MOCK, BACKGROUND_INITIAL_STATE_MOCK } from '../backgrounds/background.mock'; import { MODELS_INITIAL_STATE_MOCK } from '../models/models.mock'; import { INITIAL_STORE_STATE_MOCK } from '../root/root.fixtures'; @@ -45,8 +50,19 @@ const QUERY_DATA_WITH_POSITION: QueryData = { perfectMatch: false, }; +const PROJECT: Project = { + ...projectFixture, + topMap: { id: MAIN_MAP_ID }, +}; + +const PROJECT_STATE: ProjectState = { + ...PROJECT_STATE_INITIAL_MOCK, + data: PROJECT, +}; + const STATE_WITH_MODELS: RootState = { ...INITIAL_STORE_STATE_MOCK, + project: { ...PROJECT_STATE }, models: { ...MODELS_INITIAL_STATE_MOCK, data: MODELS_MOCK }, }; @@ -117,7 +133,7 @@ describe('map thunks - utils', () => { it('should return correct map size and modelId if query params do not include modelId', () => { const payload = getInitMapSizeAndModelId(STATE_WITH_MODELS, EMPTY_QUERY_DATA); expect(payload).toEqual({ - modelId: 5053, + modelId: MAIN_MAP_ID, size: { height: 13503, maxZoom: 9, @@ -133,7 +149,7 @@ describe('map thunks - utils', () => { modelId: 1234567, }); expect(payload).toEqual({ - modelId: 5053, + modelId: MAIN_MAP_ID, size: { height: 13503, maxZoom: 9, @@ -150,13 +166,16 @@ describe('map thunks - utils', () => { const openedMaps = getOpenedMaps( { ...STATE_WITH_MODELS, - map: { ...initialMapStateFixture, data: { ...initialMapDataFixture, modelId: 5053 } }, + map: { + ...initialMapStateFixture, + data: { ...initialMapDataFixture, modelId: MAIN_MAP_ID }, + }, }, 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: MAIN_MAP_ID, modelName: 'Main map' }, ]); }); it('should return main map and opened submap', () => { @@ -169,7 +188,7 @@ describe('map thunks - utils', () => { ); expect(openedMaps).toEqual([ - { lastPosition: { x: 0, y: 0, z: 0 }, modelId: 5053, modelName: 'Main map' }, + { lastPosition: { x: 0, y: 0, z: 0 }, modelId: MAIN_MAP_ID, modelName: 'Main map' }, { lastPosition: { x: 0, diff --git a/src/redux/map/map.thunks.ts b/src/redux/map/map.thunks.ts index 75fcb092..363b1d9c 100644 --- a/src/redux/map/map.thunks.ts +++ b/src/redux/map/map.thunks.ts @@ -147,16 +147,14 @@ export const getInitMapSizeAndModelId = ( }; export const getOpenedMaps = (state: RootState, queryData: QueryData): OppenedMap[] => { - const FIRST = 0; - const models = modelsDataSelector(state); const currentModel = currentModelSelector(state); - const mainMapId = models?.[FIRST]?.id || ZERO; + const mainMap = mainMapModelSelector(state); const openedMaps: OppenedMap[] = [ - { modelId: mainMapId, modelName: MAIN_MAP, lastPosition: DEFAULT_POSITION }, + { modelId: mainMap.id, modelName: MAIN_MAP, lastPosition: DEFAULT_POSITION }, ]; - const isMainMapSetAsCurrentModel = currentModel?.id !== mainMapId; + const isMainMapSetAsCurrentModel = currentModel?.id !== mainMap.id; if (isMainMapSetAsCurrentModel) { openedMaps.push({ diff --git a/src/redux/models/models.selectors.ts b/src/redux/models/models.selectors.ts index 9676601d..606aa70e 100644 --- a/src/redux/models/models.selectors.ts +++ b/src/redux/models/models.selectors.ts @@ -1,5 +1,7 @@ import { rootSelector } from '@/redux/root/root.selectors'; import { createSelector } from '@reduxjs/toolkit'; +import { projectDataSelector } from '@/redux/project/project.selectors'; +import { ZERO } from '@/constants/common'; import { MODEL_ID_DEFAULT } from '../map/map.constants'; import { mapDataSelector } from '../map/map.selectors'; @@ -46,14 +48,20 @@ export const modelByIdSelector = createSelector( (models, modelId) => (models?.data || []).find(({ id }) => id === modelId), ); -const MAIN_MAP = 0; -export const mainMapModelSelector = createSelector(modelsDataSelector, models => models[MAIN_MAP]); +export const mainMapModelSelector = createSelector( + projectDataSelector, + modelsDataSelector, + (project, models) => { + const topMapId = project?.topMap.id; + return models.filter(model => model.id === topMapId)[ZERO]; + }, +); export const loadingModelsSelector = createSelector(modelsSelector, state => state.loading); export const mainMapModelDescriptionSelector = createSelector( - modelsDataSelector, - models => models[MAIN_MAP].description, + mainMapModelSelector, + model => model?.description, ); export const vectorRenderingSelector = createSelector( diff --git a/src/redux/overlays/overlays.thunks.ts b/src/redux/overlays/overlays.thunks.ts index 087d5117..57698bf4 100644 --- a/src/redux/overlays/overlays.thunks.ts +++ b/src/redux/overlays/overlays.thunks.ts @@ -55,13 +55,8 @@ export const getAllUserOverlaysByCreator = createAsyncThunk<MapOverlay[], void, try { const state = getState() as RootState; const creator = state.user.login; - // eslint-disable-next-line no-console - console.log('z1'); if (!creator) return []; - // eslint-disable-next-line no-console - console.log('z2'); - const response = await axiosInstanceNewAPI<PageOf<MapOverlay>>( apiPath.getAllUserOverlaysByCreatorQuery({ creator, @@ -72,9 +67,6 @@ export const getAllUserOverlaysByCreator = createAsyncThunk<MapOverlay[], void, }, ); - // eslint-disable-next-line no-console - console.log('z3'); - const isDataValid = validateDataUsingZodSchema(response.data, pageableSchema(mapOverlay)); const sortByOrder = (userOverlayA: MapOverlay, userOverlayB: MapOverlay): number => { @@ -82,15 +74,10 @@ export const getAllUserOverlaysByCreator = createAsyncThunk<MapOverlay[], void, return -1; }; - // eslint-disable-next-line no-console - console.log('z4', response.data.content); - const sortedUserOverlays = response.data.content .sort(sortByOrder) .filter(overlay => !overlay.publicOverlay); - // eslint-disable-next-line no-console - console.log('z5', isDataValid, sortedUserOverlays); return isDataValid ? sortedUserOverlays : []; } catch (error) { return Promise.reject(getError({ error, prefix: USER_OVERLAYS_FETCHING_ERROR_PREFIX })); @@ -214,22 +201,16 @@ export const addOverlay = createAsyncThunk<undefined, AddOverlayArgs, ThunkConfi // eslint-disable-next-line consistent-return ) => { try { - // eslint-disable-next-line no-console - console.log('y0'); const createdFile = await createFile({ filename, content, }); - // eslint-disable-next-line no-console - console.log('y1'); await uploadContent({ createdFile, overlayContent: content, }); - // eslint-disable-next-line no-console - console.log('y2'); await creteOverlay({ createdFile, description, @@ -238,15 +219,9 @@ export const addOverlay = createAsyncThunk<undefined, AddOverlayArgs, ThunkConfi projectId, }); - // eslint-disable-next-line no-console - console.log('y3'); await dispatch(getAllUserOverlaysByCreator()); - // eslint-disable-next-line no-console - console.log('y4'); showToast({ type: 'success', message: USER_OVERLAY_ADD_SUCCESS_MESSAGE }); - // eslint-disable-next-line no-console - console.log('y5'); } catch (error) { if (axios.isAxiosError(error) && error.code === 'ERR_BAD_REQUEST') { const data = error.response?.data; diff --git a/src/redux/project/project.mock.ts b/src/redux/project/project.mock.ts index a1edbd3b..b1caa44e 100644 --- a/src/redux/project/project.mock.ts +++ b/src/redux/project/project.mock.ts @@ -1,5 +1,6 @@ import { DEFAULT_ERROR } from '@/constants/errors'; import { OverviewImageView } from '@/types/models'; +import { MAIN_MAP_ID } from '@/constants/mocks'; import { ProjectState } from './project.types'; export const PROJECT_STATE_INITIAL_MOCK: ProjectState = { @@ -38,7 +39,7 @@ export const PROJECT_OVERVIEW_IMAGE_MOCK: NonNullable<OverviewImageView> = { zoomLevel: 4, xCoord: 3473, yCoord: 5871, - linkedModel: 5053, + linkedModel: MAIN_MAP_ID, // type: 'OverviewModelLink', }, { @@ -87,7 +88,7 @@ export const PROJECT_OVERVIEW_IMAGE_MOCK: NonNullable<OverviewImageView> = { zoomLevel: 5, xCoord: 8081, yCoord: 1240, - linkedModel: 5053, + linkedModel: MAIN_MAP_ID, // type: 'OverviewModelLink', }, { @@ -136,7 +137,7 @@ export const PROJECT_OVERVIEW_IMAGE_MOCK: NonNullable<OverviewImageView> = { zoomLevel: 5, xCoord: 7488, yCoord: 11986, - linkedModel: 5053, + linkedModel: MAIN_MAP_ID, // type: 'OverviewModelLink', }, { diff --git a/src/services/pluginsManager/map/openMap.test.ts b/src/services/pluginsManager/map/openMap.test.ts index b3d01c8f..69aca9db 100644 --- a/src/services/pluginsManager/map/openMap.test.ts +++ b/src/services/pluginsManager/map/openMap.test.ts @@ -4,6 +4,7 @@ import { RootState, store } from '@/redux/store'; import { initialMapDataFixture, openedMapsThreeSubmapsFixture } from '@/redux/map/map.fixtures'; import { MODELS_MOCK, MODELS_MOCK_SHORT } from '@/models/mocks/modelsMock'; import MapBackgroundsEnum from '@/redux/map/map.enums'; +import { HISTAMINE_MAP_ID, MAIN_MAP_ID } from '@/constants/mocks'; import { PluginsEventBus } from '../pluginsEventBus'; import { openMap } from './openMap'; @@ -22,7 +23,7 @@ describe('openMap', () => { () => ({ map: { - data: { ...initialMapDataFixture, modelId: 5052 }, + data: { ...initialMapDataFixture, modelId: HISTAMINE_MAP_ID }, loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, @@ -36,11 +37,11 @@ describe('openMap', () => { }) as RootState, ); - openMap({ id: 5053 }); + openMap({ id: MAIN_MAP_ID }); - expect(dispatchSpy).toHaveBeenCalledWith(setActiveMap({ modelId: 5053 })); - expect(pluginDispatchEvent).toHaveBeenCalledWith('onSubmapClose', 5052); - expect(pluginDispatchEvent).toHaveBeenCalledWith('onSubmapOpen', 5053); + expect(dispatchSpy).toHaveBeenCalledWith(setActiveMap({ modelId: MAIN_MAP_ID })); + expect(pluginDispatchEvent).toHaveBeenCalledWith('onSubmapClose', HISTAMINE_MAP_ID); + expect(pluginDispatchEvent).toHaveBeenCalledWith('onSubmapOpen', MAIN_MAP_ID); }); it('should open map and set active map when map with provided id is not already opened', () => { @@ -48,7 +49,7 @@ describe('openMap', () => { () => ({ map: { - data: { ...initialMapDataFixture, modelId: 5052 }, + data: { ...initialMapDataFixture, modelId: HISTAMINE_MAP_ID }, loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, @@ -67,7 +68,7 @@ describe('openMap', () => { expect(dispatchSpy).toHaveBeenCalledWith( openMapAndSetActive({ modelId: 5061, modelName: 'Wnt signaling' }), ); - expect(pluginDispatchEvent).toHaveBeenCalledWith('onSubmapClose', 5052); + expect(pluginDispatchEvent).toHaveBeenCalledWith('onSubmapClose', HISTAMINE_MAP_ID); expect(pluginDispatchEvent).toHaveBeenCalledWith('onSubmapOpen', 5061); }); @@ -76,7 +77,7 @@ describe('openMap', () => { () => ({ map: { - data: { ...initialMapDataFixture, modelId: 5052 }, + data: { ...initialMapDataFixture, modelId: HISTAMINE_MAP_ID }, loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, diff --git a/src/services/pluginsManager/map/triggerSearch/getVisibleBioEntitiesPolygonCoordinates.test.ts b/src/services/pluginsManager/map/triggerSearch/getVisibleBioEntitiesPolygonCoordinates.test.ts index 47fc1165..35661b14 100644 --- a/src/services/pluginsManager/map/triggerSearch/getVisibleBioEntitiesPolygonCoordinates.test.ts +++ b/src/services/pluginsManager/map/triggerSearch/getVisibleBioEntitiesPolygonCoordinates.test.ts @@ -5,6 +5,7 @@ import { bioEntityContentFixture } from '@/models/fixtures/bioEntityContentsFixt import { DRAWER_INITIAL_STATE } from '@/redux/drawer/drawer.constants'; import { MODELS_DATA_MOCK_WITH_MAIN_MAP } from '@/redux/models/models.mock'; +import { HISTAMINE_MAP_ID } from '@/constants/mocks'; import { getVisibleBioEntitiesPolygonCoordinates } from './getVisibleBioEntitiesPolygonCoordinates'; jest.mock('../../../../redux/store'); @@ -24,7 +25,7 @@ describe('getVisibleBioEntitiesPolygonCoordinates', () => { ...MAP_INITIAL_STATE, data: { ...MAP_INITIAL_STATE.data, - modelId: 5052, + modelId: HISTAMINE_MAP_ID, size: { width: 256, height: 256, diff --git a/src/services/pluginsManager/map/triggerSearch/searchByQuery.test.ts b/src/services/pluginsManager/map/triggerSearch/searchByQuery.test.ts index b4beac3e..45c0e9df 100644 --- a/src/services/pluginsManager/map/triggerSearch/searchByQuery.test.ts +++ b/src/services/pluginsManager/map/triggerSearch/searchByQuery.test.ts @@ -10,6 +10,7 @@ import { RootState, store } from '@/redux/store'; import { mockNetworkNewAPIResponse } from '@/utils/mockNetworkResponse'; import { waitFor } from '@testing-library/react'; import { HttpStatusCode } from 'axios'; +import { HISTAMINE_MAP_ID } from '@/constants/mocks'; import { searchByQuery } from './searchByQuery'; import { searchFitBounds } from './searchFitBounds'; @@ -19,7 +20,7 @@ const MOCK_SEARCH_BY_QUERY_STORE = { ...MAP_INITIAL_STATE, data: { ...MAP_INITIAL_STATE.data, - modelId: 5052, + modelId: HISTAMINE_MAP_ID, size: { width: 256, height: 256, -- GitLab