import { makeAppObjectRepo } from "@vived/core";
import { Vector2 } from "@vived/core";
import { makeMouseInput } from "../../MouseInput";
import { makeHoverLabelEntity } from "../Entities/HoverLabelEntity";
import { makeMockTryShowHoverLabelUC } from "../Mocks/MockTryShowHoverLabelUC";
import { makeHoverLabelMouse } from "./HoverLabelMouse";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appObject = appObjects.getOrCreate("AppObject");
    const hoverLabel = makeHoverLabelEntity(appObject);
    makeMouseInput(appObject);
    const mockTryShowHoverLabelUC = makeMockTryShowHoverLabelUC(appObjects);
    const controller = makeHoverLabelMouse(appObject);
    return { hoverLabel, controller, mockTryShowHoverLabelUC };
}
describe("Hover Label Mouse Controller", () => {
    it("Clears any hover labels whenver the mouse moves", () => {
        const { hoverLabel, controller } = makeTestRig();
        const mockHideLabel = jest.fn();
        hoverLabel.hideHoverLabel = mockHideLabel;
        const event = {
            button: -1,
            position: Vector2.Zero(),
            event: new MouseEvent(""),
        };
        controller.onMove(event);
        expect(mockHideLabel).toHaveBeenCalled();
    });
    it("Waits and then calls the try hover label UC", () => {
        jest.useFakeTimers();
        const { controller, mockTryShowHoverLabelUC } = makeTestRig();
        const event = {
            button: -1,
            position: new Vector2(5, 6),
            event: new MouseEvent(""),
        };
        controller.onMove(event);
        jest.advanceTimersByTime(controller.hoverLabelDelay * 0.9);
        expect(mockTryShowHoverLabelUC.tryShowScreenHoverLabel).not.toHaveBeenCalled();
        jest.advanceTimersByTime(controller.hoverLabelDelay * 0.15);
        expect(mockTryShowHoverLabelUC.tryShowScreenHoverLabel).toHaveBeenCalledWith(new Vector2(5, 6));
    });
    it("Resets the delay if the mouse moves", () => {
        jest.useFakeTimers();
        const { controller, mockTryShowHoverLabelUC } = makeTestRig();
        const mouseEvent = {
            button: -1,
            position: new Vector2(5, 6),
            event: new MouseEvent(""),
        };
        controller.onMove(mouseEvent);
        jest.advanceTimersByTime(controller.hoverLabelDelay * 0.9);
        expect(mockTryShowHoverLabelUC.tryShowScreenHoverLabel).not.toHaveBeenCalled();
        mouseEvent.position = new Vector2(50, 60);
        controller.onMove(mouseEvent);
        jest.advanceTimersByTime(controller.hoverLabelDelay * 0.9);
        expect(mockTryShowHoverLabelUC.tryShowScreenHoverLabel).not.toHaveBeenCalled();
        jest.advanceTimersByTime(controller.hoverLabelDelay * 0.1);
        expect(mockTryShowHoverLabelUC.tryShowScreenHoverLabel).toHaveBeenCalledWith(new Vector2(50, 60));
    });
});
//# sourceMappingURL=HoverLabelMouse.test.js.map