"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const HideUCMock_1 = require("../Mocks/HideUCMock");
const TryHideWithPickUC_1 = require("./TryHideWithPickUC");
const MockSceneRayPickUC_1 = require("../../Babylon/Mocks/MockSceneRayPickUC");
const core_2 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const Tools_1 = require("../../Tools");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSingleton = jest.spyOn(appObjects, "registerSingleton");
    const ao = appObjects.getOrCreate("AO");
    const uc = (0, TryHideWithPickUC_1.makeTryHideWithPickUC)(ao);
    const hideableObj = appObjects.getOrCreate("hideableObj");
    const mockHideUC = new HideUCMock_1.HideUCMock(hideableObj);
    const mockRayPick = (0, MockSceneRayPickUC_1.makeMockSceneRayPickUC)(appObjects);
    const mockPick = jest.fn().mockReturnValue({ appObjectID: "hideableObj" });
    mockRayPick.sceneRayPick = mockPick;
    const mockPixelPick = (0, Babylon_1.makeMockScenePixelPickUC)(appObjects);
    mockPixelPick.scenePixelPick.mockReturnValue({ appObjectID: "hideableObj" });
    const toolRepo = (0, Tools_1.makeToolRepo)(appObjects.getOrCreate("ToolRepo"));
    const hideTool = toolRepo.makeTool("HIDE");
    hideTool.state = Tools_1.ToolState.ACTIVE;
    return {
        appObjects,
        ao,
        mockHideUC,
        uc,
        registerSingleton,
        mockPick,
        mockPixelPick,
        hideTool,
    };
}
describe("Hide UC", () => {
    it("Gets the singleton", () => {
        const { appObjects, uc } = makeTestRig();
        expect(TryHideWithPickUC_1.TryHideWithPickUC.get(appObjects)).toEqual(uc);
    });
    it("Registers as the singleton", () => {
        const { registerSingleton, uc } = makeTestRig();
        expect(registerSingleton).toHaveBeenCalledWith(uc);
    });
    it("Picks with the ray", () => {
        const { uc, mockPick } = makeTestRig();
        const pickRay = core_2.ParametricLine.FromPointDirection(new core_2.Vector3(1, 2, 3), new core_2.Vector3(4, 5, 6));
        uc.tryRayPick(pickRay);
        expect(mockPick).toHaveBeenCalledWith(pickRay);
    });
    it("Calls the UC", () => {
        const { uc, mockHideUC } = makeTestRig();
        uc.tryRayPick(core_2.ParametricLine.Forward());
        expect(mockHideUC.hide).toHaveBeenCalled();
    });
    it("Doesn't warn if the picked object does not have the UC", () => {
        const { uc, mockPick, appObjects } = makeTestRig();
        appObjects.submitWarning = jest.fn();
        appObjects.getOrCreate("SomeOtherObject");
        mockPick.mockReturnValue({
            appObjectID: "SomeOtherObject",
        });
        uc.tryRayPick(core_2.ParametricLine.Forward());
        expect(appObjects.submitWarning).not.toHaveBeenCalled();
    });
    it("Picks with a pixel", () => {
        const { uc, mockPixelPick } = makeTestRig();
        const pickPixel = new core_2.Vector2(1, 2);
        uc.tryPixelPick(pickPixel);
        expect(mockPixelPick.scenePixelPick).toHaveBeenCalledWith(pickPixel);
    });
    it("Calls the UC", () => {
        const { uc, mockHideUC } = makeTestRig();
        uc.tryPixelPick(core_2.Vector2.One());
        expect(mockHideUC.hide).toHaveBeenCalled();
    });
    it("Returns true if the hide tool is active", () => {
        const { uc, hideTool } = makeTestRig();
        hideTool.state = Tools_1.ToolState.ACTIVE;
        expect(uc.allow()).toEqual(true);
    });
    it("Returns false if the hide tool is not active", () => {
        const { uc, hideTool } = makeTestRig();
        hideTool.state = Tools_1.ToolState.ENABLED;
        expect(uc.allow()).toEqual(false);
    });
});
//# sourceMappingURL=TryHideWithPickUC.test.js.map