tor-browser

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

components_application_panel-ManifestLoader.test.js (2476B)


      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 // Import test helpers
     10 const {
     11  setupStore,
     12 } = require("resource://devtools/client/application/test/node/helpers.js");
     13 // Import fixtures
     14 const {
     15  MANIFEST_NO_ISSUES,
     16 } = require("resource://devtools/client/application/test/node/fixtures/data/constants.js");
     17 
     18 const manifestActions = require("resource://devtools/client/application/src/actions/manifest.js");
     19 // NOTE: we need to spy on the action before we load the component, so it gets
     20 //       bound to the spy, not the original implementation
     21 const fetchManifestActionSpy = jest.spyOn(manifestActions, "fetchManifest");
     22 
     23 const ManifestLoader = createFactory(
     24  require("resource://devtools/client/application/src/components/manifest/ManifestLoader.js")
     25 );
     26 
     27 describe("ManifestLoader", () => {
     28  function buildStore({ manifest, errorMessage, isLoading }) {
     29    const manifestState = Object.assign(
     30      {
     31        manifest: null,
     32        errorMessage: "",
     33        isLoading: false,
     34      },
     35      { manifest, errorMessage, isLoading }
     36    );
     37 
     38    return setupStore({ manifest: manifestState });
     39  }
     40 
     41  afterAll(() => {
     42    fetchManifestActionSpy.mockRestore();
     43  });
     44 
     45  it("loads a manifest when mounted", async () => {
     46    fetchManifestActionSpy.mockReturnValue({ type: "foo" });
     47 
     48    const store = buildStore({});
     49 
     50    shallow(ManifestLoader({ store })).dive();
     51 
     52    expect(manifestActions.fetchManifest).toHaveBeenCalled();
     53    fetchManifestActionSpy.mockReset();
     54  });
     55 
     56  it("renders a message when it is loading", async () => {
     57    const store = buildStore({ isLoading: true });
     58    const wrapper = shallow(ManifestLoader({ store })).dive();
     59    expect(wrapper).toMatchSnapshot();
     60  });
     61 
     62  it("renders a message when manifest has loaded OK", async () => {
     63    const store = buildStore({
     64      isLoading: false,
     65      manifest: MANIFEST_NO_ISSUES,
     66      errorMessage: "",
     67    });
     68    const wrapper = shallow(ManifestLoader({ store })).dive();
     69    expect(wrapper).toMatchSnapshot();
     70  });
     71 
     72  it("renders a message when manifest has failed to load", async () => {
     73    const store = buildStore({
     74      manifest: null,
     75      isLoading: false,
     76      errorMessage: "lorem ipsum",
     77    });
     78    const wrapper = shallow(ManifestLoader({ store })).dive();
     79 
     80    expect(wrapper).toMatchSnapshot();
     81  });
     82 });