import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { makeUndoRedoEntity } from "../../UndoRedo";
import { Environments, makeEnvironmentEntity } from "../Entities/Environment";
import { makeSetEnvironmentIntensityUC, SetEnvironmentIntensityUC, } from "./SetEnvironmentIntensityUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const mockDispatchStateChange = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatchStateChange.doDispatch = doDispatchMock;
    const environment = makeEnvironmentEntity(appObjects.getOrCreate("Env"));
    environment.currentEnvironment = Environments.FOREST;
    const undo = makeUndoRedoEntity(appObjects.getOrCreate("Undo"));
    const uc = makeSetEnvironmentIntensityUC(appObjects.getOrCreate("UC"));
    return {
        uc,
        environment,
        doDispatchMock,
        undo,
        appObjects,
        registerSpy,
    };
}
describe("Test Set Textural Environment", () => {
    it("Get it UC", () => {
        const { appObjects, uc } = makeTestRig();
        expect(SetEnvironmentIntensityUC.get(appObjects)).toEqual(uc);
    });
    it("Registers as the singleton", () => {
        const { uc, registerSpy } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(uc);
    });
    it("Sets the intensity", () => {
        const { uc, environment } = makeTestRig();
        expect(environment.intensity).toEqual(0.75);
        uc.update(1);
        expect(environment.intensity).toEqual(1);
    });
    it("Dispatches a state change on submit if there is a change", () => {
        const { uc, doDispatchMock } = makeTestRig();
        uc.update(1);
        uc.submit();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
    });
    it("Registers an undo if there is a change", () => {
        const { uc, undo } = makeTestRig();
        undo.submitAction = jest.fn();
        uc.update(1);
        uc.submit();
        expect(undo.submitAction).toHaveBeenCalledTimes(1);
    });
    it("Does not dispatche a state change on submit if there is a change", () => {
        const { uc, doDispatchMock } = makeTestRig();
        uc.update(0.75);
        uc.submit();
        expect(doDispatchMock).toHaveBeenCalledTimes(0);
    });
    it("Does not register an undo if there is a change", () => {
        const { uc, undo } = makeTestRig();
        undo.submitAction = jest.fn();
        uc.update(0.75);
        uc.submit();
        expect(undo.submitAction).toHaveBeenCalledTimes(0);
    });
    it("Can undo and redo the change", () => {
        const { uc, undo, doDispatchMock, environment } = makeTestRig();
        expect(environment.intensity).toEqual(0.75);
        uc.update(1);
        uc.submit();
        expect(environment.intensity).toEqual(1);
        doDispatchMock.mockClear();
        undo.doUndo();
        expect(environment.intensity).toEqual(0.75);
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        undo.doRedo();
        expect(environment.intensity).toEqual(1);
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=SetEnvironmentIntensityUC.test.js.map