"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const Tools_1 = require("../../Tools");
const StickUCMock_1 = require("../Mocks/StickUCMock");
const TryStickAppObjectUC_1 = require("./TryStickAppObjectUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSingleton = jest.spyOn(appObjects, "registerSingleton");
    const ao = appObjects.getOrCreate("AO");
    const uc = (0, TryStickAppObjectUC_1.makeTryStickAppObjectUC)(ao);
    const stickableObj = appObjects.getOrCreate("stickableObj");
    const mockHideUC = new StickUCMock_1.StickUCMock(stickableObj);
    const mockRayPick = (0, Babylon_1.makeMockSceneRayPickUC)(appObjects);
    const mockPick = jest.fn().mockReturnValue({ appObjectID: "stickableObj" });
    mockRayPick.sceneRayPick = mockPick;
    const mockPixelPick = (0, Babylon_1.makeMockScenePixelPickUC)(appObjects);
    mockPixelPick.scenePixelPick.mockReturnValue({ appObjectID: "stickableObj" });
    const toolRepo = (0, Tools_1.makeToolRepo)(appObjects.getOrCreate("Tool"));
    const peelTool = toolRepo.makeTool("PEEL");
    peelTool.state = Tools_1.ToolState.ACTIVE;
    return {
        appObjects,
        ao,
        mockHideUC,
        uc,
        registerSingleton,
        mockPick,
        mockPixelPick,
        peelTool,
    };
}
describe("Try Stick UC", () => {
    it("Gets the singleton", () => {
        const { appObjects, uc } = makeTestRig();
        expect(TryStickAppObjectUC_1.TryStickAppObjectUC.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.tryWithRay(pickRay);
        expect(mockPick).toHaveBeenCalledWith(pickRay);
    });
    it("Calls the UC", () => {
        const { uc, mockHideUC } = makeTestRig();
        uc.tryWithRay(core_2.ParametricLine.Forward());
        expect(mockHideUC.doStick).toHaveBeenCalled();
    });
    it("Does not call on ray pick if not allowed", () => {
        const { uc, mockHideUC } = makeTestRig();
        uc.allow = () => {
            return false;
        };
        uc.tryWithRay(core_2.ParametricLine.Forward());
        expect(mockHideUC.doStick).not.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.tryWithRay(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.tryWithPixel(pickPixel);
        expect(mockPixelPick.scenePixelPick).toHaveBeenCalledWith(pickPixel);
    });
    it("Calls the UC with a pixel pick", () => {
        const { uc, mockHideUC } = makeTestRig();
        uc.tryWithPixel(core_2.Vector2.One());
        expect(mockHideUC.doStick).toHaveBeenCalled();
    });
    it("Does not call on pixel pick if not allowed", () => {
        const { uc, mockHideUC } = makeTestRig();
        uc.allow = () => {
            return false;
        };
        uc.tryWithPixel(core_2.Vector2.One());
        expect(mockHideUC.doStick).not.toHaveBeenCalled();
    });
    it("Allows if the peel tool is active", () => {
        const { uc, peelTool } = makeTestRig();
        peelTool.state = Tools_1.ToolState.ACTIVE;
        expect(uc.allow()).toEqual(true);
        peelTool.state = Tools_1.ToolState.ENABLED;
        expect(uc.allow()).toEqual(false);
    });
});
//# sourceMappingURL=TryStickAppObjectUC.test.js.map