"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const OverlayColor_1 = require("../../OverlayColor/Entities/OverlayColor");
const CalloutEntity_1 = require("./CalloutEntity");
const CalloutRepo_1 = require("./CalloutRepo");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const calloutAO = appObjects.getOrCreate("calloutID");
    const callout = (0, CalloutEntity_1.makeCalloutEntity)(calloutAO);
    const observer = jest.fn();
    callout.addChangeObserver(observer);
    const repoAO = appObjects.getOrCreate("repo");
    const repo = (0, CalloutRepo_1.makeCalloutRepoEntity)(repoAO);
    repo.add(callout);
    callout.inRepo = repo;
    return { callout, appObjects, observer, repo };
}
describe("Callout Entity", () => {
    it("Gets the entoty for the App Object", () => {
        const { callout, appObjects } = makeTestRig();
        expect(CalloutEntity_1.CalloutEntity.getById("calloutID", appObjects)).toEqual(callout);
    });
    it("Notifies when the Label changes", () => {
        const { callout, observer } = makeTestRig();
        observer.mockClear();
        callout.label.notifyOnChange();
        expect(observer).toHaveBeenCalled();
    });
    it("Disposes the label", () => {
        const { callout } = makeTestRig();
        callout.label.dispose = jest.fn();
        callout.dispose();
        expect(callout.label.dispose).toHaveBeenCalled();
    });
    it("Notifies when the hideable changes", () => {
        const { callout, observer } = makeTestRig();
        observer.mockClear();
        callout.hideable.notifyOnChange();
        expect(observer).toHaveBeenCalled();
    });
    it("Disposes the hideable", () => {
        const { callout } = makeTestRig();
        callout.hideable.dispose = jest.fn();
        callout.dispose();
        expect(callout.hideable.dispose).toHaveBeenCalled();
    });
    it("Notifies when the selectable changes", () => {
        const { callout, observer } = makeTestRig();
        observer.mockClear();
        callout.selectable.notifyOnChange();
        expect(observer).toHaveBeenCalled();
    });
    it("Disposes the selectable", () => {
        const { callout } = makeTestRig();
        callout.selectable.dispose = jest.fn();
        callout.dispose();
        expect(callout.selectable.dispose).toHaveBeenCalled();
    });
    it("Removes itself from the repo", () => {
        const { callout, repo } = makeTestRig();
        expect(repo.hasForAppObject(callout.appObject.id)).toEqual(true);
        callout.dispose();
        expect(repo.hasForAppObject(callout.appObject.id)).toEqual(false);
    });
    it("Notifies when the root transform changes", () => {
        const { callout, observer } = makeTestRig();
        observer.mockClear();
        callout.rootTransform.notifyOnChange();
        expect(observer).toHaveBeenCalled();
    });
    it("Disposes the root rootTransform", () => {
        const { callout } = makeTestRig();
        callout.rootTransform.dispose = jest.fn();
        callout.dispose();
        expect(callout.rootTransform.dispose).toHaveBeenCalled();
    });
    it("Notifies when the label transform changes", () => {
        const { callout, observer } = makeTestRig();
        observer.mockClear();
        callout.labelTransform.notifyOnChange();
        expect(observer).toHaveBeenCalled();
    });
    it("Disposes the label rootTransform", () => {
        const { callout } = makeTestRig();
        callout.labelTransform.dispose = jest.fn();
        callout.dispose();
        expect(callout.labelTransform.dispose).toHaveBeenCalled();
    });
    it("Sets and gets the rootPosition", () => {
        const { callout, observer } = makeTestRig();
        expect(callout.rootPosition).toEqual(core_1.Vector3.Zero());
        callout.rootPosition = new core_1.Vector3(1, 2, 3);
        expect(callout.rootPosition).toEqual(new core_1.Vector3(1, 2, 3));
        expect(callout.rootTransform.localPosition).toEqual(new core_1.Vector3(1, 2, 3));
        expect(observer).toHaveBeenCalled();
    });
    it("Sets and gets the rootRotation", () => {
        const { callout, observer } = makeTestRig();
        expect(core_1.Quaternion.Close(callout.rootRotation, core_1.Quaternion.Identity())).toEqual(true);
        const newQ = core_1.Quaternion.FromYawPitchRoll(core_1.Angle.FromDegrees(10), core_1.Angle.FromDegrees(20), core_1.Angle.FromDegrees(30));
        callout.rootRotation = newQ;
        expect(core_1.Quaternion.Close(callout.rootRotation, newQ)).toEqual(true);
        expect(core_1.Quaternion.Close(callout.rootTransform.localRotation, newQ)).toEqual(true);
        expect(observer).toHaveBeenCalled();
    });
    it("Sets and gets the labelPosition", () => {
        const { callout, observer } = makeTestRig();
        expect(callout.labelPosition).toEqual(core_1.Vector3.Zero());
        callout.labelPosition = new core_1.Vector3(1, 2, 3);
        expect(callout.labelPosition).toEqual(new core_1.Vector3(1, 2, 3));
        expect(callout.labelTransform.localPosition).toEqual(new core_1.Vector3(1, 2, 3));
        expect(observer).toHaveBeenCalled();
    });
    it("Sets and gets the labelRotation", () => {
        const { callout, observer } = makeTestRig();
        expect(core_1.Quaternion.Close(callout.labelRotation, core_1.Quaternion.FromYawPitchRoll(core_1.Angle.FromDegrees(180), core_1.Angle.FromDegrees(0), core_1.Angle.FromDegrees(0)))).toEqual(true);
        const newQ = core_1.Quaternion.FromYawPitchRoll(core_1.Angle.FromDegrees(10), core_1.Angle.FromDegrees(20), core_1.Angle.FromDegrees(30));
        callout.labelRotation = newQ;
        expect(core_1.Quaternion.Close(callout.labelRotation, newQ)).toEqual(true);
        expect(core_1.Quaternion.Close(callout.labelTransform.localRotation, newQ)).toEqual(true);
        expect(observer).toHaveBeenCalled();
    });
    it("Sets the dto id", () => {
        const { callout } = makeTestRig();
        expect(callout.data.id).toEqual("calloutID");
    });
    it("Sets the dto parent", () => {
        const { callout } = makeTestRig();
        expect(callout.data.parentID).toEqual("repo");
    });
    it("Sets the dto root position", () => {
        const { callout } = makeTestRig();
        callout.rootPosition = new core_1.Vector3(1, 2, 3);
        expect(callout.data.rootPosition).toEqual(callout.rootPosition.dto);
    });
    it("Sets the dto root rotation", () => {
        const { callout } = makeTestRig();
        callout.rootRotation = core_1.Quaternion.FromYawPitchRoll(core_1.Angle.FromDegrees(10), core_1.Angle.FromDegrees(20), core_1.Angle.FromDegrees(30));
        expect(callout.data.rootRotation).toEqual(callout.rootRotation.dto);
    });
    it("Sets the dto label position", () => {
        const { callout } = makeTestRig();
        callout.labelPosition = new core_1.Vector3(1, 2, 3);
        expect(callout.data.labelPosition).toEqual(callout.labelPosition.dto);
    });
    it("Sets the dto label", () => {
        const { callout } = makeTestRig();
        callout.label.custom = "custom label";
        expect(callout.data.label).toEqual("custom label");
    });
    it("Sets the dto default label", () => {
        const { callout } = makeTestRig();
        callout.label.default = "default label";
        expect(callout.data.defaultLabel).toEqual("default label");
    });
    it("Sets the dto color", () => {
        const { callout } = makeTestRig();
        callout.overlayColor.overlayColor = OverlayColor_1.OverlayColorEnums.RED;
        expect(callout.data.color).toEqual("Red");
    });
    it("Applies the dto root position", () => {
        const { callout } = makeTestRig();
        callout.data = {
            id: "calloutID",
            parentID: "repo",
            rootPosition: new core_1.Vector3(1, 2, 3).dto,
            rootRotation: core_1.Quaternion.FromYawPitchRoll(core_1.Angle.FromDegrees(10), core_1.Angle.FromDegrees(20), core_1.Angle.FromDegrees(30)).dto,
            labelPosition: new core_1.Vector3(4, 5, 6).dto,
            defaultLabel: "default label",
            label: "custom label",
            size: 5,
            color: "Red",
        };
        expect(callout.rootPosition).toEqual(new core_1.Vector3(1, 2, 3));
    });
    it("Applies the dto root rotation", () => {
        const { callout } = makeTestRig();
        callout.data = {
            id: "calloutID",
            parentID: "repo",
            rootPosition: new core_1.Vector3(1, 2, 3).dto,
            rootRotation: core_1.Quaternion.FromYawPitchRoll(core_1.Angle.FromDegrees(10), core_1.Angle.FromDegrees(20), core_1.Angle.FromDegrees(30)).dto,
            labelPosition: new core_1.Vector3(4, 5, 6).dto,
            defaultLabel: "default label",
            label: "custom label",
            size: 5,
            color: "Red",
        };
        expect(core_1.Quaternion.Close(callout.rootRotation, core_1.Quaternion.FromYawPitchRoll(core_1.Angle.FromDegrees(10), core_1.Angle.FromDegrees(20), core_1.Angle.FromDegrees(30)))).toEqual(true);
    });
    it("Applies the dto label position", () => {
        const { callout } = makeTestRig();
        callout.data = {
            id: "calloutID",
            parentID: "repo",
            rootPosition: new core_1.Vector3(1, 2, 3).dto,
            rootRotation: core_1.Quaternion.FromYawPitchRoll(core_1.Angle.FromDegrees(10), core_1.Angle.FromDegrees(20), core_1.Angle.FromDegrees(30)).dto,
            labelPosition: new core_1.Vector3(4, 5, 6).dto,
            defaultLabel: "default label",
            label: "custom label",
            size: 5,
            color: "Red",
        };
        expect(callout.labelPosition).toEqual(new core_1.Vector3(4, 5, 6));
    });
    it("Applies the dto label", () => {
        const { callout } = makeTestRig();
        callout.data = {
            id: "calloutID",
            parentID: "repo",
            rootPosition: new core_1.Vector3(1, 2, 3).dto,
            rootRotation: core_1.Quaternion.FromYawPitchRoll(core_1.Angle.FromDegrees(10), core_1.Angle.FromDegrees(20), core_1.Angle.FromDegrees(30)).dto,
            labelPosition: new core_1.Vector3(4, 5, 6).dto,
            defaultLabel: "default label",
            label: "custom label",
            size: 5,
            color: "Red",
        };
        expect(callout.label.custom).toEqual("custom label");
    });
    it("Applies the dto default label", () => {
        const { callout } = makeTestRig();
        callout.data = {
            id: "calloutID",
            parentID: "repo",
            rootPosition: new core_1.Vector3(1, 2, 3).dto,
            rootRotation: core_1.Quaternion.FromYawPitchRoll(core_1.Angle.FromDegrees(10), core_1.Angle.FromDegrees(20), core_1.Angle.FromDegrees(30)).dto,
            labelPosition: new core_1.Vector3(4, 5, 6).dto,
            defaultLabel: "default label",
            label: "custom label",
            size: 5,
            color: "Red",
        };
        expect(callout.label.default).toEqual("default label");
    });
    it("Applies the dto color", () => {
        const { callout } = makeTestRig();
        callout.data = {
            id: "calloutID",
            parentID: "repo",
            rootPosition: new core_1.Vector3(1, 2, 3).dto,
            rootRotation: core_1.Quaternion.FromYawPitchRoll(core_1.Angle.FromDegrees(10), core_1.Angle.FromDegrees(20), core_1.Angle.FromDegrees(30)).dto,
            labelPosition: new core_1.Vector3(4, 5, 6).dto,
            defaultLabel: "default label",
            label: "custom label",
            size: 5,
            color: "Red",
        };
        expect(callout.overlayColor.overlayColor).toEqual(OverlayColor_1.OverlayColorEnums.RED);
    });
});
//# sourceMappingURL=CalloutEntity.test.js.map