mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-23 02:05:42 +00:00
Bug 1579795 - Part 3: Test the fetchManifest action separately r=jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D49596 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
de84d86c5f
commit
04e8ccaf1c
@ -0,0 +1,81 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
MANIFEST_NO_ISSUES,
|
||||
} = require("devtools/client/application/test/jest/fixtures/data/constants");
|
||||
|
||||
const { setupStore } = require("devtools/client/application/test/jest/helpers");
|
||||
|
||||
const {
|
||||
ManifestDevToolsError,
|
||||
services,
|
||||
} = require("devtools/client/application/src/modules/services");
|
||||
|
||||
const {
|
||||
FETCH_MANIFEST_FAILURE,
|
||||
FETCH_MANIFEST_START,
|
||||
FETCH_MANIFEST_SUCCESS,
|
||||
} = require("devtools/client/application/src/constants");
|
||||
|
||||
const {
|
||||
fetchManifest,
|
||||
} = require("devtools/client/application/src/actions/manifest");
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
@ -7,35 +7,21 @@
|
||||
const { shallow } = require("enzyme");
|
||||
const { createFactory } = require("react");
|
||||
// Import test helpers
|
||||
const {
|
||||
flushPromises,
|
||||
setupStore,
|
||||
} = require("devtools/client/application/test/jest/helpers");
|
||||
const { setupStore } = require("devtools/client/application/test/jest/helpers");
|
||||
// Import fixtures
|
||||
const {
|
||||
MANIFEST_NO_ISSUES,
|
||||
} = require("devtools/client/application/test/jest/fixtures/data/constants");
|
||||
|
||||
// Import app modules
|
||||
const {
|
||||
ManifestDevToolsError,
|
||||
services,
|
||||
} = require("devtools/client/application/src/modules/services");
|
||||
|
||||
const {
|
||||
FETCH_MANIFEST_FAILURE,
|
||||
FETCH_MANIFEST_START,
|
||||
FETCH_MANIFEST_SUCCESS,
|
||||
} = require("devtools/client/application/src/constants");
|
||||
const manifestActions = require("devtools/client/application/src/actions/manifest");
|
||||
// NOTE: we need to spy on the action before we load the component, so it gets
|
||||
// bound to the spy, not the original implementation
|
||||
const fetchManifestActionSpy = jest.spyOn(manifestActions, "fetchManifest");
|
||||
|
||||
const ManifestLoader = createFactory(
|
||||
require("devtools/client/application/src/components/manifest/ManifestLoader")
|
||||
);
|
||||
|
||||
/**
|
||||
* Test for ManifestPage.js component
|
||||
*/
|
||||
|
||||
describe("ManifestLoader", () => {
|
||||
function buildStore({ manifest, errorMessage, isLoading }) {
|
||||
const manifestState = Object.assign(
|
||||
@ -50,64 +36,19 @@ describe("ManifestLoader", () => {
|
||||
return setupStore({ manifest: manifestState });
|
||||
}
|
||||
|
||||
it("loads a manifest when mounted and triggers actions when loading is OK", async () => {
|
||||
const fetchManifestSpy = jest
|
||||
.spyOn(services, "fetchManifest")
|
||||
.mockResolvedValue(MANIFEST_NO_ISSUES);
|
||||
|
||||
const store = buildStore({});
|
||||
|
||||
shallow(ManifestLoader({ store })).dive();
|
||||
await flushPromises();
|
||||
|
||||
expect(store.getActions()).toEqual([
|
||||
{ type: FETCH_MANIFEST_START },
|
||||
{ type: FETCH_MANIFEST_SUCCESS, manifest: MANIFEST_NO_ISSUES },
|
||||
]);
|
||||
|
||||
fetchManifestSpy.mockRestore();
|
||||
afterAll(() => {
|
||||
fetchManifestActionSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("loads a manifest when mounted and triggers actions when loading fails", async () => {
|
||||
const fetchManifestSpy = jest
|
||||
.spyOn(services, "fetchManifest")
|
||||
.mockRejectedValue(new Error("lorem ipsum"));
|
||||
it("loads a manifest when mounted", async () => {
|
||||
fetchManifestActionSpy.mockReturnValue({ type: "foo" });
|
||||
|
||||
const store = buildStore({});
|
||||
|
||||
shallow(ManifestLoader({ store })).dive();
|
||||
await flushPromises();
|
||||
|
||||
expect(store.getActions()).toEqual([
|
||||
{ type: FETCH_MANIFEST_START },
|
||||
{ type: FETCH_MANIFEST_FAILURE, error: "lorem ipsum" },
|
||||
]);
|
||||
|
||||
fetchManifestSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("loads a manifest when mounted and triggers actions when loading fails due to devtools", async () => {
|
||||
const error = new ManifestDevToolsError(":(");
|
||||
const fetchManifestSpy = jest
|
||||
.spyOn(services, "fetchManifest")
|
||||
.mockRejectedValue(error);
|
||||
const consoleErrorSpy = jest
|
||||
.spyOn(console, "error")
|
||||
.mockImplementation(() => {});
|
||||
|
||||
const store = buildStore({});
|
||||
|
||||
shallow(ManifestLoader({ store })).dive();
|
||||
await flushPromises();
|
||||
|
||||
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();
|
||||
expect(manifestActions.fetchManifest).toHaveBeenCalled();
|
||||
fetchManifestActionSpy.mockReset();
|
||||
});
|
||||
|
||||
it("renders a message when it is loading", async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user