"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Entities_1 = require("../Entities");
const ActiveModelObjectListPM_1 = require("./ActiveModelObjectListPM");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const demo = appObjects.getOrCreate("demo");
    const repo = (0, Entities_1.makeChannelModelRepo)(demo);
    const pm = (0, ActiveModelObjectListPM_1.makeActiveModelObjectListPM)(demo);
    const model = repo.createChannelModel();
    model.addModelObject("obj1");
    model.addModelObject("obj2");
    return { repo, pm, appObjects, registerSpy, model };
}
describe("Demo App Presentation Manager", () => {
    it("Gets the singleton", () => {
        const { pm, appObjects } = makeTestRig();
        expect(ActiveModelObjectListPM_1.ActiveModelObjectListPM.get(appObjects)).toEqual(pm);
    });
    it("Registers as the singleton", () => {
        const { pm, registerSpy } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(pm);
    });
    it("Initializes correctly", () => {
        const { pm } = makeTestRig();
        expect(pm.lastVM).not.toBeUndefined();
    });
    it("Checks for equal VMs", () => {
        const { pm } = makeTestRig();
        const vm1 = ["obj1", "obj2"];
        const vm2 = [...vm1];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Checks for equal an object to be added", () => {
        const { pm } = makeTestRig();
        const vm1 = ["obj1", "obj2"];
        const vm2 = [...vm1, "obj3"];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for equal an object to be removed", () => {
        const { pm } = makeTestRig();
        const vm1 = ["obj1", "obj2"];
        const vm2 = ["obj1"];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for equal an object to be renamed", () => {
        const { pm } = makeTestRig();
        const vm1 = ["obj1", "obj2"];
        const vm2 = ["obj1", "CHANGED"];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Sets the VM to the active model objects", () => {
        const { pm, repo } = makeTestRig();
        const model = repo.createChannelModel();
        model.addModelObject("obj1");
        model.addModelObject("obj2");
        expect(pm.lastVM).toEqual([]);
        repo.activeModel = model.id;
        expect(pm.lastVM).toEqual(["obj1", "obj2"]);
    });
    it("Sets the VM if the active model is cleared", () => {
        const { pm, repo } = makeTestRig();
        const model = repo.createChannelModel();
        model.addModelObject("obj1");
        model.addModelObject("obj2");
        repo.activeModel = model.id;
        expect(pm.lastVM).toEqual(["obj1", "obj2"]);
        repo.activeModel = "";
        expect(pm.lastVM).toEqual([]);
    });
    it("Updates the VM when the model changes", () => {
        const { pm, repo } = makeTestRig();
        const model = repo.createChannelModel();
        model.addModelObject("obj1");
        model.addModelObject("obj2");
        repo.activeModel = model.id;
        expect(pm.lastVM).toEqual(["obj1", "obj2"]);
        const model2 = repo.createChannelModel();
        model2.addModelObject("differentObj1");
        model2.addModelObject("differentObj2");
        repo.activeModel = model2.id;
        expect(pm.lastVM).toEqual(["differentObj1", "differentObj2"]);
    });
});
//# sourceMappingURL=ActiveModelObjectListPM.test.js.map