"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Entities_1 = require("../../Label/Entities");
const LabelDropItemEntity_1 = require("../Entities/LabelDropItemEntity");
const InitializeLabelDropLabelHook_1 = require("./InitializeLabelDropLabelHook");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const labelDropAO = appObjects.getOrCreate("LabelDropAO");
    const dropLabel = new LabelDropItemEntity_1.LabelDropItemEntity(labelDropAO);
    new InitializeLabelDropLabelHook_1.InitializeLabelDropLabelHook(labelDropAO);
    const appObj1 = appObjects.getOrCreate("obj1");
    const labelEntity = (0, Entities_1.makeLabelEntity)(appObj1);
    labelEntity.custom = "App Object Label";
    return {
        labelDropAO,
        dropLabel,
    };
}
describe("Initialize Label Drop Label Hook", () => {
    it("Sets new label to label drop answer if label is undefined and there is a target id", () => {
        const { dropLabel } = makeTestRig();
        expect(dropLabel.label).toEqual("");
        dropLabel.addTargetID("obj1");
        expect(dropLabel.label).toEqual("App Object Label");
    });
    it("Should not set new label to label drop answer if label is not empty", () => {
        const { dropLabel } = makeTestRig();
        dropLabel.label = "A Label";
        dropLabel.addTargetID("obj1");
        expect(dropLabel.label).toEqual("A Label");
    });
    it("Should not set new label to label drop answer if the number of correct object Ids is not 1", () => {
        const { dropLabel } = makeTestRig();
        expect(dropLabel.label).toEqual("");
        dropLabel.targetIds = ["t1", "t2"];
        expect(dropLabel.label).toEqual("");
    });
    it("Unsubscribes if it has a label", () => {
        const { dropLabel } = makeTestRig();
        dropLabel.removeChangeObserver = jest.fn();
        dropLabel.label = "A Label";
        expect(dropLabel.removeChangeObserver).toHaveBeenCalled();
    });
    it("Unsubscribes if it has more than one target", () => {
        const { dropLabel } = makeTestRig();
        dropLabel.removeChangeObserver = jest.fn();
        dropLabel.targetIds = ["t1", "t2"];
        expect(dropLabel.removeChangeObserver).toHaveBeenCalled();
    });
    it("Unsubscribes after setting", () => {
        const { dropLabel } = makeTestRig();
        dropLabel.removeChangeObserver = jest.fn();
        dropLabel.addTargetID("obj1");
        expect(dropLabel.removeChangeObserver).toHaveBeenCalled();
    });
});
//# sourceMappingURL=InitializeLabelDropLabelHook.test.js.map