"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const AppDispatcher_1 = require("../Entities/AppDispatcher");
const DispatchStartZSpaceUC_1 = require("./DispatchStartZSpaceUC");
class MockDispatcher extends AppDispatcher_1.AppDispatcher {
    constructor() {
        super(...arguments);
        this.dispatch = jest.fn();
        this.formRequestAndDispatch = jest.fn();
    }
}
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const dispatcher = appObjects.getOrCreate("Dispatcher");
    const mockDispatcher = new MockDispatcher(dispatcher, AppDispatcher_1.AppDispatcher.type);
    const uc = (0, DispatchStartZSpaceUC_1.makeDispatchStartZSpaceUC)(dispatcher);
    return { uc, dispatcher, appObjects, mockDispatcher };
}
describe("Dispatch State Change", () => {
    it("Gets the UC", () => {
        const { uc, appObjects } = makeTestRig();
        expect(DispatchStartZSpaceUC_1.DispatchStartZSpaceUC.get(appObjects)).toEqual(uc);
    });
    it("Warns and returns undefined if there is no repo", () => {
        const { uc, appObjects } = makeTestRig();
        uc.appObject.dispose();
        console.warn = jest.fn();
        expect(DispatchStartZSpaceUC_1.DispatchStartZSpaceUC.get(appObjects)).toBeUndefined();
        expect(console.warn).toHaveBeenCalled();
    });
    it("Warns if there are more than two repos found", () => {
        const { appObjects } = makeTestRig();
        const newAO = appObjects.getOrCreate("newAO");
        new MockDispatcher(newAO, AppDispatcher_1.AppDispatcher.type);
        (0, DispatchStartZSpaceUC_1.makeDispatchStartZSpaceUC)(newAO);
        console.warn = jest.fn();
        expect(DispatchStartZSpaceUC_1.DispatchStartZSpaceUC.get(appObjects)).not.toBeUndefined();
        expect(console.warn).toHaveBeenCalled();
    });
    it("Dispatches the correct type", () => {
        const { uc, mockDispatcher } = makeTestRig();
        uc.doDispatch();
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        expect(mockDispatcher.formRequestAndDispatch.mock.calls[0][0]).toEqual(uc.requestType);
    });
    it("Dispatches the correct version", () => {
        const { uc, mockDispatcher } = makeTestRig();
        uc.doDispatch();
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        expect(mockDispatcher.formRequestAndDispatch.mock.calls[0][1]).toEqual(1);
    });
    it("Dispatches an undefined payload", () => {
        const { uc, mockDispatcher } = makeTestRig();
        uc.doDispatch();
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        const payload = mockDispatcher.formRequestAndDispatch.mock.calls[0][2];
        expect(payload).toBeUndefined();
    });
});
//# sourceMappingURL=DispatchStartZSpaceUC.test.js.map