github.com/replicatedhq/ship@v0.55.0/web/init/src/redux/data/appRoutes/actions.spec.js (about)

     1  import thunk from "redux-thunk";
     2  import configureMockStore from "redux-mock-store";
     3  import { pollContentForStep, __RewireAPI__ as RewireAPI } from "./actions";
     4  
     5  jest.useFakeTimers();
     6  
     7  describe("appRoutes actions", () => {
     8    describe("pollContentForStep", () => {
     9      it("should poll until receiving status of success and invoke the provided cb", (done) => {
    10        const middlewares = [thunk];
    11        const mockStore = configureMockStore(middlewares);
    12        const store = mockStore({
    13          polling: false,
    14        });
    15  
    16        const mockFetchContentForStep = jest.fn();
    17        mockFetchContentForStep.mockImplementation(() => Promise.resolve({
    18          progress: {
    19            detail: JSON.stringify({
    20              status: "success",
    21            }),
    22          },
    23        }));
    24        RewireAPI.__set__("fetchContentForStep", mockFetchContentForStep);
    25  
    26        const mockCb = jest.fn().mockImplementation(() => done());
    27        expect(mockCb).not.toBeCalled();
    28  
    29        store.dispatch(pollContentForStep("someRandomId", mockCb));
    30        const expectedActions = [ { payload: true, type: "POLLING" } ];
    31        const actions = store.getActions();
    32        expect(actions).toEqual(expectedActions);
    33  
    34        jest.runOnlyPendingTimers();
    35        expect(mockFetchContentForStep).toBeCalled();
    36        expect(mockFetchContentForStep).toHaveBeenCalledTimes(1);
    37      });
    38    });
    39  });