diff --git a/src/components/Map/MapViewer/utils/config/overlaysLayer/useOverlayFeatures.test.ts b/src/components/Map/MapViewer/utils/config/overlaysLayer/useOverlayFeatures.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..19c9b309415c6943c7c86e8b1fe477c606affe81 --- /dev/null +++ b/src/components/Map/MapViewer/utils/config/overlaysLayer/useOverlayFeatures.test.ts @@ -0,0 +1,69 @@ +/* eslint-disable no-magic-numbers */ +import { renderHook } from '@testing-library/react'; +import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; +import { CONFIGURATION_INITIAL_STORE_MOCKS } from '@/redux/configuration/configuration.mock'; +import { OVERLAYS_PUBLIC_FETCHED_STATE_MOCK } from '@/redux/overlays/overlays.mock'; +import { mapStateWithCurrentlySelectedMainMapFixture } from '@/redux/map/map.fixtures'; +import { MODELS_DATA_MOCK_WITH_MAIN_MAP } from '@/redux/models/models.mock'; +import { MOCKED_OVERLAY_BIO_ENTITY_RENDER } from '@/redux/overlayBioEntity/overlayBioEntity.mock'; +import { useOverlayFeatures } from './useOverlayFeatures'; + +/** + * mocks for useOverlayFeatures + * are taken from helpers functions that are used inside useOverlayFeatures + * point of the test is to test if all helper functions work correctly when combined together + */ + +describe('useOverlayFeatures', () => { + const { Wrapper } = getReduxWrapperWithStore({ + configuration: { + ...CONFIGURATION_INITIAL_STORE_MOCKS, + }, + overlayBioEntity: { + overlaysId: [11, 12], + data: { + // overlayId + 11: { + // modelId + 52: MOCKED_OVERLAY_BIO_ENTITY_RENDER, + 53: MOCKED_OVERLAY_BIO_ENTITY_RENDER, + }, + 12: { + 52: MOCKED_OVERLAY_BIO_ENTITY_RENDER, + 53: MOCKED_OVERLAY_BIO_ENTITY_RENDER, + }, + }, + }, + overlays: { + ...OVERLAYS_PUBLIC_FETCHED_STATE_MOCK, + }, + map: { + ...mapStateWithCurrentlySelectedMainMapFixture, + }, + models: { + ...MODELS_DATA_MOCK_WITH_MAIN_MAP, + }, + }); + + it('should return an array of features', () => { + const { + result: { current: features }, + } = renderHook(() => useOverlayFeatures(), { + wrapper: Wrapper, + }); + + expect(features).toHaveLength(6); + expect(features[0].getGeometry()?.getCoordinates()).toEqual([ + [ + [-13149141, 18867005], + [-13149141, 18881970], + [-13143529, 18881970], + [-13143529, 18867005], + [-13149141, 18867005], + ], + ]); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + expect(features[0].getStyle().getFill().getColor()).toBe('#FFFFFFcc'); + }); +}); diff --git a/src/redux/map/map.fixtures.ts b/src/redux/map/map.fixtures.ts index 5cb2f16fe2683d2988f2a7bd16aff6e95a558eaf..be022b6972ad0c42f4ff1c7c9e2c95351f47af4e 100644 --- a/src/redux/map/map.fixtures.ts +++ b/src/redux/map/map.fixtures.ts @@ -40,3 +40,20 @@ export const initialMapStateFixture: MapState = { error: DEFAULT_ERROR, openedMaps: openedMapsInitialValueFixture, }; + +export const mapStateWithCurrentlySelectedMainMapFixture: MapState = { + data: { + ...initialMapDataFixture, + modelId: 52, + size: { + width: 26779.25, + height: 13503, + tileSize: 256, + minZoom: 2, + maxZoom: 9, + }, + }, + loading: 'idle', + error: DEFAULT_ERROR, + openedMaps: openedMapsInitialValueFixture, +}; diff --git a/src/redux/models/models.mock.ts b/src/redux/models/models.mock.ts index e45763d82516d7ff30c12ee7512a8da5f2378cdf..b7658d3867c9d80e221fa59ffd8507c51b0cf46d 100644 --- a/src/redux/models/models.mock.ts +++ b/src/redux/models/models.mock.ts @@ -6,3 +6,27 @@ export const MODELS_INITIAL_STATE_MOCK: ModelsState = { loading: 'idle', error: DEFAULT_ERROR, }; + +export const MODELS_DATA_MOCK_WITH_MAIN_MAP: ModelsState = { + data: [ + { + idObject: 52, + 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, +}; diff --git a/src/redux/overlayBioEntity/overlayBioEntity.mock.ts b/src/redux/overlayBioEntity/overlayBioEntity.mock.ts index 4fa115d0c747d65e9d25369984108bc98c4ca6ce..84fab91d714d1acdbb49aa3275b6b5fe13cc668c 100644 --- a/src/redux/overlayBioEntity/overlayBioEntity.mock.ts +++ b/src/redux/overlayBioEntity/overlayBioEntity.mock.ts @@ -1,6 +1,49 @@ +import { OverlayBioEntityRender } from '@/types/OLrendering'; import { OverlaysBioEntityState } from './overlayBioEntity.types'; export const OVERLAY_BIO_ENTITY_INITIAL_STATE_MOCK: OverlaysBioEntityState = { overlaysId: [], data: [], }; + +export const MOCKED_OVERLAY_BIO_ENTITY_RENDER: OverlayBioEntityRender[] = [ + { + id: 1, + modelId: 52, + width: 30, + x1: 18412, + x2: 18492, + y1: 3128.653195488725, + y2: 3088.653195488725, + overlayId: 11, + height: 10, + value: 0, + color: null, + }, + { + id: 2, + modelId: 52, + width: 30, + x1: 18412, + x2: 18492, + y1: 3128.653195488725, + y2: 3088.653195488725, + overlayId: 11, + height: 10, + value: -0.2137, + color: null, + }, + { + id: 3, + modelId: 52, + width: 40, + x1: 18412, + x2: 18492, + y1: 3128.653195488725, + y2: 3088.653195488725, + overlayId: 11, + height: 10, + value: null, + color: { rgb: -65536, alpha: 0 }, + }, +];