import { makeAppObjectRepo } from "@vived/core";
import { makeMockStateMachine } from "../../StateMachine/Mocks";
import { makeLabelDropRepo } from "../Entities/LabelDropRepo";
import { SerializeLabelDrop, } from "./SerializeLabelDrop";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ao = appObjects.getOrCreate("LabelDrop");
    const stateMachine = makeMockStateMachine(appObjects);
    const labelDrop = makeLabelDropRepo(ao);
    const serializer = new SerializeLabelDrop(ao);
    const labelDrop1 = {
        id: "id1",
        label: "label 1",
        correctAppObjectIDs: ["obj1"],
    };
    return { serializer, labelDrop, stateMachine, labelDrop1 };
}
describe("Serialize App State UC", () => {
    it("Registers with the state machine", () => {
        const { serializer, stateMachine } = makeTestRig();
        expect(stateMachine.registerSerializedSystem).toHaveBeenCalledWith(serializer);
    });
    it("Applies the state correctly", () => {
        const { serializer, labelDrop, labelDrop1 } = makeTestRig();
        const state = {
            labelDrops: [labelDrop1],
        };
        labelDrop.deleteAllItems();
        serializer.applySystemState(state, 1);
        const dropItems = labelDrop.getAll();
        expect(dropItems.length).toEqual(1);
        expect(dropItems[0].id).toEqual("id1");
        expect(dropItems[0].labelEntity.custom).toEqual("label 1");
        expect(dropItems[0].targetIds).toEqual(["obj1"]);
    });
    it("Sets the default state", () => {
        const { serializer, labelDrop } = makeTestRig();
        labelDrop.makeLabelDropItem("someDrop");
        serializer.applyDefaultState();
        expect(labelDrop.getAll().length).toEqual(0);
    });
    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("Serializes the state as expected", () => {
        const { serializer, labelDrop } = makeTestRig();
        const dropItem = labelDrop.makeLabelDropItem("id1");
        dropItem.labelEntity.custom = "Hello World";
        dropItem.targetIds = ["obj1"];
        const state = serializer.getSystemState();
        const labelDrops = state.labelDrops;
        expect(labelDrops.length).toEqual(1);
        expect(labelDrops[0].id).toEqual("id1");
        expect(labelDrops[0].label).toEqual("Hello World");
        expect(labelDrops[0].correctAppObjectIDs).toEqual(["obj1"]);
    });
    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=SerializeLabelDrop.test.js.map