Skip to content

Commit

Permalink
fixed unit test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
unclFedor committed Nov 2, 2023
1 parent 8959930 commit 88eb9f2
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 16 deletions.
2 changes: 0 additions & 2 deletions jest-setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import "@testing-library/jest-dom";
import { TextEncoder, TextDecoder } from "util";
Object.assign(global, { TextDecoder, TextEncoder });
15 changes: 15 additions & 0 deletions src/components/comparison/comparison-side/comparison-side.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ 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("../../deck-gl-wrapper/deck-gl-wrapper");
jest.mock("../../main-tools-panel/main-tools-panel");
Expand Down
32 changes: 24 additions & 8 deletions src/components/deck-gl-wrapper/deck-gl-wrapper.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@ 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("@deck.gl/core");
jest.mock("@deck.gl/layers");
jest.mock("@deck.gl/geo-layers");
jest.mock("react-map-gl");
jest.mock("../../utils/debug/build-minimap-data");
jest.mock("../../utils/debug/texture-selector-utils");
jest.mock("../../utils/debug/frustum-utils");
Expand Down Expand Up @@ -61,7 +73,7 @@ import { setupStore } from "../../redux/store";
import { setColorsByAttrubute } from "../../redux/slices/colors-by-attribute-slice";
import { setDragMode } from "../../redux/slices/drag-mode-slice";
import { setDebugOptions } from "../../redux/slices/debug-options-slice";
import { addBaseMap } from "../../redux/slices/base-maps-slice"
import { addBaseMap } from "../../redux/slices/base-maps-slice";

const simpleCallbackMock = jest.fn().mockImplementation(() => {
/* Do Nothing */
Expand Down Expand Up @@ -336,7 +348,11 @@ describe("Deck.gl I3S map component", () => {

it("Should render pickable with auto highlighting", () => {
const store = setupStore();
callRender(renderWithProvider, { pickable: true, autoHighlight: true }, store);
callRender(
renderWithProvider,
{ pickable: true, autoHighlight: true },
store
);
const { pickable, autoHighlight } = Tile3DLayer.mock.lastCall[0];
expect(pickable).toBe(true);
expect(autoHighlight).toBe(true);
Expand Down Expand Up @@ -509,8 +525,7 @@ describe("Deck.gl I3S map component", () => {

describe("Render TerrainLayer", () => {
const store = setupStore();
store.dispatch(
addBaseMap({ id: "Terrain", mapUrl: "", name: "Terrain" }));
store.dispatch(addBaseMap({ id: "Terrain", mapUrl: "", name: "Terrain" }));
it("Should render terrain", () => {
callRender(renderWithProvider, undefined, store);
expect(TerrainLayer).toHaveBeenCalled();
Expand All @@ -519,7 +534,8 @@ describe("Deck.gl I3S map component", () => {
it("Should call onTerrainTileLoad", () => {
const store = setupStore();
store.dispatch(
addBaseMap({ id: "Terrain", mapUrl: "", name: "Terrain" }));
addBaseMap({ id: "Terrain", mapUrl: "", name: "Terrain" })
);
const { rerender } = callRender(renderWithProvider, undefined, store);
const { onTileLoad } = TerrainLayer.mock.lastCall[0];
const terrainTile = {
Expand Down
7 changes: 2 additions & 5 deletions src/components/layers-panel/layers-panel.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ import { LayerSettingsPanel } from "./layer-settings-panel";
import { load } from "@loaders.gl/core";
import { PageId } from "../../types";
import { setupStore } from "../../redux/store";
import {
selectSelectedBaseMapId,
} from "../../redux/slices/base-maps-slice";
import { selectSelectedBaseMapId } from "../../redux/slices/base-maps-slice";

jest.mock("@loaders.gl/core", () => ({
load: jest.fn(),
}));

jest.mock("@loaders.gl/i3s", () => ({
ArcGisWebSceneLoader: jest.fn(),
}));
Expand Down Expand Up @@ -277,7 +274,7 @@ describe("Layers Panel", () => {
});

const state = store.getState();
const baseMapId = selectSelectedBaseMapId(state);
const baseMapId = selectSelectedBaseMapId(state);
expect(baseMapId).toEqual("https://test-base-map.url");
});

Expand Down
3 changes: 3 additions & 0 deletions src/redux/slices/attribute-stats-map-slice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
import { StatsInfo } from "@loaders.gl/i3s";

jest.mock("@loaders.gl/core");
jest.mock("@loaders.gl/i3s", () => ({
load: jest.fn(),
}));

describe("slice: attribute-stats-map", () => {
it("Selector should return the initial state", () => {
Expand Down
4 changes: 4 additions & 0 deletions src/redux/slices/base-maps-slice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import reducer, {
deleteBaseMaps,
} from "./base-maps-slice";

jest.mock("@loaders.gl/i3s", () => ({
load: jest.fn(),
}));

describe("slice: base-maps", () => {
it("Reducer should return the initial state", () => {
expect(reducer(undefined, { type: undefined })).toEqual({
Expand Down
4 changes: 4 additions & 0 deletions src/redux/slices/colors-by-attribute-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ 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 */
Expand Down
4 changes: 3 additions & 1 deletion src/redux/slices/drag-mode-slice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import reducer, {
selectDragMode,
setDragMode,
} from "./drag-mode-slice";

jest.mock("@loaders.gl/i3s", () => ({
load: jest.fn(),
}));
describe("slice: drag-mode", () => {
it("Reducer should return the initial state", () => {
expect(reducer(undefined, { type: undefined })).toEqual({
Expand Down
3 changes: 3 additions & 0 deletions src/redux/slices/flattened-sublayers-slice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import {
} from "./test-data/fluttened-sublayers-slice-test-data";

jest.mock("@loaders.gl/core");
jest.mock("@loaders.gl/i3s", () => ({
load: jest.fn(),
}));

const previousState: flattenedSublayersState = {
single: {
Expand Down
3 changes: 3 additions & 0 deletions src/redux/slices/uv-debug-texture-slice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
import { ImageLoader } from "@loaders.gl/images";

jest.mock("@loaders.gl/core");
jest.mock("@loaders.gl/i3s", () => ({
load: jest.fn(),
}));

const imageStubObject = { width: 1024, height: 1024, data: new ArrayBuffer(0) };

Expand Down

0 comments on commit 88eb9f2

Please sign in to comment.