"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 Mocks_1 = require("../Mocks");
const TryPanTransformUC_1 = require("./TryPanTransformUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const tryDragAO = appObjects.getOrCreate("tryDragAO");
    const uc = (0, TryPanTransformUC_1.makeTryPanTransformUC)(tryDragAO);
    const appObj = appObjects.getOrCreate("appObj");
    const screenPeelUC = new Mocks_1.MockPanTransformUC(appObj);
    const mockPixelToRay = (0, Babylon_1.makeMockPixelToSceneRayUC)(appObjects);
    const mockPick = (0, Babylon_1.makeMockSceneRayPickUC)(appObjects).sceneRayPick;
    const mockPickResult = {
        hit: true,
        worldPickPoint: new core_2.Vector3(1, 2, 3),
        appObjectID: "appObj",
    };
    mockPick.mockReturnValue(mockPickResult);
    return { appObjects, uc, mockPickResult, screenPeelUC, mockPixelToRay };
}
describe("Default Try Screen Drag Transform UC", () => {
    it("Returns true if the initialization is successful", () => {
        const { uc } = makeTestRig();
        expect(uc.tryWithRay(core_2.ParametricLine.Forward())).toEqual(true);
    });
    it("Returns false if the pick doesn't return an app id", () => {
        const { mockPickResult, uc } = makeTestRig();
        mockPickResult.appObjectID = undefined;
        expect(uc.tryWithRay(core_2.ParametricLine.Forward())).toEqual(false);
    });
    it("Returns false if the picked app object doesn't have a ScreenPeelTransformUC", () => {
        const { mockPickResult, uc } = makeTestRig();
        mockPickResult.appObjectID = "somethingElse";
        expect(uc.tryWithRay(core_2.ParametricLine.Forward())).toEqual(false);
    });
    it("Initializes the peel UC", () => {
        const { uc, screenPeelUC } = makeTestRig();
        uc.tryWithRay(core_2.ParametricLine.Forward());
        expect(screenPeelUC.initializeRay).toHaveBeenCalledWith(core_2.ParametricLine.Forward());
    });
    it("Updates the screenPeelUC", () => {
        const { uc, screenPeelUC } = makeTestRig();
        uc.tryWithRay(core_2.ParametricLine.Forward());
        uc.moveWithRay(core_2.ParametricLine.Forward());
        expect(screenPeelUC.updateRay).toHaveBeenCalledWith(core_2.ParametricLine.Forward());
    });
    it("Doesn't update if the init did not happen the screenPeelUC", () => {
        const { uc, screenPeelUC } = makeTestRig();
        uc.moveWithRay(core_2.ParametricLine.Forward());
        expect(screenPeelUC.updateRay).not.toHaveBeenCalled();
    });
    it("Stop the UC", () => {
        const { uc, screenPeelUC } = makeTestRig();
        uc.tryWithRay(core_2.ParametricLine.Forward());
        uc.stop();
        expect(screenPeelUC.finish).toHaveBeenCalled();
    });
    it("Doesn't stop if the init did not happen the screenPeelUC", () => {
        const { uc, screenPeelUC } = makeTestRig();
        uc.stop();
        expect(screenPeelUC.finish).not.toHaveBeenCalled();
    });
    it("Cancels the UC", () => {
        const { uc, screenPeelUC } = makeTestRig();
        uc.tryWithRay(core_2.ParametricLine.Forward());
        uc.cancel();
        expect(screenPeelUC.cancelPan).toHaveBeenCalled();
    });
    it("Doesn't cancel if the init did not happen the screenPeelUC", () => {
        const { uc, screenPeelUC } = makeTestRig();
        uc.cancel();
        expect(screenPeelUC.cancelPan).not.toHaveBeenCalled();
    });
    it("Doesn't update or stop after a cancel", () => {
        const { uc, screenPeelUC } = makeTestRig();
        uc.tryWithRay(core_2.ParametricLine.Forward());
        uc.cancel();
        uc.moveWithRay(core_2.ParametricLine.Forward());
        uc.stop();
        expect(screenPeelUC.updateRay).not.toHaveBeenCalled();
        expect(screenPeelUC.finish).not.toHaveBeenCalled();
    });
    it("Doesn't update or stop if not allowed", () => {
        const { uc, screenPeelUC } = makeTestRig();
        uc.allow = () => {
            return false;
        };
        uc.tryWithRay(core_2.ParametricLine.Forward());
        uc.moveWithRay(core_2.ParametricLine.Forward());
        uc.stop();
        expect(screenPeelUC.updateRay).not.toHaveBeenCalled();
        expect(screenPeelUC.finish).not.toHaveBeenCalled();
    });
    it("Forms the ray and initializes with it when a pixel is passed in", () => {
        const { uc, mockPixelToRay } = makeTestRig();
        const initSpy = jest.spyOn(uc, "tryWithRay");
        const ray = core_2.ParametricLine.FromTwoPoint(new core_2.Vector3(1, 2, 3), new core_2.Vector3(4, 5, 6));
        mockPixelToRay.pixelToSceneRay.mockReturnValue(ray);
        uc.tryWithPixel(new core_2.Vector2(8, 9));
        expect(mockPixelToRay.pixelToSceneRay).toHaveBeenCalledWith(new core_2.Vector2(8, 9));
        expect(initSpy).toHaveBeenCalledWith(ray);
    });
    it("Forms the ray and moves with it when a pixel is passed in", () => {
        const { uc, mockPixelToRay } = makeTestRig();
        const moveSpy = jest.spyOn(uc, "moveWithRay");
        const ray = core_2.ParametricLine.FromTwoPoint(new core_2.Vector3(1, 2, 3), new core_2.Vector3(4, 5, 6));
        mockPixelToRay.pixelToSceneRay.mockReturnValue(ray);
        uc.moveWithPixel(new core_2.Vector2(8, 9));
        expect(mockPixelToRay.pixelToSceneRay).toHaveBeenCalledWith(new core_2.Vector2(8, 9));
        expect(moveSpy).toHaveBeenCalledWith(ray);
    });
});
//# sourceMappingURL=TryPanTransformUC.test.js.map