import { makeAppObjectRepo } from "@vived/core";
import { Vector2 } from "@vived/core";
import { LabelDropDragMode, makeLabelDropRepo, } from "../Entities/LabelDropRepo";
import { LabelDropDragItemPM, makeLabelDropDragItemPM, } from "./LabelDropDragItemPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const appObject = appObjects.getOrCreate("AppObject");
    const labelDrop = makeLabelDropRepo(appObject);
    const pm = makeLabelDropDragItemPM(appObject);
    return { labelDrop, registerSpy, pm, appObjects };
}
describe("Label Drop Drag Item Presentation Manager", () => {
    it("Gets the singleton", () => {
        const { appObjects, pm } = makeTestRig();
        expect(LabelDropDragItemPM.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("Returns true if the VMs are the same", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            id: "1234",
            label: "label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: false,
            alpha: 1,
            screenPosition: new Vector2(0, 0),
        };
        const vm2 = {
            id: "1234",
            label: "label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: false,
            alpha: 1,
            screenPosition: new Vector2(0, 0),
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Returns false if the id is different", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            id: "1234",
            label: "label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: undefined,
            alpha: 1,
            screenPosition: new Vector2(120, 100),
        };
        const vm2 = {
            id: "5678",
            label: "label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: undefined,
            alpha: 1,
            screenPosition: new Vector2(120, 100),
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if the label is different", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            id: "1234",
            label: "label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: undefined,
            alpha: 1,
            screenPosition: new Vector2(120, 100),
        };
        const vm2 = {
            id: "1234",
            label: "new label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: undefined,
            alpha: 1,
            screenPosition: new Vector2(120, 100),
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if show is different", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            id: "1234",
            label: "label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: undefined,
            alpha: 1,
            screenPosition: new Vector2(120, 100),
        };
        const vm2 = {
            id: "1234",
            label: "label",
            show: false,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: undefined,
            alpha: 1,
            screenPosition: new Vector2(120, 100),
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if mode is different", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            id: "1234",
            label: "label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: undefined,
            alpha: 1,
            screenPosition: new Vector2(120, 100),
        };
        const vm2 = {
            id: "1234",
            label: "label",
            show: true,
            mode: LabelDropDragMode.WORLD,
            resultIsCorrect: undefined,
            alpha: 1,
            screenPosition: new Vector2(120, 100),
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if result is different", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            id: "1234",
            label: "label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: undefined,
            alpha: 1,
            screenPosition: new Vector2(120, 100),
        };
        const vm2 = {
            id: "1234",
            label: "label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: true,
            alpha: 1,
            screenPosition: new Vector2(120, 100),
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if alpha is different", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            id: "1234",
            label: "label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: undefined,
            alpha: 1,
            screenPosition: new Vector2(120, 100),
        };
        const vm2 = {
            id: "1234",
            label: "label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: undefined,
            alpha: 0,
            screenPosition: new Vector2(120, 100),
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if screen position is different", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            id: "1234",
            label: "label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: undefined,
            alpha: 1,
            screenPosition: new Vector2(0, 0),
        };
        const vm2 = {
            id: "1234",
            label: "label",
            show: true,
            mode: LabelDropDragMode.SCREEN,
            resultIsCorrect: undefined,
            alpha: 1,
            screenPosition: new Vector2(120, 100),
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Updates the view when the dragging id changes", () => {
        const { labelDrop, pm } = makeTestRig();
        const newValue = "123abc";
        expect(pm.lastVM?.id).not.toEqual(newValue);
        labelDrop.draggingID = newValue;
        expect(pm.lastVM?.id).toEqual(newValue);
    });
    it("Updates the view when the dragged label changes", () => {
        const { labelDrop, pm } = makeTestRig();
        const itemId = "1234";
        const dragItem = labelDrop.makeLabelDropItem(itemId);
        dragItem.labelEntity.custom = "Starting label";
        labelDrop.draggingID = itemId;
        expect(pm.lastVM?.label).toEqual("Starting label");
        dragItem.labelEntity.custom = "New label";
        expect(pm.lastVM?.label).toEqual("New label");
    });
    it("Updates the view when the drag mode changes", () => {
        const { labelDrop, pm } = makeTestRig();
        const newValue = LabelDropDragMode.WORLD;
        labelDrop.draggingID = "1234";
        expect(pm.lastVM?.mode).not.toEqual(newValue);
        labelDrop.dragMode = newValue;
        expect(pm.lastVM?.mode).toEqual(newValue);
    });
    it("Updates the view when drag alpha changes", () => {
        const { labelDrop, pm } = makeTestRig();
        const newValue = 0.25;
        labelDrop.draggingID = "1234";
        expect(pm.lastVM?.alpha).not.toEqual(newValue);
        labelDrop.dragAlpha = newValue;
        expect(pm.lastVM?.alpha).toEqual(newValue);
    });
    it("Updates the view's show property to true when alpha changes from 0 to a value greater than 0", () => {
        const { labelDrop, pm } = makeTestRig();
        labelDrop.dragAlpha = 0;
        labelDrop.draggingID = "1234";
        expect(pm.lastVM?.alpha).toEqual(0);
        expect(pm.lastVM?.show).toEqual(false);
        labelDrop.dragAlpha = 1;
        expect(pm.lastVM?.show).toEqual(true);
    });
    it("Updates the view's show property to false when alpha changes from a value greater than 0 to 0", () => {
        const { labelDrop, pm } = makeTestRig();
        labelDrop.draggingID = "1234";
        labelDrop.dragAlpha = 0.5;
        expect(pm.lastVM?.alpha).toEqual(0.5);
        expect(pm.lastVM?.show).toEqual(true);
        labelDrop.dragAlpha = 0;
        expect(pm.lastVM?.show).toEqual(false);
    });
    it("Updates the view when result changes", () => {
        const { labelDrop, pm } = makeTestRig();
        const newValue = true;
        labelDrop.draggingID = "1234";
        expect(pm.lastVM?.resultIsCorrect).not.toEqual(newValue);
        labelDrop.resultIsCorrect = newValue;
        expect(pm.lastVM?.resultIsCorrect).toEqual(newValue);
    });
    it("Updates the view when scren position changes", () => {
        const { labelDrop, pm } = makeTestRig();
        const newValue = new Vector2(256, 192);
        labelDrop.draggingID = "1234";
        expect(pm.lastVM?.screenPosition).not.toEqual(newValue);
        labelDrop.screenPosition = newValue;
        expect(pm.lastVM?.screenPosition).toEqual(newValue);
    });
    it("Maintains the drag mode when dragging ID is undefined", () => {
        const { labelDrop, pm } = makeTestRig();
        labelDrop.draggingID = "1234";
        labelDrop.dragMode = LabelDropDragMode.WORLD;
        expect(pm.lastVM?.mode).toEqual(LabelDropDragMode.WORLD);
        labelDrop.draggingID = undefined;
        expect(pm.lastVM?.show).toEqual(false);
        expect(pm.lastVM?.mode).toEqual(LabelDropDragMode.WORLD);
    });
});
//# sourceMappingURL=LabelDropDragItemPM.test.js.map