import { makeAppObject, makeAppObjectRepo } from "@vived/core";
import { Vector3 } from "@vived/core";
import { makeTransform3D, Transform3D } from "../Entities/Transform3D";
import { CanBeStuckPM, makeCanBeStuckPM } from "./CanBeStuckPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appObj = makeAppObject("obj1", appObjects);
    const transform1 = makeTransform3D(appObj);
    transform1.localPosition = new Vector3(1, 2, 3);
    const view = jest.fn();
    const pm = 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 = Vector3.Zero();
        expect(spy).toHaveBeenCalledWith(false);
    });
    it("Can be disposed", () => {
        const { pm, transform1 } = makeTestRig();
        pm.dispose();
        const spy = jest.spyOn(pm, "doUpdateView");
        transform1.localPosition = 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.type)).toEqual(true);
        transform1.dispose();
        expect(appObj.hasComponent(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.getForID("obj1", appObjects)).toEqual(pm);
    });
    it("Returns undefined for an unknownID", () => {
        const { appObjects } = makeTestRig();
        expect(CanBeStuckPM.getForID("Unknown", appObjects)).toBeUndefined();
    });
    it("Returns undefined for an app object without a PM", () => {
        const { appObjects } = makeTestRig();
        appObjects.getOrCreate("newObj");
        expect(CanBeStuckPM.getForID("newObj", appObjects)).toBeUndefined();
    });
});
//# sourceMappingURL=CanBeStuckPM.test.js.map