import { Angle, makeAppObjectRepo, Quaternion, Vector3 } from "@vived/core";
import { OverlayColorEnums } from "../../OverlayColor/Entities/OverlayColor";
import { CalloutEntity, makeCalloutEntity } from "./CalloutEntity";
import { makeCalloutRepoEntity } from "./CalloutRepo";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const calloutAO = appObjects.getOrCreate("calloutID");
    const callout = makeCalloutEntity(calloutAO);
    const observer = jest.fn();
    callout.addChangeObserver(observer);
    const repoAO = appObjects.getOrCreate("repo");
    const repo = 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.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(Vector3.Zero());
        callout.rootPosition = new Vector3(1, 2, 3);
        expect(callout.rootPosition).toEqual(new Vector3(1, 2, 3));
        expect(callout.rootTransform.localPosition).toEqual(new Vector3(1, 2, 3));
        expect(observer).toHaveBeenCalled();
    });
    it("Sets and gets the rootRotation", () => {
        const { callout, observer } = makeTestRig();
        expect(Quaternion.Close(callout.rootRotation, Quaternion.Identity())).toEqual(true);
        const newQ = Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30));
        callout.rootRotation = newQ;
        expect(Quaternion.Close(callout.rootRotation, newQ)).toEqual(true);
        expect(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(Vector3.Zero());
        callout.labelPosition = new Vector3(1, 2, 3);
        expect(callout.labelPosition).toEqual(new Vector3(1, 2, 3));
        expect(callout.labelTransform.localPosition).toEqual(new Vector3(1, 2, 3));
        expect(observer).toHaveBeenCalled();
    });
    it("Sets and gets the labelRotation", () => {
        const { callout, observer } = makeTestRig();
        expect(Quaternion.Close(callout.labelRotation, Quaternion.FromYawPitchRoll(Angle.FromDegrees(180), Angle.FromDegrees(0), Angle.FromDegrees(0)))).toEqual(true);
        const newQ = Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30));
        callout.labelRotation = newQ;
        expect(Quaternion.Close(callout.labelRotation, newQ)).toEqual(true);
        expect(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 Vector3(1, 2, 3);
        expect(callout.data.rootPosition).toEqual(callout.rootPosition.dto);
    });
    it("Sets the dto root rotation", () => {
        const { callout } = makeTestRig();
        callout.rootRotation = Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30));
        expect(callout.data.rootRotation).toEqual(callout.rootRotation.dto);
    });
    it("Sets the dto label position", () => {
        const { callout } = makeTestRig();
        callout.labelPosition = new 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 = 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 Vector3(1, 2, 3).dto,
            rootRotation: Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30)).dto,
            labelPosition: new Vector3(4, 5, 6).dto,
            defaultLabel: "default label",
            label: "custom label",
            size: 5,
            color: "Red",
        };
        expect(callout.rootPosition).toEqual(new Vector3(1, 2, 3));
    });
    it("Applies the dto root rotation", () => {
        const { callout } = makeTestRig();
        callout.data = {
            id: "calloutID",
            parentID: "repo",
            rootPosition: new Vector3(1, 2, 3).dto,
            rootRotation: Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30)).dto,
            labelPosition: new Vector3(4, 5, 6).dto,
            defaultLabel: "default label",
            label: "custom label",
            size: 5,
            color: "Red",
        };
        expect(Quaternion.Close(callout.rootRotation, Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30)))).toEqual(true);
    });
    it("Applies the dto label position", () => {
        const { callout } = makeTestRig();
        callout.data = {
            id: "calloutID",
            parentID: "repo",
            rootPosition: new Vector3(1, 2, 3).dto,
            rootRotation: Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30)).dto,
            labelPosition: new Vector3(4, 5, 6).dto,
            defaultLabel: "default label",
            label: "custom label",
            size: 5,
            color: "Red",
        };
        expect(callout.labelPosition).toEqual(new Vector3(4, 5, 6));
    });
    it("Applies the dto label", () => {
        const { callout } = makeTestRig();
        callout.data = {
            id: "calloutID",
            parentID: "repo",
            rootPosition: new Vector3(1, 2, 3).dto,
            rootRotation: Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30)).dto,
            labelPosition: new 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 Vector3(1, 2, 3).dto,
            rootRotation: Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30)).dto,
            labelPosition: new 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 Vector3(1, 2, 3).dto,
            rootRotation: Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30)).dto,
            labelPosition: new Vector3(4, 5, 6).dto,
            defaultLabel: "default label",
            label: "custom label",
            size: 5,
            color: "Red",
        };
        expect(callout.overlayColor.overlayColor).toEqual(OverlayColorEnums.RED);
    });
});
//# sourceMappingURL=CalloutEntity.test.js.map