"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const MouseInput_1 = require("../../MouseInput");
const HoverLabelEntity_1 = require("../Entities/HoverLabelEntity");
const MockTryShowHoverLabelUC_1 = require("../Mocks/MockTryShowHoverLabelUC");
const HoverLabelMouse_1 = require("./HoverLabelMouse");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObject = appObjects.getOrCreate("AppObject");
    const hoverLabel = (0, HoverLabelEntity_1.makeHoverLabelEntity)(appObject);
    (0, MouseInput_1.makeMouseInput)(appObject);
    const mockTryShowHoverLabelUC = (0, MockTryShowHoverLabelUC_1.makeMockTryShowHoverLabelUC)(appObjects);
    const controller = (0, HoverLabelMouse_1.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: core_2.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 core_2.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 core_2.Vector2(5, 6));
    });
    it("Resets the delay if the mouse moves", () => {
        jest.useFakeTimers();
        const { controller, mockTryShowHoverLabelUC } = makeTestRig();
        const mouseEvent = {
            button: -1,
            position: new core_2.Vector2(5, 6),
            event: new MouseEvent(""),
        };
        controller.onMove(mouseEvent);
        jest.advanceTimersByTime(controller.hoverLabelDelay * 0.9);
        expect(mockTryShowHoverLabelUC.tryShowScreenHoverLabel).not.toHaveBeenCalled();
        mouseEvent.position = new core_2.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 core_2.Vector2(50, 60));
    });
});
//# sourceMappingURL=HoverLabelMouse.test.js.map