"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Mocks_1 = require("../../Babylon/Mocks");
const LabelDropRepo_1 = require("../Entities/LabelDropRepo");
const ToggleLabelDropTargetUC_1 = require("./ToggleLabelDropTargetUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const labelDropAO = appObjects.getOrCreate("repo");
    const repo = (0, LabelDropRepo_1.makeLabelDropRepo)(labelDropAO);
    const dropItem = repo.makeLabelDropItem("labelDropID");
    repo.editingID = "labelDropID";
    const mockRayPick = (0, Mocks_1.makeMockSceneRayPickUC)(appObjects);
    const mockPick = jest.fn().mockReturnValue({ appObjectID: "hideableObj" });
    mockRayPick.sceneRayPick = mockPick;
    const mockPixelToRay = (0, Mocks_1.makeMockPixelToSceneRayUC)(appObjects);
    const uc = (0, ToggleLabelDropTargetUC_1.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_1.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(core_2.ParametricLine.Forward());
        expect(dropItem.targetIds).toEqual(["target1"]);
        uc.tryToggleFromRay(core_2.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 = core_2.ParametricLine.FromTwoPoint(new core_2.Vector3(1, 2, 3), new core_2.Vector3(4, 5, 6));
        mockPixelToRay.pixelToSceneRay.mockReturnValue(mockRay);
        uc.tryToggleFromPixel(new core_2.Vector2(7, 8));
        expect(mockPixelToRay.pixelToSceneRay).toHaveBeenCalledWith(new core_2.Vector2(7, 8));
        expect(uc.tryToggleFromRay).toHaveBeenCalledWith(mockRay);
    });
});
//# sourceMappingURL=ToggleLabelDropTargetUC.test.js.map