import { makeAppObjectRepo } from "@vived/core";
import { MockStateMachine } from "../../StateMachine/Mocks/MockStateMachine";
import { makeObjectPickEntity } from "../Entities/ObjectPickEntity";
import { SerializeObjectPick, } from "./SerializeObjectPick";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const app = appObjects.getOrCreate("app");
    const objectPick = makeObjectPickEntity(appObjects.getOrCreate("ObjectPick"));
    const stateMachine = new MockStateMachine(app);
    const serializer = new SerializeObjectPick(appObjects.getOrCreate("ObjectPick"));
    return { serializer, objectPick, stateMachine };
}
describe("Serialize Object Pick", () => {
    it("Registers with the Serialized System on construction", () => {
        const { serializer, stateMachine } = makeTestRig();
        expect(stateMachine.registerSerializedSystem).toHaveBeenCalledWith(serializer);
    });
    it("Applies the state correctly", () => {
        const { serializer, objectPick } = makeTestRig();
        const state = {
            correctObjectIds: ["co1", "co2", "co3"],
        };
        objectPick.clearCorrectObjectIds();
        objectPick.addCorrectObjectId("co_1");
        objectPick.addCorrectObjectId("co_2");
        objectPick.addCorrectObjectId("co_3");
        serializer.applySystemState(state, 1);
        expect(objectPick.correctObjectIds).toEqual(["co1", "co2", "co3"]);
    });
    it("Sets the default state as expected", () => {
        const { serializer, objectPick } = makeTestRig();
        objectPick.clearCorrectObjectIds();
        objectPick.addCorrectObjectId("co_1");
        objectPick.addCorrectObjectId("co_2");
        objectPick.addCorrectObjectId("co_3");
        serializer.applyDefaultState();
        expect(objectPick.correctObjectIds).toEqual([]);
    });
    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=SerializeObjectPick.test.js.map