"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const GlbModelEntity_1 = require("./GlbModelEntity");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const sceneModel = (0, GlbModelEntity_1.makeGlbModelEntity)(appObjects.getOrCreate("modelID"));
    const observer = jest.fn();
    sceneModel.addChangeObserver(observer);
    return { sceneModel, observer, appObjects };
}
describe("GLB Model Entity", () => {
    it("Sets the id", () => {
        const { sceneModel } = makeTestRig();
        expect(sceneModel.id).toEqual("modelID");
    });
    it("Notifies when the state changes", () => {
        const { sceneModel, observer } = makeTestRig();
        expect(sceneModel.state).toEqual(GlbModelEntity_1.GlbModelState.INIT);
        sceneModel.state = GlbModelEntity_1.GlbModelState.LOADING;
        expect(sceneModel.state).toEqual(GlbModelEntity_1.GlbModelState.LOADING);
        expect(observer).toHaveBeenCalled();
    });
    it("Does not notify if there is no change in the state", () => {
        const { sceneModel, observer } = makeTestRig();
        expect(sceneModel.state).toEqual(GlbModelEntity_1.GlbModelState.INIT);
        sceneModel.state = GlbModelEntity_1.GlbModelState.INIT;
        sceneModel.state = GlbModelEntity_1.GlbModelState.INIT;
        sceneModel.state = GlbModelEntity_1.GlbModelState.INIT;
        sceneModel.state = GlbModelEntity_1.GlbModelState.INIT;
        expect(observer).not.toHaveBeenCalled();
    });
    it("Sets an error", () => {
        const { sceneModel, observer } = makeTestRig();
        expect(sceneModel.state).toEqual(GlbModelEntity_1.GlbModelState.INIT);
        expect(sceneModel.modelError).toBeUndefined();
        const e = new Error("Some Error");
        sceneModel.modelError = e;
        expect(observer).toHaveBeenCalled();
        expect(sceneModel.state).toEqual(GlbModelEntity_1.GlbModelState.ERROR);
        expect(sceneModel.modelError).toEqual(e);
    });
    it("Allows a mesh to be added", () => {
        const { sceneModel } = makeTestRig();
        expect(sceneModel.hasMesh("mesh1Path")).toEqual(false);
        sceneModel.addMesh({
            mesh: {},
            name: "meshName",
            path: "mesh1Path",
        });
        expect(sceneModel.hasMesh("mesh1Path")).toEqual(true);
    });
    it("Gets a mesh object by its path", () => {
        const { sceneModel } = makeTestRig();
        const mesh = {
            mesh: {},
            name: "meshName",
            path: "mesh1Path",
        };
        sceneModel.addMesh(mesh);
        expect(sceneModel.getMesh("mesh1Path")).toEqual(mesh);
    });
    it("Returns undefined when getting an unknown mesh path", () => {
        const { sceneModel } = makeTestRig();
        expect(sceneModel.getMesh("unknown")).toBeUndefined();
    });
    it("Gets all the meshes", () => {
        const { sceneModel } = makeTestRig();
        const mesh = {
            mesh: {},
            name: "meshName",
            path: "mesh1Path",
        };
        sceneModel.addMesh(mesh);
        expect(sceneModel.getAllMeshes()).toEqual([mesh]);
    });
});
//# sourceMappingURL=GlbModelEntity.test.js.map