"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Mocks_1 = require("../../StateMachine/Mocks");
const LabelDropRepo_1 = require("../Entities/LabelDropRepo");
const SerializeLabelDrop_1 = require("./SerializeLabelDrop");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("LabelDrop");
    const stateMachine = (0, Mocks_1.makeMockStateMachine)(appObjects);
    const labelDrop = (0, LabelDropRepo_1.makeLabelDropRepo)(ao);
    const serializer = new SerializeLabelDrop_1.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