import { makeAppObjectRepo } from "@vived/core";
import { ParametricLine, Vector2, Vector3 } from "@vived/core";
import { makeMockPixelToSceneRayUC, makeMockSceneRayPickUC, } from "../../Babylon/Mocks";
import { makeLabelDropRepo } from "../Entities/LabelDropRepo";
import { makeToggleLabelDropTargetUC, ToggleLabelDropTargetUC, } from "./ToggleLabelDropTargetUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const labelDropAO = appObjects.getOrCreate("repo");
    const repo = makeLabelDropRepo(labelDropAO);
    const dropItem = repo.makeLabelDropItem("labelDropID");
    repo.editingID = "labelDropID";
    const mockRayPick = makeMockSceneRayPickUC(appObjects);
    const mockPick = jest.fn().mockReturnValue({ appObjectID: "hideableObj" });
    mockRayPick.sceneRayPick = mockPick;
    const mockPixelToRay = makeMockPixelToSceneRayUC(appObjects);
    const uc = makeToggleLabelDropTargetUC(labelDropAO);
    return {
        appObjects,
        repo,
        uc,
        dropItem,
        mockPick,
        registerSpy,
        mockPixelToRay,
    };
}
describe("Toggle Label Drop Target UC", () => {
    it("Get it UC", () => {
        const { appObjects, uc } = makeTestRig();
        expect(ToggleLabelDropTargetUC.get(appObjects)).toEqual(uc);
    });
    it("Registers as the singleton", () => {
        const { uc, registerSpy } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(uc);
    });
    it("Toggles target ID", () => {
        const { uc, dropItem } = makeTestRig();
        expect(dropItem.targetIds).toEqual([]);
        uc.toggleByID("target1");
        expect(dropItem.targetIds).toEqual(["target1"]);
        uc.toggleByID("target1");
        expect(dropItem.targetIds).toEqual([]);
    });
    it("Toggles the ray picked ID", () => {
        const { uc, dropItem, mockPick } = makeTestRig();
        expect(dropItem.targetIds).toEqual([]);
        mockPick.mockReturnValue({
            appObjectID: "target1",
        });
        uc.tryToggleFromRay(ParametricLine.Forward());
        expect(dropItem.targetIds).toEqual(["target1"]);
        uc.tryToggleFromRay(ParametricLine.Forward());
        expect(dropItem.targetIds).toEqual([]);
    });
    it("Converts a pixel to a ray and then picks", () => {
        const { uc, mockPixelToRay } = makeTestRig();
        uc.tryToggleFromRay = jest.fn();
        const mockRay = ParametricLine.FromTwoPoint(new Vector3(1, 2, 3), new Vector3(4, 5, 6));
        mockPixelToRay.pixelToSceneRay.mockReturnValue(mockRay);
        uc.tryToggleFromPixel(new Vector2(7, 8));
        expect(mockPixelToRay.pixelToSceneRay).toHaveBeenCalledWith(new Vector2(7, 8));
        expect(uc.tryToggleFromRay).toHaveBeenCalledWith(mockRay);
    });
});
//# sourceMappingURL=ToggleLabelDropTargetUC.test.js.map