UNPKG

@panoramax/web-viewer

Version:

Panoramax web viewer for geolocated pictures

85 lines (73 loc) 2.2 kB
import Viewer from "../../../src/components/core/Viewer"; import "./BasicMock"; jest.mock("../../../src/components/core/PhotoViewer", () => ( class PhotoViewer extends EventTarget { constructor() { super(); this.loader = { setAttribute: jest.fn() }; this.api = { getMapStyle: () => ({}), _getMapRequestTransform: () => ({}), _endpoints: {}, }; this._t = { maplibre: {}, psv: {} }; this.grid = { appendChild: jest.fn() }; } getAttribute() { return null; } isWidthSmall() { return false; } isHeightSmall() { return false; } getSubComponentsNames() { return ["loader", "api", "psv", "grid", "popup", "urlHandler"]; } onceAPIReady() { return Promise.resolve(); } static GetJSONConverter() { return {}; } } )); let comp; global.console = { info: jest.fn(), error: jest.fn(), warn: jest.fn(), log: global.console.log }; beforeEach(() => comp = new Viewer()); afterEach(() => jest.clearAllMocks()); describe("_initWidgets", () => { let initParamsMock; beforeEach(() => { comp.grid.appendChild = jest.fn(); // Mock the return value of getParentPostInit initParamsMock = { widgets: "true", focus: "pic", picture: "somePicture", }; comp._createInitParamsHandler(); comp._initParams.getParentPostInit = jest.fn(); comp._initParams.getParentPostInit.mockReturnValue(initParamsMock); }); it("should not add widgets if widgets is false", () => { initParamsMock.widgets = "false"; comp._initWidgets(); expect(comp.grid.appendChild).not.toHaveBeenCalled(); }); it("should handle widgets if width is not small", () => { comp.isWidthSmall = () => false; comp._initWidgets(); expect(comp.grid.appendChild).toMatchSnapshot(); }); it("should handle widgets if width is small", () => { comp.isWidthSmall = () => true; comp._initWidgets(); expect(comp.grid.appendChild).toMatchSnapshot(); }); }); describe("getClassName", () => { it("works", () => { expect(comp.getClassName()).toBe("Viewer"); }); }); describe("getSubComponentsNames", () => { it("works", () => { expect(comp.getSubComponentsNames()).toEqual(["loader", "api", "psv", "grid", "popup", "urlHandler", "mini", "map"]); }); });