import { makeAppObjectRepo } from "@vived/core";
import { makeObjectPickEntity } from "../Entities/ObjectPickEntity";
import { makeValidateObjectPickUcMock } from "../Mocks/ValidateObjectPickUcMock";
import { makeObjectPickPM, ObjectPickPM } from "./ObjectPickPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const appObj = appObjects.getOrCreate("ObjectPickAO");
    const objectPickEntity = makeObjectPickEntity(appObj);
    const mockValidate = makeValidateObjectPickUcMock(appObjects);
    mockValidate.validateObjectPick.mockReturnValue(null);
    const pm = makeObjectPickPM(appObj);
    return {
        appObj,
        appObjects,
        objectPickEntity,
        pm,
        registerSpy,
        mockValidate,
    };
}
describe("Object Pick Presentation Manager", () => {
    it("Gets the singleton", () => {
        const { appObjects, pm } = makeTestRig();
        expect(ObjectPickPM.get(appObjects)).toEqual(pm);
    });
    it("Registers as the singleton", () => {
        const { registerSpy, pm } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(pm);
    });
    it("Sets the last vm on construction", () => {
        const { pm } = makeTestRig();
        expect(pm.lastVM).not.toBeUndefined();
    });
    it("Updates the view when the entity changes", () => {
        const { pm, objectPickEntity } = makeTestRig();
        objectPickEntity.addCorrectObjectId("obj1");
        objectPickEntity.submit("obj1");
        objectPickEntity.isSelectingCorrectObjects = true;
        expect(pm.lastVM).toEqual({
            correctObjectIds: ["obj1"],
            isSelectingCorrectObjects: true,
            hasSubmitted: true,
            isCorrect: true,
            validationMessage: null,
        });
    });
    it("Sets the validation message", () => {
        const { pm, objectPickEntity, mockValidate } = makeTestRig();
        mockValidate.validateObjectPick.mockReturnValue("Some Message");
        objectPickEntity.addCorrectObjectId("obj1");
        objectPickEntity.submit("obj1");
        objectPickEntity.isSelectingCorrectObjects = true;
        expect(pm.lastVM).toEqual({
            correctObjectIds: ["obj1"],
            isSelectingCorrectObjects: true,
            hasSubmitted: true,
            isCorrect: true,
            validationMessage: "Some Message",
        });
    });
    it("Returns true if the VMs are the same", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            correctObjectIds: ["obj1", "obj2"],
            isSelectingCorrectObjects: true,
            hasSubmitted: true,
            isCorrect: true,
            validationMessage: null,
        };
        const vm2 = {
            ...vm1,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Checks for an object to be removed", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            correctObjectIds: ["obj1", "obj2"],
            isSelectingCorrectObjects: true,
            hasSubmitted: true,
            isCorrect: true,
            validationMessage: null,
        };
        const vm2 = {
            ...vm1,
            correctObjectIds: ["obj1"],
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for an object to be added", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            correctObjectIds: ["obj1", "obj2"],
            isSelectingCorrectObjects: true,
            hasSubmitted: true,
            isCorrect: true,
            validationMessage: null,
        };
        const vm2 = {
            ...vm1,
            correctObjectIds: ["obj1", "obj2", "obj3"],
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for an object to be change", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            correctObjectIds: ["obj1", "obj2"],
            isSelectingCorrectObjects: true,
            hasSubmitted: true,
            isCorrect: true,
            validationMessage: null,
        };
        const vm2 = {
            ...vm1,
            correctObjectIds: ["obj1", "CHANGED"],
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for isSelectingCorrectObjects to change", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            correctObjectIds: ["obj1", "obj2"],
            isSelectingCorrectObjects: true,
            hasSubmitted: true,
            isCorrect: true,
            validationMessage: null,
        };
        const vm2 = {
            ...vm1,
            isSelectingCorrectObjects: false,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for hasSubmitted to change", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            correctObjectIds: ["obj1", "obj2"],
            isSelectingCorrectObjects: true,
            hasSubmitted: true,
            isCorrect: true,
            validationMessage: null,
        };
        const vm2 = {
            ...vm1,
            hasSubmitted: false,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for isCorrect to change", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            correctObjectIds: ["obj1", "obj2"],
            isSelectingCorrectObjects: true,
            hasSubmitted: true,
            isCorrect: true,
            validationMessage: null,
        };
        const vm2 = {
            ...vm1,
            isCorrect: false,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for the validation message to change", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            correctObjectIds: ["obj1", "obj2"],
            isSelectingCorrectObjects: true,
            hasSubmitted: true,
            isCorrect: true,
            validationMessage: null,
        };
        const vm2 = {
            ...vm1,
            validationMessage: "some message",
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
});
//# sourceMappingURL=ObjectPickPM.test.js.map