Skip to content

Commit

Permalink
Unit test added
Browse files Browse the repository at this point in the history
  • Loading branch information
dariaterekhova-actionengine committed Nov 27, 2024
1 parent b1b1966 commit eb69ca2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
},
parser: "@typescript-eslint/parser",
extends: ["standard-with-typescript", "plugin:react/recommended"],
// ignorePatterns: ["**/*.html"],
ignorePatterns: ["**/*.slpk"],
overrides: [
{
env: {
Expand Down
37 changes: 32 additions & 5 deletions src/redux/slices/flattened-sublayers-slice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ import {
wslExpectedLayers,
wslTestTileset,
} from "./test-data/fluttened-sublayers-slice-test-data";
import { readFile } from "node:fs/promises";

jest.mock("@loaders.gl/core");
jest.mock("@loaders.gl/i3s", () => {
return jest.fn().mockImplementation(() => {
return null;
});
});
jest.mock("@loaders.gl/i3s");

const previousState: FlattenedSublayersState = {
single: {
Expand Down Expand Up @@ -304,6 +301,36 @@ describe("slice: flattened-sublayers", () => {
expect(newSingleState.flattenedSublayers.single.layerCounter).toEqual(1);
});

it("getFlattenedSublayers should call mocked layers loading for SLPK tileset", async () => {
(load as unknown as jest.Mock<any>).mockReturnValue(
Promise.resolve(bslTestTileset)
);

const store = setupStore();
const state = store.getState();
expect(selectLayers(state)).toEqual([]);

const slpkBinary = (await readFile("src/redux/slices/test-data/Admin_Building_v18.slpk")).buffer as any;
slpkBinary.size = slpkBinary.byteLength;

const tilesetsData = [
{
hasChildren: false,
id: "testSLPK_id",
type: TilesetType.I3S,
url: slpkBinary,
},
];

await store.dispatch(
getFlattenedSublayers({ tilesetsData, buildingExplorerOpened: false })
);

const newSingleState = store.getState();
expect(selectSublayers(newSingleState)).toEqual(expectedOverviewSubLayers);
expect(newSingleState.flattenedSublayers.single.layerCounter).toEqual(1);
});

it("getFlattenedSublayers should call mocked layers loading and put BSL layers and sublayers into the slice state", async () => {
(load as unknown as jest.Mock<any>).mockReturnValue(
Promise.resolve(bslTestTileset)
Expand Down
Binary file not shown.

0 comments on commit eb69ca2

Please sign in to comment.