"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const UndoRedo_1 = require("../../UndoRedo");
const Environment_1 = require("../Entities/Environment");
const SetTexturalEnvironmentUC_1 = require("./SetTexturalEnvironmentUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const mockDispatchStateChange = (0, Dispatcher_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatchStateChange.doDispatch = doDispatchMock;
    const environment = (0, Environment_1.makeEnvironmentEntity)(appObjects.getOrCreate("Env"));
    environment.currentEnvironment = Environment_1.Environments.FOREST;
    const undo = (0, UndoRedo_1.makeUndoRedoEntity)(appObjects.getOrCreate("Undo"));
    const uc = (0, SetTexturalEnvironmentUC_1.makeSetTexturalEnvironmentUC)(appObjects.getOrCreate("UC"));
    return {
        uc,
        environment,
        doDispatchMock,
        undo,
        appObjects,
        registerSpy,
    };
}
describe("Test Set Textural Environment", () => {
    it("Get it UC", () => {
        const { appObjects, uc } = makeTestRig();
        expect(SetTexturalEnvironmentUC_1.SetTexturalEnvironmentUC.get(appObjects)).toEqual(uc);
    });
    it("Registers as the singleton", () => {
        const { uc, registerSpy } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(uc);
    });
    it("Sets textural environment for existing environment", () => {
        const { uc, environment } = makeTestRig();
        uc.setEnvironment(Environment_1.Environments.NIGHT);
        expect(environment.currentEnvironment).toEqual(Environment_1.Environments.NIGHT);
    });
    it("Dispatches a state change if there is a change", () => {
        const { uc, doDispatchMock } = makeTestRig();
        uc.setEnvironment(Environment_1.Environments.NIGHT);
        uc.setEnvironment(Environment_1.Environments.NIGHT);
        uc.setEnvironment(Environment_1.Environments.NIGHT);
        uc.setEnvironment(Environment_1.Environments.NIGHT);
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
    });
    it("Registers an undo if there is a change", () => {
        const { uc, undo } = makeTestRig();
        undo.submitAction = jest.fn();
        uc.setEnvironment(Environment_1.Environments.NIGHT);
        uc.setEnvironment(Environment_1.Environments.NIGHT);
        uc.setEnvironment(Environment_1.Environments.NIGHT);
        uc.setEnvironment(Environment_1.Environments.NIGHT);
        expect(undo.submitAction).toHaveBeenCalledTimes(1);
    });
    it("Can undo and redo the change", () => {
        const { uc, undo, doDispatchMock, environment } = makeTestRig();
        expect(environment.currentEnvironment).toEqual(Environment_1.Environments.FOREST);
        uc.setEnvironment(Environment_1.Environments.NIGHT);
        expect(environment.currentEnvironment).toEqual(Environment_1.Environments.NIGHT);
        doDispatchMock.mockClear();
        undo.doUndo();
        expect(environment.currentEnvironment).toEqual(Environment_1.Environments.FOREST);
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        undo.doRedo();
        expect(environment.currentEnvironment).toEqual(Environment_1.Environments.NIGHT);
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=SetTexturalEnvironmentUC.test.js.map