import { makeAppObjectRepo } from "@vived/core";
import { makeLabelDropRepo } from "../Entities/LabelDropRepo";
import { makeValidateLabelDrop, ValidateLabelDrop } from "./ValidateLabelDrop";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const repo = makeLabelDropRepo(appObjects.getOrCreate("Repo"));
    const dropItem = repo.makeLabelDropItem();
    dropItem.label = "Label";
    dropItem.addTargetID("obj1");
    const uc = 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.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