import { makeAppObjectRepo } from "@vived/core";
import { makeObjectPickEntity } from "./ObjectPickEntity";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const objectPickAO = appObjects.getOrCreate("ObjectPick");
    const objectPick = makeObjectPickEntity(objectPickAO);
    const observer = jest.fn();
    objectPick.addChangeObserver(observer);
    return { objectPick, observer, appObjects };
}
describe("ObjectPick Entity", () => {
    it("Initialized correctObjectIds with empty array", () => {
        const { objectPick } = makeTestRig();
        expect(objectPick.correctObjectIds.length).toEqual(0);
    });
    it("Sets the correctObjectIds", () => {
        const { objectPick } = makeTestRig();
        objectPick.addCorrectObjectId("co1");
        expect(objectPick.correctObjectIds.length).toEqual(1);
    });
    it("Notifies when correctObjectIds is changed", () => {
        const { objectPick, observer } = makeTestRig();
        objectPick.addCorrectObjectId("co1");
        expect(observer).toHaveBeenCalled();
    });
    it("Removes an ID from correctObjectIds", () => {
        const { objectPick } = makeTestRig();
        objectPick.addCorrectObjectId("co1");
        objectPick.removeCorrectObjectId("co1");
        expect(objectPick.correctObjectIds.length).toEqual(0);
    });
    it("Initializes hasSubmitted as false", () => {
        const { objectPick } = makeTestRig();
        expect(objectPick.hasSubmitted).toBeFalsy();
    });
    it("Submits an ID", () => {
        const { objectPick } = makeTestRig();
        objectPick.submit("submittedId");
        expect(objectPick.hasSubmitted).toBeTruthy();
    });
    it("Notifies when hasSubmitted is changed", () => {
        const { objectPick, observer } = makeTestRig();
        objectPick.submit("submittedId");
        expect(observer).toHaveBeenCalled();
    });
    it("Clears submission and resets hasSubmitted", () => {
        const { objectPick } = makeTestRig();
        objectPick.submit("submittedId");
        objectPick.reset();
        expect(objectPick.hasSubmitted).toBeFalsy();
    });
    it("Initialized isSelectingCorrectObjects as false", () => {
        const { objectPick } = makeTestRig();
        expect(objectPick.isSelectingCorrectObjects).toBeFalsy();
    });
    it("Sets isSelectingCorrectObjects", () => {
        const { objectPick } = makeTestRig();
        objectPick.isSelectingCorrectObjects = true;
        expect(objectPick.isSelectingCorrectObjects).toBeTruthy();
    });
    it("Notifies when isSelectingCorrectObjects is changed", () => {
        const { objectPick, observer } = makeTestRig();
        objectPick.isSelectingCorrectObjects = true;
        expect(observer).toHaveBeenCalled();
    });
    it("Doesn't notify when isSelectingCorrectObjects is not changed", () => {
        const { objectPick, observer } = makeTestRig();
        objectPick.isSelectingCorrectObjects = true;
        observer.mockClear();
        objectPick.isSelectingCorrectObjects = true;
        objectPick.isSelectingCorrectObjects = true;
        objectPick.isSelectingCorrectObjects = true;
        expect(observer).not.toHaveBeenCalled();
    });
    it("Clears the ObjectPick entity", () => {
        const { objectPick, observer } = makeTestRig();
        objectPick.addCorrectObjectId("co1");
        objectPick.submit("submittedId");
        objectPick.isSelectingCorrectObjects = true;
        expect(observer).toHaveBeenCalled();
        expect(objectPick.correctObjectIds.length).toEqual(1);
        expect(objectPick.hasSubmitted).toBeTruthy();
        objectPick.clearCorrectObjectIds();
        expect(observer).toHaveBeenCalled();
        expect(objectPick.correctObjectIds.length).toEqual(0);
        expect(objectPick.hasSubmitted).toBeFalsy();
    });
    it("Removed an object ID if that app object is disposed", () => {
        const { objectPick, appObjects } = makeTestRig();
        const obj1 = appObjects.getOrCreate("AppObj1");
        objectPick.addCorrectObjectId("AppObj1");
        expect(objectPick.correctObjectIds).toEqual(["AppObj1"]);
        obj1.dispose();
        expect(objectPick.correctObjectIds).toEqual([]);
    });
    it("Returns a copy of the correct IDs", () => {
        const { objectPick } = makeTestRig();
        const original = objectPick.correctObjectIds;
        expect(original).toEqual([]);
        objectPick.addCorrectObjectId("obj1");
        expect(original).toEqual([]);
    });
});
//# sourceMappingURL=ObjectPickEntity.test.js.map