import { makeAppObjectRepo } from "@vived/core";
import { ParametricLine } from "@vived/core";
import { makeMockSceneRayPickUC } from "../../Babylon";
import { MockMoveTransformUC } from "../Mocks/MockMoveTransformUC";
import { makeTryMoveTransformUC } from "./TryMoveTransformUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const tryDragAO = appObjects.getOrCreate("tryDragAO");
    const uc = makeTryMoveTransformUC(tryDragAO);
    const appObj = appObjects.getOrCreate("appObj");
    const mockMoveUC = new MockMoveTransformUC(appObj);
    const mockRayPick = makeMockSceneRayPickUC(appObjects);
    const mockPick = jest.fn().mockReturnValue({ appObjectID: "hideableObj" });
    mockRayPick.sceneRayPick = mockPick;
    const mockPickResult = {
        hit: true,
        appObjectID: "appObj",
    };
    mockPick.mockReturnValue(mockPickResult);
    return { appObjects, uc, mockPickResult, mockMoveUC };
}
describe("Default Try Move Transform UC", () => {
    it("Returns true if the initialization is successful", () => {
        const { uc } = makeTestRig();
        expect(uc.tryWithRay(ParametricLine.Forward())).toEqual(true);
    });
    it("Returns false if not allowed", () => {
        const { uc } = makeTestRig();
        uc.allow = () => {
            return false;
        };
        expect(uc.tryWithRay(ParametricLine.Forward())).toEqual(false);
    });
    it("Returns false if the pick doesn't return an app id", () => {
        const { mockPickResult, uc } = makeTestRig();
        mockPickResult.appObjectID = undefined;
        expect(uc.tryWithRay(ParametricLine.Forward())).toEqual(false);
    });
    it("Returns false if the picked app object doesn't have a Move Transform UC", () => {
        const { mockPickResult, uc } = makeTestRig();
        mockPickResult.appObjectID = "somethingElse";
        expect(uc.tryWithRay(ParametricLine.Forward())).toEqual(false);
    });
    it("Updates the mockMoveUC", () => {
        const { uc, mockMoveUC } = makeTestRig();
        uc.tryWithRay(ParametricLine.Forward());
        uc.moveWithRay(ParametricLine.Forward());
        expect(mockMoveUC.update).toHaveBeenCalled();
    });
    it("Doesn't update if the init did not happen the mockMoveUC", () => {
        const { uc, mockMoveUC } = makeTestRig();
        uc.moveWithRay(ParametricLine.Forward());
        expect(mockMoveUC.update).not.toHaveBeenCalled();
    });
    it("Stop the UC", () => {
        const { uc, mockMoveUC } = makeTestRig();
        uc.tryWithRay(ParametricLine.Forward());
        uc.stop();
        expect(mockMoveUC.finish).toHaveBeenCalled();
    });
    it("Doesn't stop if the init did not happen the mockMoveUC", () => {
        const { uc, mockMoveUC } = makeTestRig();
        uc.stop();
        expect(mockMoveUC.finish).not.toHaveBeenCalled();
    });
    it("Cancels the UC", () => {
        const { uc, mockMoveUC } = makeTestRig();
        uc.tryWithRay(ParametricLine.Forward());
        uc.cancel();
        expect(mockMoveUC.cancel).toHaveBeenCalled();
    });
    it("Doesn't cancel if the init did not happen the mockMoveUC", () => {
        const { uc, mockMoveUC } = makeTestRig();
        uc.cancel();
        expect(mockMoveUC.cancel).not.toHaveBeenCalled();
    });
    it("Doesn't update or stop after a cancel", () => {
        const { uc, mockMoveUC } = makeTestRig();
        uc.tryWithRay(ParametricLine.Forward());
        uc.cancel();
        uc.moveWithRay(ParametricLine.Forward());
        uc.stop();
        expect(mockMoveUC.update).not.toHaveBeenCalled();
        expect(mockMoveUC.finish).not.toHaveBeenCalled();
    });
    it("Doesn't update or stop if not allowed", () => {
        const { uc, mockMoveUC } = makeTestRig();
        uc.allow = () => {
            return false;
        };
        uc.tryWithRay(ParametricLine.Forward());
        uc.moveWithRay(ParametricLine.Forward());
        uc.stop();
        expect(mockMoveUC.update).not.toHaveBeenCalled();
        expect(mockMoveUC.finish).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=TryMoveTransformUC.test.js.map