"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const StateMachine_1 = require("../../StateMachine");
const Environment_1 = require("../Entities/Environment");
const SerializeEnvironment_1 = require("./SerializeEnvironment");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const app = appObjects.getOrCreate("app");
    const stateMachine = new StateMachine_1.MockStateMachine(app);
    const environment = (0, Environment_1.makeEnvironmentEntity)(appObjects.getOrCreate("Environment"));
    const serializer = new SerializeEnvironment_1.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 = Environment_1.Environments.PARKING;
        environment.intensity = 0.555;
        const state = serializer.getSystemState();
        expect(state.environment).toEqual(Environment_1.Environments.PARKING);
        expect(state.intensity).toEqual(0.555);
    });
    it("Applies the state 1 correctly", () => {
        const { serializer, environment } = makeTestRig();
        const state = {
            environment: Environment_1.Environments.ROOM,
        };
        environment.currentEnvironment = Environment_1.Environments.STUDIO;
        environment.intensity = 0.5;
        serializer.applySystemState(state, 1);
        expect(environment.currentEnvironment).toEqual(Environment_1.Environments.ROOM);
        expect(environment.intensity).toEqual(serializer.defaultState.intensity);
    });
    it("Applies the state 2 correctly", () => {
        const { serializer, environment } = makeTestRig();
        const state = {
            environment: Environment_1.Environments.ROOM,
            intensity: 0.999,
        };
        environment.currentEnvironment = Environment_1.Environments.STUDIO;
        environment.intensity = 0.5;
        serializer.applySystemState(state, 2);
        expect(environment.currentEnvironment).toEqual(Environment_1.Environments.ROOM);
        expect(environment.intensity).toEqual(0.999);
    });
    it("Sets the default state as expected", () => {
        const { serializer, environment } = makeTestRig();
        environment.currentEnvironment = Environment_1.Environments.ROOM;
        environment.intensity = 0.999;
        serializer.applyDefaultState();
        expect(environment.currentEnvironment).toEqual(Environment_1.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