"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Entities_1 = require("../Entities");
const Selectable_1 = require("../Entities/Selectable");
const SelectableStatePM_1 = require("./SelectableStatePM");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObj = appObjects.getOrCreate("appObj1");
    const selection = (0, Entities_1.makeSelection)(appObjects.getOrCreate("Selection"));
    const selectable = (0, Selectable_1.makeSelectable)(appObj);
    selectable.hovered = true;
    selectable.pressed = true;
    selectable.selected = true;
    const pm = (0, SelectableStatePM_1.makeSelectableStatePM)(appObj);
    return { pm, appObj, appObjects, selectable, selection };
}
describe("Selectable Presentation Manager", () => {
    it("Checks for equal VMs", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            isHovered: true,
            isPressed: true,
            isSelected: true,
            somethingElseIsSelected: true,
        };
        const vm2 = {
            isHovered: true,
            isPressed: true,
            isSelected: true,
            somethingElseIsSelected: true,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("VMs are not equal if the hover doesn't match", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            isHovered: true,
            isPressed: true,
            isSelected: true,
            somethingElseIsSelected: true,
        };
        const vm2 = {
            isHovered: false,
            isPressed: true,
            isSelected: true,
            somethingElseIsSelected: true,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("VMs are not equal if the pressed doesn't match", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            isHovered: true,
            isPressed: true,
            isSelected: true,
            somethingElseIsSelected: true,
        };
        const vm2 = {
            isHovered: true,
            isPressed: false,
            isSelected: true,
            somethingElseIsSelected: true,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("VMs are not equal if the selected doesn't match", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            isHovered: true,
            isPressed: true,
            isSelected: true,
            somethingElseIsSelected: true,
        };
        const vm2 = {
            isHovered: true,
            isPressed: true,
            isSelected: false,
            somethingElseIsSelected: true,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("VMs are not equal if the something else is selected doesn't match", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            isHovered: true,
            isPressed: true,
            isSelected: true,
            somethingElseIsSelected: true,
        };
        const vm2 = {
            isHovered: true,
            isPressed: true,
            isSelected: true,
            somethingElseIsSelected: false,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Sets the VM as expected", () => {
        const { pm } = makeTestRig();
        expect(pm.lastVM?.isHovered).toEqual(true);
        expect(pm.lastVM?.isPressed).toEqual(true);
        expect(pm.lastVM?.isSelected).toEqual(true);
    });
    it("Updates the view when the entity changes", () => {
        const { pm, selectable } = makeTestRig();
        const view = jest.fn();
        pm.addView(view);
        view.mockClear();
        selectable.hovered = !selectable.hovered;
        expect(view).toHaveBeenCalled();
    });
    it("Unsubscribes from the entity when disposed", () => {
        const { pm, selectable } = makeTestRig();
        const view = jest.fn();
        pm.addView(view);
        pm.dispose();
        view.mockClear();
        selectable.hovered = !selectable.hovered;
        expect(view).not.toHaveBeenCalled();
    });
    it("Gets the PM", () => {
        const { appObjects, pm } = makeTestRig();
        expect(SelectableStatePM_1.SelectableStatePM.get("appObj1", appObjects)).toEqual(pm);
    });
    it("Sets if something else is selected", () => {
        const { pm, selection, appObjects } = makeTestRig();
        const otherAO = appObjects.getOrCreate("appObj2");
        selection.makeAppObjectSelectable(otherAO);
        selection.selectedObjectId = "appObj2";
        expect(pm.lastVM?.somethingElseIsSelected).toEqual(true);
    });
});
//# sourceMappingURL=SelectableStatePM.test.js.map