import { makeAppObjectRepo } from "@vived/core";
import { AppDispatcher } from "../Entities/AppDispatcher";
import { DispatchStopZSpaceUC, makeDispatchStopZSpaceUC, } from "./DispatchStopZSpaceUC";
class MockDispatcher extends AppDispatcher {
    constructor() {
        super(...arguments);
        this.dispatch = jest.fn();
        this.formRequestAndDispatch = jest.fn();
    }
}
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const dispatcher = appObjects.getOrCreate("Dispatcher");
    const mockDispatcher = new MockDispatcher(dispatcher, AppDispatcher.type);
    const uc = makeDispatchStopZSpaceUC(dispatcher);
    return { uc, dispatcher, appObjects, mockDispatcher };
}
describe("Dispatch State Change", () => {
    it("Gets the UC", () => {
        const { uc, appObjects } = makeTestRig();
        expect(DispatchStopZSpaceUC.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(DispatchStopZSpaceUC.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.type);
        makeDispatchStopZSpaceUC(newAO);
        console.warn = jest.fn();
        expect(DispatchStopZSpaceUC.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=DispatchStopZSpaceUC.test.js.map