"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const AppDispatcher_1 = require("../Entities/AppDispatcher");
const StateHasChangedUC_1 = require("./StateHasChangedUC");
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, StateHasChangedUC_1.makeStateHasChangedUC)(dispatcher);
    return { uc, dispatcher, appObjects, mockDispatcher };
}
describe("Dispatch StateHasChangedUC", () => {
    it("Gets the UC", () => {
        const { uc, appObjects } = makeTestRig();
        expect(StateHasChangedUC_1.StateHasChangedUC.get(appObjects)).toEqual(uc);
    });
    it("Dispatches the correct type", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        uc.stateHasChanged({ foo: "bar" }, ["model1"], "validation message");
        expect(spy).toHaveBeenCalledTimes(1);
        expect(spy.mock.calls[0][0]).toEqual("ON_STATE_CHANGE");
    });
    it("Dispatches the correct version", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        uc.stateHasChanged({ foo: "bar" }, ["model1"], "validation message");
        expect(spy).toHaveBeenCalledTimes(1);
        expect(spy.mock.calls[0][1]).toEqual(3);
    });
    it("Dispatches the correct payload", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        uc.stateHasChanged({ foo: "bar" }, ["model1"], "validation message");
        expect(spy).toHaveBeenCalledTimes(1);
        const payload = spy.mock.calls[0][2];
        expect(payload.stateObject).toEqual({ foo: "bar" });
        expect(payload.assets).toEqual(["model1"]);
        expect(payload.validationErrorMessage).toEqual("validation message");
    });
});
//# sourceMappingURL=StateHasChangedUC.test.js.map