"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const RenderCanvasUC_1 = require("./RenderCanvasUC");
const MockKeyboardInput_1 = require("../../KeyboardInput/Mocks/MockKeyboardInput");
const MockMouseInput_1 = require("../../MouseInput/Mocks/MockMouseInput");
const MockTouchInput_1 = require("../../TouchController/Mock/MockTouchInput");
const Babylon_1 = require("../../Babylon");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const app = appObjects.getOrCreate("App");
    const renderUC = (0, RenderCanvasUC_1.makeRenderCanvasUC)(app);
    const mockKeybaord = new MockKeyboardInput_1.MockKeyboardInput(app);
    const mockBabylon = (0, Babylon_1.makeMockBabylonRenderingUC)(appObjects);
    const mockMouse = new MockMouseInput_1.MockMouseInput(app);
    const mockTouch = new MockTouchInput_1.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_1.RenderCanvasUC.get(appObjects)).toEqual(renderUC);
    });
    it("Warns and returns undefined if there is no UC", () => {
        const { renderUC, appObjects, mockWarn } = makeTestRig();
        renderUC.dispose();
        expect(RenderCanvasUC_1.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");
        (0, RenderCanvasUC_1.makeRenderCanvasUC)(newAO);
        expect(RenderCanvasUC_1.RenderCanvasUC.get(appObjects)).not.toBeUndefined();
        expect(mockWarn).toHaveBeenCalled();
    });
});
//# sourceMappingURL=RenderCanvasUC.test.js.map