"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const LabelDropItemEntity_1 = require("./LabelDropItemEntity");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("appObj1");
    const entity = new LabelDropItemEntity_1.LabelDropItemEntity(ao);
    const observer = jest.fn();
    entity.addChangeObserver(observer);
    return { appObjects, entity, observer };
}
describe("Label Drop Item Entity", () => {
    it("Gets the Entity", () => {
        const { appObjects, entity } = makeTestRig();
        expect(LabelDropItemEntity_1.LabelDropItemEntity.get("appObj1", appObjects)).toEqual(entity);
    });
    it("Reruns the app object ID", () => {
        const { entity } = makeTestRig();
        expect(entity.id).toEqual(entity.appObject.id);
    });
    it("Notifies when the target ids are set", () => {
        const { entity, observer } = makeTestRig();
        entity.targetIds = ["id1", "id2"];
        expect(entity.targetIds).toEqual(["id1", "id2"]);
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Notifies when a new target is set", () => {
        const { entity, observer } = makeTestRig();
        entity.addTargetID("id1");
        entity.addTargetID("id1");
        entity.addTargetID("id1");
        entity.addTargetID("id1");
        expect(entity.targetIds).toEqual(["id1"]);
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Notifies when a new target is removed", () => {
        const { entity, observer } = makeTestRig();
        entity.addTargetID("id1");
        observer.mockClear();
        entity.removeTargetID("id1");
        entity.removeTargetID("id1");
        entity.removeTargetID("id1");
        entity.removeTargetID("id1");
        expect(entity.targetIds).toEqual([]);
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Returns a target validation message when there are no targets", () => {
        const { entity } = makeTestRig();
        expect(entity.targetValidationMessage).toEqual(LabelDropItemEntity_1.LabelDropItemEntity.LABEL_DROP_NEED_TARGETS);
        entity.addTargetID("id1");
        expect(entity.targetValidationMessage).toBeUndefined();
    });
    it("Notifies on submit", () => {
        const { entity, observer } = makeTestRig();
        observer.mockClear();
        entity.submitLabelDrop("droppedOnObj");
        expect(observer).toHaveBeenCalled();
    });
    it("Bumps the tries when submitted", () => {
        const { entity } = makeTestRig();
        expect(entity.tries).toEqual(0);
        entity.submitLabelDrop("droppedOnObj");
        expect(entity.tries).toEqual(1);
    });
    it("Answered correctly returns false if not a correct answer", () => {
        const { entity } = makeTestRig();
        expect(entity.answeredCorrectly).toBeUndefined();
        entity.submitLabelDrop("droppedOnObj");
        expect(entity.answeredCorrectly).toEqual(false);
    });
    it("Answered correctly returns true if a correct answer", () => {
        const { entity } = makeTestRig();
        entity.addTargetID("droppedOnObj");
        expect(entity.answeredCorrectly).toBeUndefined();
        entity.submitLabelDrop("droppedOnObj");
        expect(entity.answeredCorrectly).toEqual(true);
    });
    it("Clears the tries when reset", () => {
        const { entity } = makeTestRig();
        entity.submitLabelDrop("droppedOnObj");
        expect(entity.tries).toEqual(1);
        entity.reset();
        expect(entity.tries).toEqual(0);
    });
    it("Clears the answeredCorrectly when reset", () => {
        const { entity } = makeTestRig();
        entity.submitLabelDrop("droppedOnObj");
        expect(entity.answeredCorrectly).toEqual(false);
        entity.reset();
        expect(entity.answeredCorrectly).toBeUndefined();
    });
    it("Notifies when reset", () => {
        const { entity, observer } = makeTestRig();
        entity.submitLabelDrop("droppedOnObj");
        observer.mockClear();
        entity.reset();
        expect(observer).toHaveBeenCalled();
    });
    it("Gets the data", () => {
        const { entity } = makeTestRig();
        entity.addTargetID("aTarget");
        entity.labelEntity.custom = "Hello World";
        expect(entity.data).toEqual({
            id: "appObj1",
            label: "Hello World",
            correctAppObjectIDs: ["aTarget"],
        });
    });
    it("Sets the data", () => {
        const { entity, observer } = makeTestRig();
        entity.data = {
            id: "appObj1",
            label: "Hello World",
            correctAppObjectIDs: ["aTarget"],
        };
        expect(entity.labelEntity.custom).toEqual("Hello World");
        expect(entity.targetIds).toEqual(["aTarget"]);
        expect(observer).toHaveBeenCalled();
    });
});
//# sourceMappingURL=LabelDropItemEntity.test.js.map