tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

components_application_panel-PageSwitcher.test.js (2101B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Import libs
      7 const { shallow } = require("enzyme");
      8 const { createFactory } = require("react");
      9 
     10 // Import setupStore with imported & combined reducers
     11 const {
     12  setupStore,
     13 } = require("resource://devtools/client/application/test/node/helpers.js");
     14 
     15 const PageSwitcher = createFactory(
     16  require("resource://devtools/client/application/src/components/routing/PageSwitcher.js")
     17 );
     18 
     19 const {
     20  PAGE_TYPES,
     21 } = require("resource://devtools/client/application/src/constants.js");
     22 
     23 /**
     24 * Test for workerListEmpty.js component
     25 */
     26 
     27 describe("PageSwitcher", () => {
     28  function buildStoreWithSelectedPage(selectedPage) {
     29    return setupStore({
     30      ui: {
     31        selectedPage,
     32      },
     33    });
     34  }
     35 
     36  const consoleErrorSpy = jest
     37    .spyOn(console, "error")
     38    .mockImplementation(() => {});
     39 
     40  beforeEach(() => {
     41    console.error.mockClear();
     42  });
     43 
     44  afterAll(() => {
     45    consoleErrorSpy.mockRestore();
     46  });
     47 
     48  it("renders the ManifestPage component when manifest page is selected", () => {
     49    const store = buildStoreWithSelectedPage(PAGE_TYPES.MANIFEST);
     50    const wrapper = shallow(PageSwitcher({ store })).dive();
     51    expect(wrapper).toMatchSnapshot();
     52  });
     53 
     54  it("renders the WorkersPage component when workers page is selected", () => {
     55    const store = buildStoreWithSelectedPage(PAGE_TYPES.SERVICE_WORKERS);
     56    const wrapper = shallow(PageSwitcher({ store })).dive();
     57    expect(wrapper).toMatchSnapshot();
     58  });
     59 
     60  it("renders nothing when no page is selected", () => {
     61    const store = buildStoreWithSelectedPage(null);
     62    const wrapper = shallow(PageSwitcher({ store })).dive();
     63    expect(console.error).toHaveBeenCalledTimes(1);
     64    expect(wrapper).toMatchSnapshot();
     65  });
     66 
     67  it("renders nothing when an invalid page is selected", () => {
     68    const store = buildStoreWithSelectedPage("foo");
     69    const wrapper = shallow(PageSwitcher({ store })).dive();
     70    expect(console.error).toHaveBeenCalledTimes(1);
     71    expect(wrapper).toMatchSnapshot();
     72  });
     73 });