From 73af9f212408b18dc691357c6de4866b4bcdd22e Mon Sep 17 00:00:00 2001 From: Viktor Belomestnov Date: Fri, 3 Nov 2023 14:37:20 +0100 Subject: [PATCH] fix tests --- .../attributes-stats/attribute-stats.spec.tsx | 5 ++ .../comparison-side/comparison-side.spec.tsx | 46 ++++++++++++------- .../debug-panel/debug-panel.spec.tsx | 5 ++ .../deck-gl-wrapper/deck-gl-wrapper.spec.tsx | 46 +++++++++++++------ .../layers-panel/map-options-panel.spec.tsx | 5 ++ .../map-control-panel.spec.tsx | 6 +++ .../slices/attribute-stats-map-slice.spec.ts | 11 +++-- src/redux/slices/base-maps-slice.spec.ts | 8 ++-- src/redux/slices/base-maps-slice.ts | 2 +- .../slices/colors-by-attribute-slice.spec.ts | 6 +++ src/redux/slices/colors-by-attribute-slice.ts | 4 -- src/redux/slices/debug-option-slice.spec.ts | 6 +++ src/redux/slices/drag-mode-slice.spec.ts | 10 ++-- .../slices/flattened-sublayers-slice.spec.ts | 8 ++-- .../slices/uv-debug-texture-slice.spec.ts | 8 ++-- 15 files changed, 123 insertions(+), 53 deletions(-) diff --git a/src/components/attributes-panel/attributes-stats/attribute-stats.spec.tsx b/src/components/attributes-panel/attributes-stats/attribute-stats.spec.tsx index 1d8507eb..4cc808dd 100644 --- a/src/components/attributes-panel/attributes-stats/attribute-stats.spec.tsx +++ b/src/components/attributes-panel/attributes-stats/attribute-stats.spec.tsx @@ -9,6 +9,11 @@ import { setupStore } from "../../../redux/store"; import { setColorsByAttrubute } from "../../../redux/slices/colors-by-attribute-slice"; jest.mock("@loaders.gl/core"); +jest.mock("@loaders.gl/i3s", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); jest.mock("../histogram", () => ({ HistogramChart: jest.fn().mockImplementation(() =>
HistogramChart
), diff --git a/src/components/comparison/comparison-side/comparison-side.spec.tsx b/src/components/comparison/comparison-side/comparison-side.spec.tsx index c2405fb3..198cb217 100644 --- a/src/components/comparison/comparison-side/comparison-side.spec.tsx +++ b/src/components/comparison/comparison-side/comparison-side.spec.tsx @@ -18,22 +18,36 @@ import { MemoryUsagePanel } from "../../memory-usage-panel/memory-usage-panel"; import { setupStore } from "../../../redux/store"; import { setDragMode } from "../../../redux/slices/drag-mode-slice"; -jest.mock("@deck.gl/geo-layers", () => ({ - load: jest.fn(), -})); -jest.mock("@deck.gl/layers", () => ({ - load: jest.fn(), -})); -jest.mock("maplibre-gl", () => ({ - load: jest.fn(), -})); -jest.mock("@loaders.gl/i3s", () => ({ - load: jest.fn(), -})); -jest.mock("@loaders.gl/3d-tiles", () => ({ - load: jest.fn(), -})); -jest.mock("@loaders.gl/core"); +jest.mock("react-map-gl/maplibre", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); +jest.mock("@loaders.gl/core", () => { + return { + load: jest.fn(), + }; +}); +jest.mock("@loaders.gl/i3s", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); +jest.mock("@loaders.gl/3d-tiles", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); +jest.mock("@deck.gl/layers", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); +jest.mock("@deck.gl/geo-layers", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); jest.mock("../../deck-gl-wrapper/deck-gl-wrapper"); jest.mock("../../main-tools-panel/main-tools-panel"); jest.mock("../../layers-panel/layers-panel"); diff --git a/src/components/debug-panel/debug-panel.spec.tsx b/src/components/debug-panel/debug-panel.spec.tsx index 18b75124..6d449b15 100644 --- a/src/components/debug-panel/debug-panel.spec.tsx +++ b/src/components/debug-panel/debug-panel.spec.tsx @@ -16,6 +16,11 @@ import { selectBoundingVolumeType, } from "../../redux/slices/debug-options-slice"; +jest.mock("@loaders.gl/i3s", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); jest.mock("../../utils/hooks/layout"); jest.mock("../close-button/close-button", () => ({ CloseButton: ({ onClick }) => { diff --git a/src/components/deck-gl-wrapper/deck-gl-wrapper.spec.tsx b/src/components/deck-gl-wrapper/deck-gl-wrapper.spec.tsx index 5bed7024..934b2994 100644 --- a/src/components/deck-gl-wrapper/deck-gl-wrapper.spec.tsx +++ b/src/components/deck-gl-wrapper/deck-gl-wrapper.spec.tsx @@ -11,6 +11,19 @@ import { // Mocks jest.mock("@loaders.gl/core"); +jest.mock("@loaders.gl/i3s", () => { + return { + COORDINATE_SYSTEM: { + METER_OFFSETS: 2, + LNGLAT_OFFSETS: 3, + }, + }; +}); +jest.mock("@loaders.gl/3d-tiles", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); jest.mock("@loaders.gl/images"); jest.mock("@loaders.gl/tiles"); jest.mock("@deck.gl/react", () => { @@ -18,22 +31,25 @@ jest.mock("@deck.gl/react", () => { return null; }); }); -jest.mock("@deck.gl/geo-layers", () => ({ - load: jest.fn(), -})); -jest.mock("@deck.gl/layers", () => ({ - load: jest.fn(), -})); -jest.mock("maplibre-gl", () => ({ - load: jest.fn(), -})); -jest.mock("@loaders.gl/i3s", () => ({ - load: jest.fn(), -})); -jest.mock("@loaders.gl/3d-tiles", () => ({ - load: jest.fn(), -})); +jest.mock("react-map-gl/maplibre", () => { + return { + Map: jest.fn().mockImplementation(() =>
), + }; +}); jest.mock("@deck.gl/core"); +jest.mock("@deck.gl/layers", () => { + return { + LineLayer: jest.fn(), + ScatterplotLayer: jest.fn(), + }; +}); + +jest.mock("@deck.gl/geo-layers", () => { + return { + Tile3DLayer: jest.fn(), + TerrainLayer: jest.fn(), + }; +}); jest.mock("../../utils/debug/build-minimap-data"); jest.mock("../../utils/debug/texture-selector-utils"); jest.mock("../../utils/debug/frustum-utils"); diff --git a/src/components/layers-panel/map-options-panel.spec.tsx b/src/components/layers-panel/map-options-panel.spec.tsx index 6ee488ac..8f3130a1 100644 --- a/src/components/layers-panel/map-options-panel.spec.tsx +++ b/src/components/layers-panel/map-options-panel.spec.tsx @@ -14,6 +14,11 @@ import { selectSelectedBaseMapId, } from "../../redux/slices/base-maps-slice"; +jest.mock("@loaders.gl/i3s", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); jest.mock("./base-map-list-item/base-map-list-item"); jest.mock("../plus-button/plus-button"); jest.mock("./delete-confirmation"); diff --git a/src/components/map-control-panel/map-control-panel.spec.tsx b/src/components/map-control-panel/map-control-panel.spec.tsx index 879182b6..724001a8 100644 --- a/src/components/map-control-panel/map-control-panel.spec.tsx +++ b/src/components/map-control-panel/map-control-panel.spec.tsx @@ -5,6 +5,12 @@ import { MapControllPanel } from "./map-control-panel"; import { setupStore } from "../../redux/store"; import { setDragMode } from "../../redux/slices/drag-mode-slice"; +jest.mock("@loaders.gl/i3s", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); + describe("MapControllPanel", () => { let componentElement; let buttons; diff --git a/src/redux/slices/attribute-stats-map-slice.spec.ts b/src/redux/slices/attribute-stats-map-slice.spec.ts index 124a921f..6f55d6d7 100644 --- a/src/redux/slices/attribute-stats-map-slice.spec.ts +++ b/src/redux/slices/attribute-stats-map-slice.spec.ts @@ -4,12 +4,13 @@ import { getAttributeStatsInfo, selectStatisitcsMap, } from "./attribute-stats-map-slice"; -import { StatsInfo } from "@loaders.gl/i3s"; jest.mock("@loaders.gl/core"); -jest.mock("@loaders.gl/i3s", () => ({ - load: jest.fn(), -})); +jest.mock("@loaders.gl/i3s", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); describe("slice: attribute-stats-map", () => { it("Selector should return the initial state", () => { @@ -57,7 +58,7 @@ describe("slice: attribute-stats-map", () => { }); }); -const stats: StatsInfo = { +const stats = { avg: 27.159085097827166, max: 1408.377901, min: 0, diff --git a/src/redux/slices/base-maps-slice.spec.ts b/src/redux/slices/base-maps-slice.spec.ts index ed7952ea..f102075b 100644 --- a/src/redux/slices/base-maps-slice.spec.ts +++ b/src/redux/slices/base-maps-slice.spec.ts @@ -9,9 +9,11 @@ import reducer, { deleteBaseMaps, } from "./base-maps-slice"; -jest.mock("@loaders.gl/i3s", () => ({ - load: jest.fn(), -})); +jest.mock("@loaders.gl/i3s", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); describe("slice: base-maps", () => { it("Reducer should return the initial state", () => { diff --git a/src/redux/slices/base-maps-slice.ts b/src/redux/slices/base-maps-slice.ts index e1a10a84..356b5df3 100644 --- a/src/redux/slices/base-maps-slice.ts +++ b/src/redux/slices/base-maps-slice.ts @@ -4,7 +4,7 @@ import { BASE_MAPS } from "../../constants/map-styles"; import { RootState } from "../store"; // Define a type for the slice state -interface BaseMapsState { +export interface BaseMapsState { baseMap: BaseMap[]; selectedBaseMap: string; } diff --git a/src/redux/slices/colors-by-attribute-slice.spec.ts b/src/redux/slices/colors-by-attribute-slice.spec.ts index 62eae9c1..7969f4de 100644 --- a/src/redux/slices/colors-by-attribute-slice.spec.ts +++ b/src/redux/slices/colors-by-attribute-slice.spec.ts @@ -5,6 +5,12 @@ import reducer, { setColorsByAttrubute, } from "./colors-by-attribute-slice"; +jest.mock("@loaders.gl/i3s", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); + describe("slice: colors-by-attribute", () => { it("Reducer should return the initial state", () => { expect(reducer(undefined, { type: undefined })).toEqual({ value: null }); diff --git a/src/redux/slices/colors-by-attribute-slice.ts b/src/redux/slices/colors-by-attribute-slice.ts index 613aaff7..8483b5e0 100644 --- a/src/redux/slices/colors-by-attribute-slice.ts +++ b/src/redux/slices/colors-by-attribute-slice.ts @@ -2,10 +2,6 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit"; import { ColorsByAttribute } from "../../types"; import { RootState } from "../store"; -jest.mock("@loaders.gl/i3s", () => ({ - load: jest.fn(), -})); - // Define a type for the slice state export interface ColorsByAttributeState { /** Values of color properties responsible for colorizig by attributes */ diff --git a/src/redux/slices/debug-option-slice.spec.ts b/src/redux/slices/debug-option-slice.spec.ts index 277d5925..210e95fd 100644 --- a/src/redux/slices/debug-option-slice.spec.ts +++ b/src/redux/slices/debug-option-slice.spec.ts @@ -21,6 +21,12 @@ import reducer, { setDebugOptions, } from "./debug-options-slice"; +jest.mock("@loaders.gl/i3s", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); + describe("slice: debug-options", () => { it("Reducer should return the initial state", () => { expect(reducer(undefined, { type: undefined })).toEqual({ diff --git a/src/redux/slices/drag-mode-slice.spec.ts b/src/redux/slices/drag-mode-slice.spec.ts index 013594ed..9308df16 100644 --- a/src/redux/slices/drag-mode-slice.spec.ts +++ b/src/redux/slices/drag-mode-slice.spec.ts @@ -5,9 +5,13 @@ import reducer, { selectDragMode, setDragMode, } from "./drag-mode-slice"; -jest.mock("@loaders.gl/i3s", () => ({ - load: jest.fn(), -})); + +jest.mock("@loaders.gl/i3s", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); + describe("slice: drag-mode", () => { it("Reducer should return the initial state", () => { expect(reducer(undefined, { type: undefined })).toEqual({ diff --git a/src/redux/slices/flattened-sublayers-slice.spec.ts b/src/redux/slices/flattened-sublayers-slice.spec.ts index 71784d45..1141f6e0 100644 --- a/src/redux/slices/flattened-sublayers-slice.spec.ts +++ b/src/redux/slices/flattened-sublayers-slice.spec.ts @@ -25,9 +25,11 @@ import { } from "./test-data/fluttened-sublayers-slice-test-data"; jest.mock("@loaders.gl/core"); -jest.mock("@loaders.gl/i3s", () => ({ - load: jest.fn(), -})); +jest.mock("@loaders.gl/i3s", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); const previousState: flattenedSublayersState = { single: { diff --git a/src/redux/slices/uv-debug-texture-slice.spec.ts b/src/redux/slices/uv-debug-texture-slice.spec.ts index 01f6ccc6..8d10424f 100644 --- a/src/redux/slices/uv-debug-texture-slice.spec.ts +++ b/src/redux/slices/uv-debug-texture-slice.spec.ts @@ -7,9 +7,11 @@ import { import { ImageLoader } from "@loaders.gl/images"; jest.mock("@loaders.gl/core"); -jest.mock("@loaders.gl/i3s", () => ({ - load: jest.fn(), -})); +jest.mock("@loaders.gl/i3s", () => { + return jest.fn().mockImplementation(() => { + return null; + }); +}); const imageStubObject = { width: 1024, height: 1024, data: new ArrayBuffer(0) };