"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Mocks_1 = require("../../Babylon/Mocks");
const Tools_1 = require("../../Tools");
const CreateCalloutUcMock_1 = require("../Mocks/CreateCalloutUcMock");
const CreateCalloutUC_1 = require("./CreateCalloutUC");
const TryAddCallout_1 = require("./TryAddCallout");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const createCalloutAO = appObjects.getOrCreate("createCalloutAO");
    const mockSceneRayPick = (0, Mocks_1.makeMockSceneRayPickUC)(appObjects);
    const mockPick = jest.fn().mockReturnValue({
        worldPickPoint: new core_1.Vector3(1, 2, 3),
        hit: true,
        normal: new core_1.Vector3(4, 5, 6),
        objectPickMeta: {
            appObjectID: "appObj1",
        },
    });
    mockSceneRayPick.sceneRayPick = mockPick;
    const calloutAO = appObjects.getOrCreate("appObj1");
    const mockCreate = new CreateCalloutUcMock_1.CreateCalloutUcMock(calloutAO);
    mockCreate.fromPick.mockReturnValue(appObjects.getOrCreate("appObj2"));
    const mockPixelToRay = (0, Mocks_1.makeMockPixelToSceneRayUC)(appObjects);
    const tryAddUC = (0, TryAddCallout_1.makeTryAddCalloutUC)(createCalloutAO);
    const toolRepo = (0, Tools_1.makeToolRepo)(appObjects.getOrCreate("ToolRepo"));
    toolRepo.makeTool("CALLOUT");
    toolRepo.makeTool("OTHER");
    toolRepo.triggerTool("CALLOUT");
    return {
        tryAddUC,
        mockPick,
        mockCreate,
        calloutAO,
        appObjects,
        mockPixelToRay,
        toolRepo,
    };
}
describe("Try Add Callout UC", () => {
    it("Forms the pixel into a ray and passed it to the initialize with ray", () => {
        const { mockPixelToRay, tryAddUC } = makeTestRig();
        const mockRay = core_1.ParametricLine.FromTwoPoint(new core_1.Vector3(1, 2, 3), new core_1.Vector3(4, 5, 6));
        mockPixelToRay.pixelToSceneRay.mockReturnValue(mockRay);
        tryAddUC.initializeWithRay = jest.fn();
        tryAddUC.initializeWithPixel(new core_1.Vector2(7, 8));
        expect(mockPixelToRay.pixelToSceneRay).toHaveBeenCalledWith(new core_1.Vector2(7, 8));
        expect(tryAddUC.initializeWithRay).toHaveBeenCalledWith(mockRay);
    });
    it("Forms the pixel into a ray and passed it to the move with ray", () => {
        const { mockPixelToRay, tryAddUC } = makeTestRig();
        const mockRay = core_1.ParametricLine.FromTwoPoint(new core_1.Vector3(1, 2, 3), new core_1.Vector3(4, 5, 6));
        mockPixelToRay.pixelToSceneRay.mockReturnValue(mockRay);
        tryAddUC.moveWithRay = jest.fn();
        tryAddUC.moveWithPixel(new core_1.Vector2(7, 8));
        expect(mockPixelToRay.pixelToSceneRay).toHaveBeenCalledWith(new core_1.Vector2(7, 8));
        expect(tryAddUC.moveWithRay).toHaveBeenCalledWith(mockRay);
    });
    it("Returns false if not allowed", () => {
        const { tryAddUC } = makeTestRig();
        tryAddUC.allow = () => {
            return false;
        };
        expect(tryAddUC.initializeWithRay(core_1.ParametricLine.Forward())).toEqual(false);
    });
    it("Returns false if the pick is not on anything", () => {
        const { mockPick, tryAddUC } = makeTestRig();
        mockPick.mockReturnValue(undefined);
        expect(tryAddUC.initializeWithRay(core_1.ParametricLine.Forward())).toEqual(false);
    });
    it("Returns false if it can't find the app object", () => {
        const { tryAddUC, appObjects } = makeTestRig();
        appObjects.remove("appObj1");
        expect(tryAddUC.initializeWithRay(core_1.ParametricLine.Forward())).toEqual(false);
    });
    it("Returns false if it can't find Create UC on the app object", () => {
        const { tryAddUC, calloutAO } = makeTestRig();
        calloutAO.removeComponent(CreateCalloutUC_1.CreateCalloutUC.type);
        expect(tryAddUC.initializeWithRay(core_1.ParametricLine.Forward())).toEqual(false);
    });
    it("Does not allow if the tool is not Callout", () => {
        const { tryAddUC, toolRepo } = makeTestRig();
        toolRepo.triggerTool("OTHER");
        expect(tryAddUC.allow()).toEqual(false);
        toolRepo.triggerTool("CALLOUT");
        expect(tryAddUC.allow()).toEqual(true);
    });
});
//# sourceMappingURL=TryAddCallout.test.js.map