UNPKG

@panoramax/web-viewer

Version:

Panoramax web viewer for geolocated pictures

58 lines (46 loc) 1.51 kB
import PhotoViewer from "../../../src/components/core/PhotoViewer"; import "./BasicMock"; let comp; global.console = { info: jest.fn(), error: jest.fn(), warn: jest.fn(), log: global.console.log }; beforeEach(() => comp = new PhotoViewer()); 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("PhotoViewer"); }); }); describe("getSubComponentsNames", () => { it("works", () => { expect(comp.getSubComponentsNames()).toEqual(["loader", "api", "psv", "grid", "popup", "urlHandler"]); }); });