import { makeAppObjectRepo } from "@vived/core";
import { makeLabelEntity } from "../Entities/LabelEntity";
import { LabelPM, makeLabelPM } from "./LabelPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appObj = appObjects.getOrCreate("appObj");
    const labelEnt = makeLabelEntity(appObj);
    labelEnt.custom = "Hello World";
    labelEnt.default = "The Default Label";
    const pm = makeLabelPM(appObj);
    const view = jest.fn();
    pm.addView(view);
    return { appObj, appObjects, labelEnt, pm, view };
}
describe("Label Presentation Manager", () => {
    it("Sets the last vm on construction", () => {
        const { pm, labelEnt } = makeTestRig();
        expect(pm.lastVM).not.toBeUndefined();
        expect(pm.lastVM?.customLabel).toEqual(labelEnt.custom);
        expect(pm.lastVM?.defaultLabel).toEqual(labelEnt.default);
        expect(pm.lastVM?.displayLabel).toEqual(labelEnt.display);
        expect(pm.lastVM?.hasCustomLabel).toEqual(labelEnt.hasCustomLabel);
        expect(pm.lastVM?.labelValidation).toEqual(labelEnt.customLabelValidationMessage);
    });
    it("Updates the view when the label changes", () => {
        const { labelEnt, pm } = makeTestRig();
        const spy = jest.spyOn(pm, "doUpdateView");
        labelEnt.custom = "New Label";
        expect(spy).toHaveBeenCalled();
    });
    it("Can be disposed", () => {
        const { labelEnt, pm } = makeTestRig();
        pm.dispose();
        const spy = jest.spyOn(pm, "doUpdateView");
        labelEnt.custom = "New Label";
        expect(spy).not.toHaveBeenCalled();
    });
    it("Returns true if the VMs are the same", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            customLabel: "customLabel",
            defaultLabel: "defaultLabel",
            displayLabel: "displayLabel",
            hasCustomLabel: true,
            labelValidation: null,
        };
        const sameVM = { ...vm1 };
        expect(pm.vmsAreEqual(vm1, sameVM)).toEqual(true);
    });
    it("Returns false if the VMs don't have the same custom label", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            customLabel: "customLabel",
            defaultLabel: "defaultLabel",
            displayLabel: "displayLabel",
            hasCustomLabel: true,
            labelValidation: null,
        };
        const vm2 = { ...vm1 };
        vm2.customLabel = "something else";
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if the VMs don't have the same default label", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            customLabel: "customLabel",
            defaultLabel: "defaultLabel",
            displayLabel: "displayLabel",
            hasCustomLabel: true,
            labelValidation: null,
        };
        const vm2 = { ...vm1 };
        vm2.defaultLabel = "something else";
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Gets the PM for and ID", () => {
        const { appObjects, pm } = makeTestRig();
        expect(LabelPM.getForID("appObj", appObjects)).toEqual(pm);
    });
    it("Returns undefined for an unknownID", () => {
        const { appObjects } = makeTestRig();
        expect(LabelPM.getForID("Unknown", appObjects)).toBeUndefined();
    });
    it("Returns undefined for an app object without a PM", () => {
        const { appObjects } = makeTestRig();
        appObjects.getOrCreate("newObj");
        expect(LabelPM.getForID("newObj", appObjects)).toBeUndefined();
    });
});
//# sourceMappingURL=LabelPM.test.js.map