import { makeAppObjectRepo } from "@vived/core";
import { Color, Vector3 } from "@vived/core";
import { SceneRayPickUC } from "../../Babylon";
import { makeStylusEntity } from "../Entity/StylusEntity";
import { makeStylusColorLengthPM, StylusColorLengthPM, } from "./StylusColorLengthPM";
class MockSceneRayPick extends SceneRayPickUC {
    constructor() {
        super(...arguments);
        this.sceneRayPick = jest.fn();
    }
}
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSingletonSpy = jest.spyOn(appObjects, "registerSingleton");
    const stylusAO = appObjects.getOrCreate("Stylus");
    const stylusEntity = makeStylusEntity(stylusAO);
    const mockSceneRayPick = new MockSceneRayPick(stylusAO, SceneRayPickUC.type);
    jest.spyOn(stylusEntity, "isInUse", "get").mockReturnValue(true);
    const pm = makeStylusColorLengthPM(stylusAO);
    return {
        zSpaceEntity: stylusEntity,
        pm,
        stylusEntity,
        mockSceneRayPick,
        registerSingletonSpy,
        appObjects,
    };
}
describe("ZSpace Stylus Color and Length Presentation Manager", () => {
    it("Checks for equal vms", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            color: Color.RGB(1, 1, 1),
            length: 2,
        };
        const vm2 = {
            color: Color.RGB(1, 1, 1),
            length: 2,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Checks for a change in the color value", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            color: Color.RGB(1, 2, 3),
            length: 2,
        };
        const vm2 = {
            color: Color.RGB(1, 1, 1),
            length: 2,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for a change in the length value", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            color: Color.RGB(1, 1, 1),
            length: 1,
        };
        const vm2 = {
            color: Color.RGB(1, 1, 1),
            length: 2,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Default the VM", () => {
        const { pm, stylusEntity } = makeTestRig();
        jest.spyOn(stylusEntity, "isInUse", "get").mockReturnValue(false);
        stylusEntity.notifyOnChange();
        expect(pm.lastVM?.color).toEqual(pm.rayColorNoPick);
        expect(pm.lastVM?.length).toEqual(0);
    });
    it("Sets the ray color when a pick happens", () => {
        const { pm, mockSceneRayPick, stylusEntity } = makeTestRig();
        expect(pm.lastVM?.color).toEqual(pm.rayColorNoPick);
        const mockPick = {
            hit: true,
            worldPickPoint: new Vector3(10, 0, 0),
        };
        mockSceneRayPick.sceneRayPick.mockReturnValue(mockPick);
        stylusEntity.notifyOnChange();
        expect(pm.lastVM?.color).toEqual(pm.rayColorPick);
    });
    it("Sets the ray length to the distance between the stylus and the pick", () => {
        const { pm, mockSceneRayPick, stylusEntity } = makeTestRig();
        expect(pm.lastVM?.length).toEqual(1);
        const mockPick = {
            hit: true,
            worldPickPoint: new Vector3(10, 0, 0),
        };
        mockSceneRayPick.sceneRayPick.mockReturnValue(mockPick);
        stylusEntity.transform.worldPosition = new Vector3(-1, 0, 0);
        expect(pm.lastVM?.length).toEqual(11);
    });
    it("Registers as a singleton", () => {
        const { pm, registerSingletonSpy } = makeTestRig();
        expect(registerSingletonSpy).toHaveBeenCalledWith(pm);
    });
    it("Gets the singleton", () => {
        const { pm, appObjects } = makeTestRig();
        expect(StylusColorLengthPM.get(appObjects)).toEqual(pm);
    });
});
//# sourceMappingURL=StylusColorLengthPM.test.js.map