Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/actions/__tests__/email-actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {
normalizeRenderErrors
} from "../email-actions";
import * as methods from "../../utils/methods";

jest.mock("../../history", () => ({ push: jest.fn() }));
import history from "../../history";

jest.mock("openstack-uicore-foundation/lib/utils/actions", () => ({
__esModule: true,
Expand All @@ -34,6 +33,11 @@ jest.mock("../marketing-actions", () => ({
saveMarketingSetting: jest.fn()
}));

jest.mock("../../history", () => ({
__esModule: true,
default: { push: jest.fn() }
}));

const requestMock =
(requestActionCreator, receiveActionCreator) => () => (dispatch) => {
if (requestActionCreator && typeof requestActionCreator === "function") {
Expand Down Expand Up @@ -85,6 +89,7 @@ describe("saveEmailTemplate", () => {
jest.spyOn(methods, "getAccessTokenSafely").mockResolvedValue("TOKEN");
postRequest.mockImplementation(requestMock);
putRequest.mockImplementation(requestMock);
history.push.mockClear();
});

afterEach(() => {
Expand Down Expand Up @@ -113,6 +118,14 @@ describe("saveEmailTemplate", () => {
actionTypes.indexOf("TEMPLATE_ADDED")
);
});

it("navigates to the new template's edit route using the server-assigned id", async () => {
const store = mockStore({});
store.dispatch(saveEmailTemplate({ identifier: "test-template" }));
await flushPromises();

expect(history.push).toHaveBeenCalledWith("/app/emails/templates/1");
});
});

describe("update path (entity has id)", () => {
Expand All @@ -137,6 +150,14 @@ describe("saveEmailTemplate", () => {
actionTypes.indexOf("TEMPLATE_UPDATED")
);
});

it("does not navigate away", async () => {
const store = mockStore({});
store.dispatch(saveEmailTemplate({ id: 1, identifier: "test-template" }));
await flushPromises();

expect(history.push).not.toHaveBeenCalled();
});
});
});

Expand Down
Loading
Loading