"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const LabelDropRepo_1 = require("../Entities/LabelDropRepo");
const ValidateLabelDrop_1 = require("./ValidateLabelDrop");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const repo = (0, LabelDropRepo_1.makeLabelDropRepo)(appObjects.getOrCreate("Repo"));
    const dropItem = repo.makeLabelDropItem();
    dropItem.label = "Label";
    dropItem.addTargetID("obj1");
    const uc = (0, ValidateLabelDrop_1.makeValidateLabelDrop)(appObjects.getOrCreate("AO"));
    return { appObjects, repo, registerSpy, uc, dropItem };
}
describe("Validate Label Drop State", () => {
    it("Get it UC", () => {
        const { appObjects, uc } = makeTestRig();
        expect(ValidateLabelDrop_1.ValidateLabelDrop.get(appObjects)).toEqual(uc);
    });
    it("Registers as the singleton", () => {
        const { uc, registerSpy } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(uc);
    });
    it("Returns null if all good", () => {
        const { uc } = makeTestRig();
        expect(uc.validate()).toBeNull();
    });
    it("Checks if there aren't any label drop answers", () => {
        const { uc, repo } = makeTestRig();
        repo.deleteAllItems();
        expect(uc.validate()).toEqual(uc.LABEL_DROP_ANSWER_REQUIRED);
    });
    it("Checks if Label drop answer is still being edited", () => {
        const { uc, repo, dropItem } = makeTestRig();
        repo.editingID = dropItem.id;
        expect(uc.validate()).toEqual(uc.LABEL_DROP_STILL_EDITING);
    });
    it("Checks for an item label validation problem", () => {
        const { uc, dropItem } = makeTestRig();
        dropItem.labelEntity.customLabelValidator = () => {
            return "SOME LABEL ERROR";
        };
        expect(uc.validate()).toEqual("SOME LABEL ERROR");
    });
    it("Checks for am item target validation problem", () => {
        const { uc, dropItem } = makeTestRig();
        jest
            .spyOn(dropItem, "targetValidationMessage", "get")
            .mockReturnValue("SOME TARGET ERROR");
        expect(uc.validate()).toEqual("SOME TARGET ERROR");
    });
});
//# sourceMappingURL=ValidateLabelDrop.test.js.map