"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const LabelEntity_1 = require("../../Label/Entities/LabelEntity");
const OverlayColor_1 = require("../../OverlayColor/Entities/OverlayColor");
const CalloutGlobals_1 = require("../Entities/CalloutGlobals");
const CalloutRepo_1 = require("../Entities/CalloutRepo");
const CreateCalloutUC_1 = require("./CreateCalloutUC");
const CreateCalloutUndoRedo_1 = require("./CreateCalloutUndoRedo");
jest.mock("./CreateCalloutUndoRedo");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const calloutGlobals = (0, CalloutGlobals_1.makeCalloutGlobals)(appObjects.getOrCreate("CalloutGlobals"));
    const repoObj = appObjects.getOrCreate("repoObj");
    const repo = (0, CalloutRepo_1.makeCalloutRepoEntity)(repoObj);
    const label = (0, LabelEntity_1.makeLabelEntity)(repoObj);
    label.default = "a sick default label";
    const uc = (0, CreateCalloutUC_1.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_1.CreateCalloutUC.get(repoObj)).toEqual(uc);
    });
    it("Gets the UC by ID", () => {
        const { appObjects, uc } = makeTestRig();
        expect(CreateCalloutUC_1.CreateCalloutUC.getById("repoObj", appObjects)).toEqual(uc);
    });
    it("Sets the root position to the world pick point", () => {
        const { uc } = makeTestRig();
        const newCallout = uc.fromPick(new core_1.Vector3(1, 2, 3), core_1.Vector3.One());
        expect(newCallout?.rootTransform.worldPosition).toEqual(new core_1.Vector3(1, 2, 3));
    });
    it("Sets the root world rotation to the pick normal", () => {
        const { uc } = makeTestRig();
        const newCallout = uc.fromPick(core_1.Vector3.One(), new core_1.Vector3(1, 2, 3));
        const expectRot = core_1.Quaternion.FromDirectionVector(new core_1.Vector3(1, 2, 3));
        expect(core_1.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 core_1.Vector3(1, 2, 3);
        const pickNormal = new core_1.Vector3(4, 5, 6);
        const newCallout = uc.fromPick(pickPoint, pickNormal);
        const bumpVector = core_1.Vector3.NewVectorOfLength(pickNormal, uc.newLabelBumpAmount);
        const expectedPos = core_1.Vector3.Add(bumpVector, pickPoint);
        expect(newCallout.labelTransform.worldPosition).toEqual(expectedPos);
    });
    it("Sets the label rotation looking backwards", () => {
        const { uc } = makeTestRig();
        const newCallout = uc.fromPick(core_1.Vector3.One(), new core_1.Vector3(1, 2, 3));
        const expectRot = core_1.Quaternion.FromYawPitchRoll(core_1.Angle.FromDegrees(180), core_1.Angle.FromDegrees(0), core_1.Angle.FromDegrees(0));
        expect(core_1.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(core_1.Vector3.One(), new core_1.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(core_1.Vector3.One(), new core_1.Vector3(1, 2, 3));
        expect(newCallout.size).toEqual(1.23);
    });
    it("Sets the callout to the global color", () => {
        const { uc, calloutGlobals } = makeTestRig();
        calloutGlobals.lastColor = OverlayColor_1.OverlayColorEnums.PINK;
        const newCallout = uc.fromPick(core_1.Vector3.One(), new core_1.Vector3(1, 2, 3));
        expect(newCallout.overlayColor.overlayColor).toEqual(OverlayColor_1.OverlayColorEnums.PINK);
    });
    it("Creates an undo", () => {
        const { uc } = makeTestRig();
        uc.fromPick(core_1.Vector3.One(), new core_1.Vector3(1, 2, 3));
        expect(CreateCalloutUndoRedo_1.CreateCalloutUndoRedo).toHaveBeenCalled();
    });
});
//# sourceMappingURL=CreateCalloutUC.test.js.map