tor-browser

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

actions_application_panel-manifest.test.js (2504B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const {
      7  MANIFEST_NO_ISSUES,
      8 } = require("resource://devtools/client/application/test/node/fixtures/data/constants.js");
      9 
     10 const {
     11  setupStore,
     12 } = require("resource://devtools/client/application/test/node/helpers.js");
     13 
     14 const {
     15  ManifestDevToolsError,
     16  services,
     17 } = require("resource://devtools/client/application/src/modules/application-services.js");
     18 
     19 const {
     20  FETCH_MANIFEST_FAILURE,
     21  FETCH_MANIFEST_START,
     22  FETCH_MANIFEST_SUCCESS,
     23 } = require("resource://devtools/client/application/src/constants.js");
     24 
     25 const {
     26  fetchManifest,
     27 } = require("resource://devtools/client/application/src/actions/manifest.js");
     28 
     29 describe("Manifest actions: fetchManifest", () => {
     30  it("dispatches a START - SUCCESS sequence when fetching is OK", async () => {
     31    const fetchManifestSpy = jest
     32      .spyOn(services, "fetchManifest")
     33      .mockResolvedValue(MANIFEST_NO_ISSUES);
     34 
     35    const store = setupStore({});
     36    await store.dispatch(fetchManifest());
     37 
     38    expect(store.getActions()).toEqual([
     39      { type: FETCH_MANIFEST_START },
     40      { type: FETCH_MANIFEST_SUCCESS, manifest: MANIFEST_NO_ISSUES },
     41    ]);
     42 
     43    fetchManifestSpy.mockRestore();
     44  });
     45 
     46  it("dispatches a START - FAILURE sequence when fetching fails", async () => {
     47    const fetchManifestSpy = jest
     48      .spyOn(services, "fetchManifest")
     49      .mockRejectedValue(new Error("lorem ipsum"));
     50 
     51    const store = setupStore({});
     52    await store.dispatch(fetchManifest());
     53 
     54    expect(store.getActions()).toEqual([
     55      { type: FETCH_MANIFEST_START },
     56      { type: FETCH_MANIFEST_FAILURE, error: "lorem ipsum" },
     57    ]);
     58 
     59    fetchManifestSpy.mockRestore();
     60  });
     61 
     62  it("dispatches a START - FAILURE sequence when fetching fails due to a devtools error", async () => {
     63    const error = new ManifestDevToolsError(":(");
     64    const fetchManifestSpy = jest
     65      .spyOn(services, "fetchManifest")
     66      .mockRejectedValue(error);
     67    const consoleErrorSpy = jest
     68      .spyOn(console, "error")
     69      .mockImplementation(() => {});
     70 
     71    const store = setupStore({});
     72    await store.dispatch(fetchManifest());
     73 
     74    expect(store.getActions()).toEqual([
     75      { type: FETCH_MANIFEST_START },
     76      { type: FETCH_MANIFEST_FAILURE, error: "manifest-loaded-devtools-error" },
     77    ]);
     78    expect(consoleErrorSpy).toHaveBeenCalledWith(error);
     79 
     80    fetchManifestSpy.mockRestore();
     81    consoleErrorSpy.mockRestore();
     82  });
     83 });