import { makeAppObjectRepo, ParametricLine, Vector2, Vector3, } from "@vived/core";
import { makeMockPixelToSceneRayUC, makeMockSceneRayPickUC, } from "../../Babylon/Mocks";
import { makeToolRepo } from "../../Tools";
import { CreateCalloutUcMock } from "../Mocks/CreateCalloutUcMock";
import { CreateCalloutUC } from "./CreateCalloutUC";
import { makeTryAddCalloutUC } from "./TryAddCallout";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const createCalloutAO = appObjects.getOrCreate("createCalloutAO");
    const mockSceneRayPick = makeMockSceneRayPickUC(appObjects);
    const mockPick = jest.fn().mockReturnValue({
        worldPickPoint: new Vector3(1, 2, 3),
        hit: true,
        normal: new Vector3(4, 5, 6),
        objectPickMeta: {
            appObjectID: "appObj1",
        },
    });
    mockSceneRayPick.sceneRayPick = mockPick;
    const calloutAO = appObjects.getOrCreate("appObj1");
    const mockCreate = new CreateCalloutUcMock(calloutAO);
    mockCreate.fromPick.mockReturnValue(appObjects.getOrCreate("appObj2"));
    const mockPixelToRay = makeMockPixelToSceneRayUC(appObjects);
    const tryAddUC = makeTryAddCalloutUC(createCalloutAO);
    const toolRepo = 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 = ParametricLine.FromTwoPoint(new Vector3(1, 2, 3), new Vector3(4, 5, 6));
        mockPixelToRay.pixelToSceneRay.mockReturnValue(mockRay);
        tryAddUC.initializeWithRay = jest.fn();
        tryAddUC.initializeWithPixel(new Vector2(7, 8));
        expect(mockPixelToRay.pixelToSceneRay).toHaveBeenCalledWith(new 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 = ParametricLine.FromTwoPoint(new Vector3(1, 2, 3), new Vector3(4, 5, 6));
        mockPixelToRay.pixelToSceneRay.mockReturnValue(mockRay);
        tryAddUC.moveWithRay = jest.fn();
        tryAddUC.moveWithPixel(new Vector2(7, 8));
        expect(mockPixelToRay.pixelToSceneRay).toHaveBeenCalledWith(new Vector2(7, 8));
        expect(tryAddUC.moveWithRay).toHaveBeenCalledWith(mockRay);
    });
    it("Returns false if not allowed", () => {
        const { tryAddUC } = makeTestRig();
        tryAddUC.allow = () => {
            return false;
        };
        expect(tryAddUC.initializeWithRay(ParametricLine.Forward())).toEqual(false);
    });
    it("Returns false if the pick is not on anything", () => {
        const { mockPick, tryAddUC } = makeTestRig();
        mockPick.mockReturnValue(undefined);
        expect(tryAddUC.initializeWithRay(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(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.type);
        expect(tryAddUC.initializeWithRay(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