summaryrefslogtreecommitdiffstats
path: root/devtools/client/application/test/node/actions/actions_application_panel-manifest.test.js
blob: a8d4844f4ce758c619262627e0e467ceaf45a300 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const {
  MANIFEST_NO_ISSUES,
} = require("resource://devtools/client/application/test/node/fixtures/data/constants.js");

const {
  setupStore,
} = require("resource://devtools/client/application/test/node/helpers.js");

const {
  ManifestDevToolsError,
  services,
} = require("resource://devtools/client/application/src/modules/application-services.js");

const {
  FETCH_MANIFEST_FAILURE,
  FETCH_MANIFEST_START,
  FETCH_MANIFEST_SUCCESS,
} = require("resource://devtools/client/application/src/constants.js");

const {
  fetchManifest,
} = require("resource://devtools/client/application/src/actions/manifest.js");

describe("Manifest actions: fetchManifest", () => {
  it("dispatches a START - SUCCESS sequence when fetching is OK", async () => {
    const fetchManifestSpy = jest
      .spyOn(services, "fetchManifest")
      .mockResolvedValue(MANIFEST_NO_ISSUES);

    const store = setupStore({});
    await store.dispatch(fetchManifest());

    expect(store.getActions()).toEqual([
      { type: FETCH_MANIFEST_START },
      { type: FETCH_MANIFEST_SUCCESS, manifest: MANIFEST_NO_ISSUES },
    ]);

    fetchManifestSpy.mockRestore();
  });

  it("dispatches a START - FAILURE sequence when fetching fails", async () => {
    const fetchManifestSpy = jest
      .spyOn(services, "fetchManifest")
      .mockRejectedValue(new Error("lorem ipsum"));

    const store = setupStore({});
    await store.dispatch(fetchManifest());

    expect(store.getActions()).toEqual([
      { type: FETCH_MANIFEST_START },
      { type: FETCH_MANIFEST_FAILURE, error: "lorem ipsum" },
    ]);

    fetchManifestSpy.mockRestore();
  });

  it("dispatches a START - FAILURE sequence when fetching fails due to a devtools error", async () => {
    const error = new ManifestDevToolsError(":(");
    const fetchManifestSpy = jest
      .spyOn(services, "fetchManifest")
      .mockRejectedValue(error);
    const consoleErrorSpy = jest
      .spyOn(console, "error")
      .mockImplementation(() => {});

    const store = setupStore({});
    await store.dispatch(fetchManifest());

    expect(store.getActions()).toEqual([
      { type: FETCH_MANIFEST_START },
      { type: FETCH_MANIFEST_FAILURE, error: "manifest-loaded-devtools-error" },
    ]);
    expect(consoleErrorSpy).toHaveBeenCalledWith(error);

    fetchManifestSpy.mockRestore();
    consoleErrorSpy.mockRestore();
  });
});