import { makeAppObjectRepo } from "@vived/core";
import { makeRenderCanvasUC, RenderCanvasUC } from "./RenderCanvasUC";
import { MockKeyboardInput } from "../../KeyboardInput/Mocks/MockKeyboardInput";
import { MockMouseInput } from "../../MouseInput/Mocks/MockMouseInput";
import { MockTouchInputEntity } from "../../TouchController/Mock/MockTouchInput";
import { makeMockBabylonRenderingUC } from "../../Babylon";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const app = appObjects.getOrCreate("App");
    const renderUC = makeRenderCanvasUC(app);
    const mockKeybaord = new MockKeyboardInput(app);
    const mockBabylon = makeMockBabylonRenderingUC(appObjects);
    const mockMouse = new MockMouseInput(app);
    const mockTouch = new MockTouchInputEntity(app);
    const mockWarn = jest.fn();
    appObjects.submitWarning = mockWarn;
    return {
        appObjects,
        renderUC,
        mockBabylon,
        mockKeybaord,
        mockWarn,
        mockTouch,
        mockMouse,
    };
}
describe("Render Canvas UC", () => {
    it("Submits the canvas to the keyboard input", () => {
        const { mockKeybaord, renderUC } = makeTestRig();
        const renderCanvas = document.createElement("canvas");
        renderUC.submitCanvas(renderCanvas);
        expect(mockKeybaord.setEventElement).toHaveBeenCalledWith(renderCanvas);
    });
    it("Warns if it can't find the keyboard input when a canvas is submitted", () => {
        const { mockKeybaord, renderUC, mockWarn } = makeTestRig();
        const renderCanvas = document.createElement("canvas");
        mockKeybaord.dispose();
        renderUC.submitCanvas(renderCanvas);
        expect(mockWarn).toHaveBeenCalled();
    });
    it("Clears the input element from keyboard input", () => {
        const { mockKeybaord, renderUC } = makeTestRig();
        renderUC.clearCanvas();
        expect(mockKeybaord.clearInputElement).toHaveBeenCalled();
    });
    it("Warns if it can't find the keyboard input when a canvas is cleared", () => {
        const { mockKeybaord, renderUC, mockWarn } = makeTestRig();
        mockKeybaord.dispose();
        renderUC.clearCanvas();
        expect(mockWarn).toHaveBeenCalled();
    });
    it("Submits the canvas to the mouse input", () => {
        const { mockMouse, renderUC } = makeTestRig();
        const renderCanvas = document.createElement("canvas");
        renderUC.submitCanvas(renderCanvas);
        expect(mockMouse.setEventElement).toHaveBeenCalledWith(renderCanvas);
    });
    it("Warns if it can't find the mouse input when a canvas is submitted", () => {
        const { mockMouse, renderUC, mockWarn } = makeTestRig();
        const renderCanvas = document.createElement("canvas");
        mockMouse.dispose();
        renderUC.submitCanvas(renderCanvas);
        expect(mockWarn).toHaveBeenCalled();
    });
    it("Clears the input element from mouse input", () => {
        const { mockMouse, renderUC } = makeTestRig();
        renderUC.clearCanvas();
        expect(mockMouse.clearInputElement).toHaveBeenCalled();
    });
    it("Warns if it can't find the mouse input when a canvas is cleared", () => {
        const { mockMouse, renderUC, mockWarn } = makeTestRig();
        mockMouse.dispose();
        renderUC.clearCanvas();
        expect(mockWarn).toHaveBeenCalled();
    });
    it("Submits the canvas to the touch input", () => {
        const { mockTouch, renderUC } = makeTestRig();
        const renderCanvas = document.createElement("canvas");
        renderUC.submitCanvas(renderCanvas);
        expect(mockTouch.setEventElement).toHaveBeenCalledWith(renderCanvas);
    });
    it("Warns if it can't find the touch input when a canvas is submitted", () => {
        const { mockTouch, renderUC, mockWarn } = makeTestRig();
        const renderCanvas = document.createElement("canvas");
        mockTouch.dispose();
        renderUC.submitCanvas(renderCanvas);
        expect(mockWarn).toHaveBeenCalled();
    });
    it("Clears the input element from touch input", () => {
        const { mockTouch, renderUC } = makeTestRig();
        renderUC.clearCanvas();
        expect(mockTouch.clearInputElement).toHaveBeenCalled();
    });
    it("Warns if it can't find the touch input when a canvas is cleared", () => {
        const { mockTouch, renderUC, mockWarn } = makeTestRig();
        mockTouch.dispose();
        renderUC.clearCanvas();
        expect(mockWarn).toHaveBeenCalled();
    });
    it("Submits the canvas to the babylon rendering", () => {
        const { mockBabylon, renderUC } = makeTestRig();
        const renderCanvas = document.createElement("canvas");
        renderUC.submitCanvas(renderCanvas);
        expect(mockBabylon.submitRenderCanvas).toHaveBeenCalledWith(renderCanvas);
    });
    it("Warns if it can't find the babylon rendering when a canvas is submitted", () => {
        const { mockBabylon, renderUC, mockWarn } = makeTestRig();
        const renderCanvas = document.createElement("canvas");
        mockBabylon.dispose();
        renderUC.submitCanvas(renderCanvas);
        expect(mockWarn).toHaveBeenCalled();
    });
    it("Clears the input element from babylon rendering", () => {
        const { mockBabylon, renderUC } = makeTestRig();
        renderUC.clearCanvas();
        expect(mockBabylon.clearRenderCanvas).toHaveBeenCalled();
    });
    it("Warns if it can't find the babylon rendering when a canvas is cleared", () => {
        const { mockBabylon, renderUC, mockWarn } = makeTestRig();
        mockBabylon.dispose();
        renderUC.clearCanvas();
        expect(mockWarn).toHaveBeenCalled();
    });
    it("Gets the UC", () => {
        const { renderUC, appObjects } = makeTestRig();
        expect(RenderCanvasUC.get(appObjects)).toEqual(renderUC);
    });
    it("Warns and returns undefined if there is no UC", () => {
        const { renderUC, appObjects, mockWarn } = makeTestRig();
        renderUC.dispose();
        expect(RenderCanvasUC.get(appObjects)).toBeUndefined();
        expect(mockWarn).toHaveBeenCalled();
    });
    it("Warns if there are more than two UCs found", () => {
        const { appObjects, mockWarn } = makeTestRig();
        const newAO = appObjects.getOrCreate("newAO");
        makeRenderCanvasUC(newAO);
        expect(RenderCanvasUC.get(appObjects)).not.toBeUndefined();
        expect(mockWarn).toHaveBeenCalled();
    });
});
//# sourceMappingURL=RenderCanvasUC.test.js.map