import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import React from "react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { DragHandel, DragHandelContext } from "./dragHandle";
afterEach(cleanup);
describe("DragHandle Component", () => {
    it("should render correctly", () => {
        const contextValue = {
            onPointerDown: vi.fn(),
            onResize: vi.fn(),
            columns: 2,
            rows: 2,
        };
        render(<DragHandelContext.Provider value={contextValue}>
                <DragHandel index={1} orientation="vertical"/>
            </DragHandelContext.Provider>);
        const button = screen.getByRole("button");
        expect(button).toBeTruthy();
    });
    it("should trigger onResize with arrow keys", () => {
        const onResize = vi.fn();
        const contextValue = {
            onPointerDown: vi.fn(),
            onResize,
            columns: 2,
            rows: 2,
        };
        render(<DragHandelContext.Provider value={contextValue}>
                <DragHandel index={1} orientation="vertical"/>
            </DragHandelContext.Provider>);
        const button = screen.getByRole("button");
        fireEvent.keyDown(button, { key: "ArrowRight" });
        expect(onResize).toHaveBeenCalledTimes(1);
        expect(onResize.mock.calls[0][0].movementX).toBe(8);
        fireEvent.keyDown(button, { key: "ArrowLeft" });
        expect(onResize).toHaveBeenCalledTimes(2);
        expect(onResize.mock.calls[1][0].movementX).toBe(-8);
    });
    it("should trigger onPointerDown", () => {
        const onPointerDown = vi.fn();
        const contextValue = {
            onPointerDown,
            onResize: vi.fn(),
            columns: 2,
            rows: 2,
        };
        render(<DragHandelContext.Provider value={contextValue}>
                <DragHandel index={1} orientation="vertical"/>
            </DragHandelContext.Provider>);
        const button = screen.getByRole("button");
        fireEvent.pointerDown(button);
        expect(onPointerDown).toHaveBeenCalledTimes(1);
    });
});
