"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const SerializeAllowHoverLabel_1 = require("./SerializeAllowHoverLabel");
const HoverLabelEntity_1 = require("../Entities/HoverLabelEntity");
const core_1 = require("@vived/core");
const StateMachine_1 = require("../../StateMachine");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObject = appObjects.getOrCreate("AppObject");
    const hoverLabel = (0, HoverLabelEntity_1.makeHoverLabelEntity)(appObject);
    const stateMachineAo = appObjects.getOrCreate("stateMachine");
    const stateMachine = (0, StateMachine_1.makeStateMachineEntity)(stateMachineAo);
    const mockRegister = jest.fn();
    stateMachine.registerSerializedSystem = mockRegister;
    const serializer = new SerializeAllowHoverLabel_1.SerializeAllowHoverLabel(appObject);
    return { hoverLabel, stateMachine, mockRegister, serializer };
}
describe("Serialize Allow Hover Label", () => {
    it("Registers with the state machine", () => {
        const { mockRegister } = makeTestRig();
        expect(mockRegister).toHaveBeenCalled();
    });
    it("Forms the state as expected", () => {
        const { serializer, hoverLabel } = makeTestRig();
        hoverLabel.allowHoverLabel = false;
        const stateObj1 = serializer.getSystemState();
        expect(stateObj1.allow).toEqual(false);
        hoverLabel.allowHoverLabel = true;
        const stateObj2 = serializer.getSystemState();
        expect(stateObj2.allow).toEqual(true);
    });
    it("Applies v1 data as expected", () => {
        const { serializer, hoverLabel } = makeTestRig();
        hoverLabel.allowHoverLabel = true;
        const data1 = {
            allow: false,
        };
        serializer.applySystemState(data1, 1);
        expect(hoverLabel.allowHoverLabel).toEqual(false);
        const data2 = {
            allow: true,
        };
        serializer.applySystemState(data2, 1);
        expect(hoverLabel.allowHoverLabel).toEqual(true);
    });
    it("Warns and then apply default if an unsupported version is passed in", () => {
        const { serializer } = makeTestRig();
        const mockApplyDefault = jest.fn();
        serializer.applyDefaultState = mockApplyDefault;
        console.warn = jest.fn();
        serializer.applySystemState({ foo: "bar" }, -1);
        expect(mockApplyDefault).toHaveBeenCalled();
        expect(console.warn).toHaveBeenCalled();
    });
    it("Applies a default state", () => {
        const { serializer, hoverLabel } = makeTestRig();
        hoverLabel.allowHoverLabel = false;
        serializer.applyDefaultState();
        expect(hoverLabel.allowHoverLabel).toEqual(true);
    });
});
//# sourceMappingURL=SerializeAllowHoverLabel.test.js.map