"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Transform3D_1 = require("../Entities/Transform3D");
const CanBeStuckPM_1 = require("./CanBeStuckPM");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObj = (0, core_1.makeAppObject)("obj1", appObjects);
    const transform1 = (0, Transform3D_1.makeTransform3D)(appObj);
    transform1.localPosition = new core_2.Vector3(1, 2, 3);
    const view = jest.fn();
    const pm = (0, CanBeStuckPM_1.makeCanBeStuckPM)(appObj);
    return { appObjects, transform1, pm, view };
}
describe("Can Be Stuck PM", () => {
    it("Sets the last vm on construction", () => {
        const { pm } = makeTestRig();
        expect(pm.lastVM).toEqual(true);
    });
    it("Updates the view when the position changes", () => {
        const { pm, transform1 } = makeTestRig();
        const spy = jest.spyOn(pm, "doUpdateView");
        transform1.localPosition = core_2.Vector3.Zero();
        expect(spy).toHaveBeenCalledWith(false);
    });
    it("Can be disposed", () => {
        const { pm, transform1 } = makeTestRig();
        pm.dispose();
        const spy = jest.spyOn(pm, "doUpdateView");
        transform1.localPosition = core_2.Vector3.Zero();
        expect(spy).not.toHaveBeenCalled();
    });
    it("Is removed from the app object if the entity gets disposed", () => {
        const { transform1 } = makeTestRig();
        const appObj = transform1.appObject;
        expect(appObj.hasComponent(Transform3D_1.Transform3D.type)).toEqual(true);
        transform1.dispose();
        expect(appObj.hasComponent(Transform3D_1.Transform3D.type)).toEqual(false);
    });
    it("Checks for changes in the vm", () => {
        const { pm } = makeTestRig();
        expect(pm.vmsAreEqual(true, true)).toEqual(true);
        expect(pm.vmsAreEqual(false, false)).toEqual(true);
        expect(pm.vmsAreEqual(true, false)).toEqual(false);
        expect(pm.vmsAreEqual(false, true)).toEqual(false);
    });
    it("Gets the PM for and ID", () => {
        const { appObjects, pm } = makeTestRig();
        expect(CanBeStuckPM_1.CanBeStuckPM.getForID("obj1", appObjects)).toEqual(pm);
    });
    it("Returns undefined for an unknownID", () => {
        const { appObjects } = makeTestRig();
        expect(CanBeStuckPM_1.CanBeStuckPM.getForID("Unknown", appObjects)).toBeUndefined();
    });
    it("Returns undefined for an app object without a PM", () => {
        const { appObjects } = makeTestRig();
        appObjects.getOrCreate("newObj");
        expect(CanBeStuckPM_1.CanBeStuckPM.getForID("newObj", appObjects)).toBeUndefined();
    });
});
//# sourceMappingURL=CanBeStuckPM.test.js.map