"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const ChannelModelObject_1 = require("../Entities/ChannelModelObject");
const ChannelModelObjectPM_1 = require("./ChannelModelObjectPM");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("AO");
    const modelObject = (0, ChannelModelObject_1.makeChannelModelObject)(ao);
    const addObserverSpy = jest.spyOn(modelObject, "addChangeObserver");
    const pm = (0, ChannelModelObjectPM_1.makeChannelModelObjectPM)(ao);
    return { appObjects, ao, modelObject, pm, addObserverSpy };
}
describe("Channel Model Object PM", () => {
    it("Registers as an observer", () => {
        const { addObserverSpy } = makeTestRig();
        expect(addObserverSpy).toHaveBeenCalled();
    });
    it("Checks for equal VMs", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            label: "a label",
            labelValidationMessage: "a message",
            tags: ["tag1", "tag2"],
        };
        const vm2 = { ...vm1 };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Checks for change in the label", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            label: "a label",
            labelValidationMessage: "a message",
            tags: ["tag1", "tag2"],
        };
        const vm2 = { ...vm1, label: "CHANGED" };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for change in the label validation", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            label: "a label",
            labelValidationMessage: "a message",
            tags: ["tag1", "tag2"],
        };
        const vm2 = {
            ...vm1,
            labelValidationMessage: "CHANGED",
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for change a tag to be added", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            label: "a label",
            labelValidationMessage: "a message",
            tags: ["tag1", "tag2"],
        };
        const vm2 = {
            ...vm1,
            tags: ["tag1", "tag2", "tag3"],
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for change a tag to be removed", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            label: "a label",
            labelValidationMessage: "a message",
            tags: ["tag1", "tag2"],
        };
        const vm2 = { ...vm1, tags: ["tag1"] };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for change a tag to be changed", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            label: "a label",
            labelValidationMessage: "a message",
            tags: ["tag1", "tag2"],
        };
        const vm2 = { ...vm1, tags: ["tag1", "CHANGED"] };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Sets the label in the VM", () => {
        const { pm, modelObject } = makeTestRig();
        modelObject.label.custom = "A Label";
        expect(pm.lastVM?.label).toEqual("A Label");
    });
    it("Sets the label validation in the VM", () => {
        const { pm, modelObject } = makeTestRig();
        modelObject.label.customLabelValidator = () => {
            return "Some Validation";
        };
        modelObject.label.custom = "A Label";
        expect(pm.lastVM?.labelValidationMessage).toEqual("Some Validation");
    });
    it("Sets the tags in the VM", () => {
        const { pm, modelObject } = makeTestRig();
        modelObject.tags = ["tag1"];
        expect(pm.lastVM?.tags).toEqual(["tag1"]);
    });
    it("Initializes the VM", () => {
        const { pm } = makeTestRig();
        expect(pm.lastVM).not.toBeUndefined();
    });
    it("Gets the PM for an ID", () => {
        const { pm, ao, appObjects } = makeTestRig();
        expect(ChannelModelObjectPM_1.ChannelModelObjectPM.get(ao.id, appObjects)).toEqual(pm);
    });
});
//# sourceMappingURL=ChannelModelObjectPM.test.js.map