import { makeAppObjectRepo } from "@vived/core";
import { MockStateMachine } from "../../StateMachine";
import { Environments, makeEnvironmentEntity } from "../Entities/Environment";
import { SerializeEnvironment, } from "./SerializeEnvironment";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const app = appObjects.getOrCreate("app");
    const stateMachine = new MockStateMachine(app);
    const environment = makeEnvironmentEntity(appObjects.getOrCreate("Environment"));
    const serializer = new SerializeEnvironment(app);
    return { serializer, stateMachine, environment };
}
describe("Serialize Environment UC", () => {
    it("Registers with the Serialized System on construction", () => {
        const { serializer, stateMachine } = makeTestRig();
        expect(stateMachine.registerSerializedSystem).toHaveBeenCalledWith(serializer);
    });
    it("Forms the expected state", () => {
        const { serializer, environment } = makeTestRig();
        environment.currentEnvironment = Environments.PARKING;
        environment.intensity = 0.555;
        const state = serializer.getSystemState();
        expect(state.environment).toEqual(Environments.PARKING);
        expect(state.intensity).toEqual(0.555);
    });
    it("Applies the state 1 correctly", () => {
        const { serializer, environment } = makeTestRig();
        const state = {
            environment: Environments.ROOM,
        };
        environment.currentEnvironment = Environments.STUDIO;
        environment.intensity = 0.5;
        serializer.applySystemState(state, 1);
        expect(environment.currentEnvironment).toEqual(Environments.ROOM);
        expect(environment.intensity).toEqual(serializer.defaultState.intensity);
    });
    it("Applies the state 2 correctly", () => {
        const { serializer, environment } = makeTestRig();
        const state = {
            environment: Environments.ROOM,
            intensity: 0.999,
        };
        environment.currentEnvironment = Environments.STUDIO;
        environment.intensity = 0.5;
        serializer.applySystemState(state, 2);
        expect(environment.currentEnvironment).toEqual(Environments.ROOM);
        expect(environment.intensity).toEqual(0.999);
    });
    it("Sets the default state as expected", () => {
        const { serializer, environment } = makeTestRig();
        environment.currentEnvironment = Environments.ROOM;
        environment.intensity = 0.999;
        serializer.applyDefaultState();
        expect(environment.currentEnvironment).toEqual(Environments.STUDIO);
        expect(environment.intensity).toEqual(serializer.defaultState.intensity);
    });
    it("Applies the default state if an unsupported version is passed in", () => {
        const { serializer } = makeTestRig();
        serializer.applyDefaultState = jest.fn();
        serializer.applySystemState({ foo: "bar" }, -1);
        expect(serializer.applyDefaultState).toHaveBeenCalled();
    });
    it("Applies the default state if the state is bungled", () => {
        const { serializer } = makeTestRig();
        serializer.applyDefaultState = jest.fn();
        serializer.applySystemState({ foo: "bar" }, 1);
        expect(serializer.applyDefaultState).toHaveBeenCalled();
    });
});
//# sourceMappingURL=SerializeEnvironment.test.js.map