import { Angle, makeAppObjectRepo, Quaternion, Vector3 } from "@vived/core";
import { makeLabelEntity } from "../../Label/Entities/LabelEntity";
import { OverlayColorEnums } from "../../OverlayColor/Entities/OverlayColor";
import { makeCalloutGlobals } from "../Entities/CalloutGlobals";
import { makeCalloutRepoEntity } from "../Entities/CalloutRepo";
import { CreateCalloutUC, makeCreateCalloutUC } from "./CreateCalloutUC";
import { CreateCalloutUndoRedo } from "./CreateCalloutUndoRedo";
jest.mock("./CreateCalloutUndoRedo");
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const calloutGlobals = makeCalloutGlobals(appObjects.getOrCreate("CalloutGlobals"));
    const repoObj = appObjects.getOrCreate("repoObj");
    const repo = makeCalloutRepoEntity(repoObj);
    const label = makeLabelEntity(repoObj);
    label.default = "a sick default label";
    const uc = makeCreateCalloutUC(repoObj);
    return {
        appObjects,
        repoObj,
        repo,
        uc,
        label,
        calloutGlobals,
    };
}
describe("Create Callout UC", () => {
    it("Gets the UC off an app object", () => {
        const { repoObj, uc } = makeTestRig();
        expect(CreateCalloutUC.get(repoObj)).toEqual(uc);
    });
    it("Gets the UC by ID", () => {
        const { appObjects, uc } = makeTestRig();
        expect(CreateCalloutUC.getById("repoObj", appObjects)).toEqual(uc);
    });
    it("Sets the root position to the world pick point", () => {
        const { uc } = makeTestRig();
        const newCallout = uc.fromPick(new Vector3(1, 2, 3), Vector3.One());
        expect(newCallout?.rootTransform.worldPosition).toEqual(new Vector3(1, 2, 3));
    });
    it("Sets the root world rotation to the pick normal", () => {
        const { uc } = makeTestRig();
        const newCallout = uc.fromPick(Vector3.One(), new Vector3(1, 2, 3));
        const expectRot = Quaternion.FromDirectionVector(new Vector3(1, 2, 3));
        expect(Quaternion.Close(newCallout.rootTransform.worldRotation, expectRot)).toEqual(true);
    });
    it("Sets the label position as the pick plus a little bump along the normal", () => {
        const { uc } = makeTestRig();
        const pickPoint = new Vector3(1, 2, 3);
        const pickNormal = new Vector3(4, 5, 6);
        const newCallout = uc.fromPick(pickPoint, pickNormal);
        const bumpVector = Vector3.NewVectorOfLength(pickNormal, uc.newLabelBumpAmount);
        const expectedPos = Vector3.Add(bumpVector, pickPoint);
        expect(newCallout.labelTransform.worldPosition).toEqual(expectedPos);
    });
    it("Sets the label rotation looking backwards", () => {
        const { uc } = makeTestRig();
        const newCallout = uc.fromPick(Vector3.One(), new Vector3(1, 2, 3));
        const expectRot = Quaternion.FromYawPitchRoll(Angle.FromDegrees(180), Angle.FromDegrees(0), Angle.FromDegrees(0));
        expect(Quaternion.Close(newCallout.labelTransform.worldRotation, expectRot)).toEqual(true);
    });
    it("Sets the default label the the repo's current label", () => {
        const { uc, label } = makeTestRig();
        label.custom = "a custom label";
        const newCallout = uc.fromPick(Vector3.One(), new Vector3(1, 2, 3));
        expect(newCallout.label.default).toEqual(label.custom);
    });
    it("Sets the callout to the global size", () => {
        const { uc, calloutGlobals } = makeTestRig();
        calloutGlobals.lastSize = 1.23;
        const newCallout = uc.fromPick(Vector3.One(), new Vector3(1, 2, 3));
        expect(newCallout.size).toEqual(1.23);
    });
    it("Sets the callout to the global color", () => {
        const { uc, calloutGlobals } = makeTestRig();
        calloutGlobals.lastColor = OverlayColorEnums.PINK;
        const newCallout = uc.fromPick(Vector3.One(), new Vector3(1, 2, 3));
        expect(newCallout.overlayColor.overlayColor).toEqual(OverlayColorEnums.PINK);
    });
    it("Creates an undo", () => {
        const { uc } = makeTestRig();
        uc.fromPick(Vector3.One(), new Vector3(1, 2, 3));
        expect(CreateCalloutUndoRedo).toHaveBeenCalled();
    });
});
//# sourceMappingURL=CreateCalloutUC.test.js.map