import { makeAppObjectRepo } from "@vived/core";
import { Quaternion, Vector3 } from "@vived/core";
import { makeStylusEntity } from "../Entity/StylusEntity";
import { makeStylusIsInUsePM, StylusIsInUsePM } from "./StylusIsInUsePM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSingletonSpy = jest.spyOn(appObjects, "registerSingleton");
    const stylusAO = appObjects.getOrCreate("Stylus");
    const stylusEntity = makeStylusEntity(stylusAO);
    const pm = makeStylusIsInUsePM(stylusAO);
    return { pm, stylusEntity, registerSingletonSpy, appObjects };
}
describe("Stylus is in use", () => {
    it("Initializes the VM", () => {
        const { pm } = makeTestRig();
        const lastVM = pm.lastVM;
        expect(lastVM).toEqual(false);
    });
    it("Updates is in use to true if the stylus has moved", () => {
        const { pm, stylusEntity } = makeTestRig();
        stylusEntity.transform.worldPosition = Vector3.One();
        stylusEntity.transform.worldRotation = new Quaternion(1, 1, 1, 1);
        const lastVM = pm.lastVM;
        expect(lastVM).toEqual(true);
    });
    it("Updates is in use back to false", () => {
        const { pm, stylusEntity } = makeTestRig();
        stylusEntity.transform.worldPosition = Vector3.One();
        stylusEntity.transform.worldRotation = new Quaternion(1, 1, 1, 1);
        stylusEntity.transform.worldPosition = Vector3.Zero();
        stylusEntity.transform.worldRotation = Quaternion.Identity();
        const lastVM = pm.lastVM;
        expect(lastVM).toEqual(false);
    });
    it("Registers as a singleton", () => {
        const { pm, registerSingletonSpy } = makeTestRig();
        expect(registerSingletonSpy).toHaveBeenCalledWith(pm);
    });
    it("Gets the singleton", () => {
        const { pm, appObjects } = makeTestRig();
        expect(StylusIsInUsePM.get(appObjects)).toEqual(pm);
    });
});
//# sourceMappingURL=StylusIsInUsePM.test.js.map