"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 Transform3DPM_1 = require("./Transform3DPM");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObj = appObjects.getOrCreate("appObj");
    const transform = Transform3D_1.Transform3D.addIfMissing(appObj);
    transform.localPosition = new core_2.Vector3(1, 2, 3);
    transform.localScale = new core_2.Vector3(4, 5, 6);
    transform.localRotation = core_2.Quaternion.FromYawPitchRoll(core_2.Angle.FromDegrees(7), core_2.Angle.FromDegrees(8), core_2.Angle.FromDegrees(9));
    const pm = (0, Transform3DPM_1.makeTransform3DPM)(appObj);
    const view = jest.fn();
    pm.addView(view);
    return { appObj, appObjects, transform, pm, view };
}
describe("Transform Presentation Manager", () => {
    it("Sets the last vm on construction", () => {
        const { pm, transform } = makeTestRig();
        expect(pm.lastVM).not.toBeUndefined();
        expect(pm.lastVM?.position).toEqual(transform.localPosition);
        expect(pm.lastVM?.rotation).toEqual(transform.localRotation);
        expect(pm.lastVM?.scale).toEqual(transform.localScale);
    });
    it("Updates the view when the transform changes", () => {
        const { transform, pm } = makeTestRig();
        const spy = jest.spyOn(pm, "doUpdateView");
        transform.localPosition = new core_2.Vector3(10, 20, 30);
        expect(spy).toHaveBeenCalled();
    });
    it("Can be disposed", () => {
        const { transform, pm } = makeTestRig();
        pm.dispose();
        const spy = jest.spyOn(pm, "doUpdateView");
        transform.localPosition = new core_2.Vector3(10, 20, 30);
        expect(spy).not.toHaveBeenCalled();
    });
    it("Is removed from the app object if the entity gets disposed", () => {
        const { transform } = makeTestRig();
        const appObj = transform.appObject;
        expect(appObj.hasComponent(Transform3D_1.Transform3D.type)).toEqual(true);
        transform.dispose();
        expect(appObj.hasComponent(Transform3D_1.Transform3D.type)).toEqual(false);
    });
    it("Returns true if the VMs are the same", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            position: new core_2.Vector3(1, 2, 3),
            scale: new core_2.Vector3(4, 5, 6),
            rotation: core_2.Quaternion.FromYawPitchRoll(core_2.Angle.FromDegrees(7), core_2.Angle.FromDegrees(8), core_2.Angle.FromDegrees(9)),
        };
        const vm2 = { ...vm1 };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Returns false if the VMs don't have the same pos", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            position: new core_2.Vector3(1, 2, 3),
            scale: new core_2.Vector3(4, 5, 6),
            rotation: core_2.Quaternion.FromYawPitchRoll(core_2.Angle.FromDegrees(7), core_2.Angle.FromDegrees(8), core_2.Angle.FromDegrees(9)),
        };
        const vm2 = { ...vm1 };
        vm2.position = core_2.Vector3.Zero();
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if the VMs don't have the same scale", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            position: new core_2.Vector3(1, 2, 3),
            scale: new core_2.Vector3(4, 5, 6),
            rotation: core_2.Quaternion.FromYawPitchRoll(core_2.Angle.FromDegrees(7), core_2.Angle.FromDegrees(8), core_2.Angle.FromDegrees(9)),
        };
        const vm2 = { ...vm1 };
        vm2.scale = core_2.Vector3.Zero();
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if the VMs don't have the same rotation", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            position: new core_2.Vector3(1, 2, 3),
            scale: new core_2.Vector3(4, 5, 6),
            rotation: core_2.Quaternion.FromYawPitchRoll(core_2.Angle.FromDegrees(7), core_2.Angle.FromDegrees(8), core_2.Angle.FromDegrees(9)),
        };
        const vm2 = { ...vm1 };
        vm2.rotation = core_2.Quaternion.Identity();
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Gets the PM for and ID", () => {
        const { appObjects, pm } = makeTestRig();
        expect(Transform3DPM_1.Transform3DPM.getForID("appObj", appObjects)).toEqual(pm);
    });
    it("Returns undefined for an unknownID", () => {
        const { appObjects } = makeTestRig();
        expect(Transform3DPM_1.Transform3DPM.getForID("Unknown", appObjects)).toBeUndefined();
    });
    it("Returns undefined for an app object without a PM", () => {
        const { appObjects } = makeTestRig();
        appObjects.getOrCreate("newObj");
        expect(Transform3DPM_1.Transform3DPM.getForID("newObj", appObjects)).toBeUndefined();
    });
});
//# sourceMappingURL=Transform3DPM.test.js.map