import { makeAppObjectRepo } from "@vived/core";
import { Angle, Quaternion, Vector3 } from "@vived/core";
import { OverlayColorEnums } from "../../OverlayColor";
import { makeSelection } from "../../Selection";
import { makeLandmarkEntity } from "./LandmarkEntity";
import { makeLandmarkRepoEntity } from "./LandmarkRepo";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const baseObj = appObjects.getOrCreate("baseObj");
    const selection = makeSelection(baseObj);
    const obj = appObjects.getOrCreate("landmarkID");
    const landmark = makeLandmarkEntity(obj);
    const observer = jest.fn();
    landmark.addChangeObserver(observer);
    return { landmark, observer, appObjects, selection };
}
describe("Landmark App Object", () => {
    it("Notifies when the Label changes", () => {
        const { landmark, observer } = makeTestRig();
        observer.mockClear();
        landmark.label.notifyOnChange();
        expect(observer).toHaveBeenCalled();
    });
    it("Disposes the label", () => {
        const { landmark } = makeTestRig();
        landmark.label.dispose = jest.fn();
        landmark.dispose();
        expect(landmark.label.dispose).toHaveBeenCalled();
    });
    it("Notifies when the Transform changes", () => {
        const { landmark, observer } = makeTestRig();
        observer.mockClear();
        landmark.transform.notifyOnChange();
        expect(observer).toHaveBeenCalled();
    });
    it("Disposes the Transform", () => {
        const { landmark } = makeTestRig();
        landmark.transform.dispose = jest.fn();
        landmark.dispose();
        expect(landmark.transform.dispose).toHaveBeenCalled();
    });
    it("Notifies when the hideable changes", () => {
        const { landmark, observer } = makeTestRig();
        observer.mockClear();
        landmark.hideable.notifyOnChange();
        expect(observer).toHaveBeenCalled();
    });
    it("Disposes the hideable", () => {
        const { landmark } = makeTestRig();
        landmark.hideable.dispose = jest.fn();
        landmark.dispose();
        expect(landmark.hideable.dispose).toHaveBeenCalled();
    });
    it("Notifies when the overlayColor changes", () => {
        const { landmark, observer } = makeTestRig();
        observer.mockClear();
        landmark.overlayColor.notifyOnChange();
        expect(observer).toHaveBeenCalled();
    });
    it("Disposes the overlay", () => {
        const { landmark } = makeTestRig();
        landmark.overlayColor.dispose = jest.fn();
        landmark.dispose();
        expect(landmark.overlayColor.dispose).toHaveBeenCalled();
    });
    it("Notifies when the selectable changes", () => {
        const { landmark, observer } = makeTestRig();
        observer.mockClear();
        landmark.selectable.notifyOnChange();
        expect(observer).toHaveBeenCalled();
    });
    it("Disposes the selectable", () => {
        const { landmark } = makeTestRig();
        landmark.selectable.dispose = jest.fn();
        landmark.dispose();
        expect(landmark.selectable.dispose).toHaveBeenCalled();
    });
    it("Sets the parent to the repo ID", () => {
        const { landmark, appObjects } = makeTestRig();
        const repo = makeLandmarkRepoEntity(appObjects.getOrCreate("RepoID"));
        landmark.inRepo = repo;
        expect(landmark.parentID).toEqual("RepoID");
    });
    it("Sets the dto id", () => {
        const { landmark } = makeTestRig();
        expect(landmark.data.id).toEqual("landmarkID");
    });
    it("Sets the dto parent to empty it is has not been added to a repo", () => {
        const { landmark } = makeTestRig();
        expect(landmark.data.parentID).toEqual("");
    });
    it("Sets the dto parent to the repo ID", () => {
        const { landmark, appObjects } = makeTestRig();
        const repo = makeLandmarkRepoEntity(appObjects.getOrCreate("RepoID"));
        landmark.inRepo = repo;
        expect(landmark.data.parentID).toEqual("RepoID");
    });
    it("Sets the transform parent to the Repo's transform", () => {
        const { landmark, appObjects } = makeTestRig();
        const repo = makeLandmarkRepoEntity(appObjects.getOrCreate("RepoID"));
        landmark.inRepo = repo;
        expect(landmark.transform.parent).toEqual(repo.transform);
    });
    it("Sets the dto root position", () => {
        const { landmark } = makeTestRig();
        landmark.position = new Vector3(1, 2, 3);
        expect(landmark.data.position).toEqual(landmark.position.dto);
    });
    it("Sets the dto root rotation", () => {
        const { landmark } = makeTestRig();
        landmark.rotation = Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30));
        expect(landmark.data.rotation).toEqual(landmark.rotation.dto);
    });
    it("Sets the dto size", () => {
        const { landmark } = makeTestRig();
        landmark.size = 2;
        expect(landmark.data.size).toEqual(2);
    });
    it("Sets the dto label", () => {
        const { landmark } = makeTestRig();
        landmark.label.custom = "custom label";
        expect(landmark.data.label).toEqual("custom label");
    });
    it("Sets the dto default label", () => {
        const { landmark } = makeTestRig();
        landmark.label.default = "default label";
        expect(landmark.data.defaultLabel).toEqual("default label");
    });
    it("Applies the dto label", () => {
        const { landmark } = makeTestRig();
        landmark.data = {
            id: "landmarkID",
            parentID: "meshId",
            position: new Vector3(1, 2, 3).dto,
            rotation: Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30)).dto,
            defaultLabel: "default label",
            label: "custom label",
            size: 5,
            color: OverlayColorEnums.BLUE,
        };
        expect(landmark.label.custom).toEqual("custom label");
    });
    it("Applies the dto default label", () => {
        const { landmark } = makeTestRig();
        landmark.data = {
            id: "landmarkID",
            parentID: "meshId",
            position: new Vector3(1, 2, 3).dto,
            rotation: Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30)).dto,
            defaultLabel: "default label",
            label: "custom label",
            size: 5,
            color: OverlayColorEnums.BLUE,
        };
        expect(landmark.label.default).toEqual("default label");
    });
});
//# sourceMappingURL=LandmarkEntity.test.js.map