import { makeAppObjectRepo } from "@vived/core";
import { makeBabylonEntity } from "./BabylonEntity";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appObj = appObjects.getOrCreate("appObj");
    const babylon = makeBabylonEntity(appObj);
    const observer = jest.fn();
    babylon.addChangeObserver(observer);
    return { babylon, observer };
}
describe("Babylon Entity", () => {
    it("Notifies when show inspector changes", () => {
        const { babylon, observer } = makeTestRig();
        expect(babylon.showInspector).toEqual(false);
        babylon.showInspector = true;
        babylon.showInspector = true;
        babylon.showInspector = true;
        expect(babylon.showInspector).toEqual(true);
        expect(observer).toHaveBeenCalledTimes(1);
        babylon.showInspector = false;
        expect(babylon.showInspector).toEqual(false);
        expect(observer).toHaveBeenCalledTimes(2);
    });
    it("Notifies when is running changes", () => {
        const { babylon, observer } = makeTestRig();
        expect(babylon.showInspector).toEqual(false);
        babylon.isRendering = true;
        babylon.isRendering = true;
        babylon.isRendering = true;
        expect(babylon.isRendering).toEqual(true);
        expect(observer).toHaveBeenCalledTimes(1);
        babylon.isRendering = false;
        expect(babylon.isRendering).toEqual(false);
        expect(observer).toHaveBeenCalledTimes(2);
    });
    it("Forms app object meta", () => {
        const { babylon } = makeTestRig();
        const meta = babylon.makeAppObjectMeta("objectID");
        expect(meta).toEqual({ appObjectID: "objectID" });
    });
    it("Get app object ID", () => {
        const { babylon } = makeTestRig();
        const meta = { appObjectID: "objectID" };
        expect(babylon.getAppObjectIDFromMeta(meta)).toEqual("objectID");
        expect(babylon.getAppObjectIDFromMeta({ foo: "bar" })).toBeUndefined();
    });
    it("Notifies when the working canvas changes", () => {
        const { babylon, observer } = makeTestRig();
        const canvas = document.createElement("canvas");
        expect(babylon.workingCanvas).toBeUndefined();
        babylon.workingCanvas = canvas;
        babylon.workingCanvas = canvas;
        babylon.workingCanvas = canvas;
        expect(babylon.workingCanvas).toEqual(canvas);
        expect(observer).toHaveBeenCalledTimes(1);
        babylon.workingCanvas = undefined;
        babylon.workingCanvas = undefined;
        babylon.workingCanvas = undefined;
        expect(babylon.workingCanvas).toBeUndefined();
        expect(observer).toHaveBeenCalledTimes(2);
    });
    it("Notifies when the render canvas changes", () => {
        const { babylon, observer } = makeTestRig();
        const canvas = document.createElement("canvas");
        expect(babylon.renderCanvas).toBeUndefined();
        babylon.renderCanvas = canvas;
        babylon.renderCanvas = canvas;
        babylon.renderCanvas = canvas;
        expect(babylon.renderCanvas).toEqual(canvas);
        expect(observer).toHaveBeenCalledTimes(1);
        babylon.renderCanvas = undefined;
        babylon.renderCanvas = undefined;
        babylon.renderCanvas = undefined;
        expect(babylon.renderCanvas).toBeUndefined();
        expect(observer).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=BabylonEntity.test.js.map