import { makeAppObjectRepo } from "@vived/core";
import { makeStylusEntity } from "../../../Stylus";
import { MockTryMoveTransformUC } from "../../Mocks/MockTryMoveTransformUC";
import { MoveTransformSC } from "./MoveTransformSC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const stylus = makeStylusEntity(appObjects.getOrCreate("Stylus"));
    const registerSpy = jest.spyOn(stylus, "registerController");
    const ao = appObjects.getOrCreate("AO");
    const mockUC = new MockTryMoveTransformUC(ao);
    mockUC.tryWithRay.mockReturnValue(true);
    const controller = new MoveTransformSC(ao);
    return { mockUC, controller, registerSpy };
}
describe("Pan Scene Root Stylus Controller", () => {
    it("Registers", () => {
        const { registerSpy, controller } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(controller);
    });
    it("Initializes on press", () => {
        const { mockUC, controller } = makeTestRig();
        controller.onButtonDown(0);
        expect(mockUC.tryWithRay).toHaveBeenCalled();
    });
    it("Does not initialize if not allowed", () => {
        const { mockUC, controller } = makeTestRig();
        controller.allow = () => {
            return false;
        };
        controller.onButtonDown(0);
        expect(mockUC.tryWithRay).not.toHaveBeenCalled();
    });
    it("Updates on move after an successful press", () => {
        const { mockUC, controller } = makeTestRig();
        controller.onButtonDown(0);
        controller.onStylusMove();
        expect(mockUC.moveWithRay).toHaveBeenCalled();
    });
    it("Does not updates if the try uc returns false", () => {
        const { mockUC, controller } = makeTestRig();
        mockUC.tryWithRay.mockReturnValue(false);
        controller.onButtonDown(0);
        controller.onStylusMove();
        expect(mockUC.moveWithRay).not.toHaveBeenCalled();
    });
    it("Does not updates if not initialized", () => {
        const { mockUC, controller } = makeTestRig();
        controller.onStylusMove();
        expect(mockUC.moveWithRay).not.toHaveBeenCalled();
    });
    it("Ends after an successful press", () => {
        const { mockUC, controller } = makeTestRig();
        controller.onButtonDown(0);
        controller.onButtonUp();
        expect(mockUC.stop).toHaveBeenCalled();
    });
    it("Does not end if press was not initialized", () => {
        const { mockUC, controller } = makeTestRig();
        controller.onStylusMove();
        controller.onButtonUp();
        expect(mockUC.stop).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=MoveTransformSC.test.js.map