github.com/replicatedhq/ship@v0.55.0/web/init/src/components/shared/DetermineComponentForRoute.spec.js (about) 1 import React from "react"; 2 import { shallow } from "enzyme"; 3 import { DetermineComponentForRoute, __RewireAPI__ as RewireAPI } from "./DetermineComponentForRoute"; 4 5 jest.mock("./DiffEditor"); 6 jest.mock("../kustomize/kustomize_overlay/AceEditorHOC"); 7 8 const mockPollContentForStep = jest.fn(); 9 const mockKustomizeIntroProps = { 10 apiEndpoint: "https://ship-api.com", 11 phase: "kustomize-intro", 12 dataLoading: {}, 13 actions: ["mockKustomizeIntroAction"], 14 getContentForStep: jest.fn(), 15 routes: [ 16 { 17 phase: "kustomize", 18 id: "mockKustomizeId", 19 }, 20 { 21 phase: "kustomize-intro", 22 id: "mockKustomizeIntroId", 23 }, 24 ], 25 finalizeStep: jest.fn(), 26 pollContentForStep: mockPollContentForStep, 27 history: { 28 goBack: jest.fn() 29 }, 30 currentRoute: { 31 id: "mockKustomizeIntroId", 32 }, 33 }; 34 35 describe("DetermineComponentForRoute", () => { 36 describe("skipKustomize", () => { 37 it("completes kustomize step and polls for the outro", async() => { 38 const mockHandleAction = jest.fn(); 39 40 const mockFetchContentForStep = jest.fn(); 41 mockFetchContentForStep.mockImplementation(() => ({ 42 actions: ["mockKustomizeAction"], 43 })); 44 RewireAPI.__set__("fetchContentForStep", mockFetchContentForStep); 45 46 const wrapper = shallow( 47 <DetermineComponentForRoute 48 {...mockKustomizeIntroProps} 49 fetchContentForStep={mockFetchContentForStep} 50 /> 51 ); 52 wrapper.instance().handleAction = mockHandleAction; 53 wrapper.update(); 54 55 await wrapper.instance().skipKustomize(); 56 57 expect(mockFetchContentForStep.mock.calls).toHaveLength(1); 58 expect(mockFetchContentForStep.mock.calls[0]).toEqual(["https://ship-api.com", "kustomize"]); 59 60 expect(mockPollContentForStep).toHaveBeenCalled(); 61 expect(mockPollContentForStep.mock.calls[0][0]).toEqual("kustomize"); 62 }); 63 }); 64 });