import { SerializeAllowHoverLabel, } from "./SerializeAllowHoverLabel";
import { makeHoverLabelEntity } from "../Entities/HoverLabelEntity";
import { makeAppObjectRepo } from "@vived/core";
import { makeStateMachineEntity } from "../../StateMachine";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appObject = appObjects.getOrCreate("AppObject");
    const hoverLabel = makeHoverLabelEntity(appObject);
    const stateMachineAo = appObjects.getOrCreate("stateMachine");
    const stateMachine = makeStateMachineEntity(stateMachineAo);
    const mockRegister = jest.fn();
    stateMachine.registerSerializedSystem = mockRegister;
    const serializer = new 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