"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const ChallengeEntity_1 = require("./ChallengeEntity");
const ChallengeMock_1 = require("../Mocks/ChallengeMock");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSingletonSpy = jest.spyOn(appObjects, "registerSingleton");
    const ao = appObjects.getOrCreate("AO");
    const entity = (0, ChallengeEntity_1.makeChallengeEntity)(ao);
    const challenge1 = new ChallengeMock_1.ChallengeMock("Challenge1");
    entity.registerChallenge(challenge1);
    const observer = jest.fn();
    entity.addChangeObserver(observer);
    return { ao, appObjects, entity, registerSingletonSpy, observer, challenge1 };
}
describe("Challenge Entity", () => {
    it("Gets the singleton", () => {
        const { appObjects, entity } = makeTestRig();
        expect(ChallengeEntity_1.ChallengeEntity.get(appObjects)).toEqual(entity);
    });
    it("Register the singleton", () => {
        const { registerSingletonSpy, entity } = makeTestRig();
        expect(registerSingletonSpy).toHaveBeenCalledWith(entity);
    });
    it("Starts out set to the NONE challenge", () => {
        const { entity } = makeTestRig();
        expect(entity.selectedChallenge).toEqual("NONE");
    });
    it("Notifies when a challenge is registered", () => {
        const { entity, observer } = makeTestRig();
        observer.mockClear();
        entity.registerChallenge(new ChallengeMock_1.ChallengeMock("Challenge2"));
        expect(observer).toHaveBeenCalled();
    });
    it("Sets the current challenge", () => {
        const { entity } = makeTestRig();
        entity.selectedChallenge = "Challenge1";
        expect(entity.selectedChallenge).toEqual("Challenge1");
    });
    it("Warns when an unknown challenge is selected", () => {
        const { entity } = makeTestRig();
        entity.warn = jest.fn();
        entity.selectedChallenge = "UNKNOWN";
        expect(entity.warn).toHaveBeenCalled();
    });
    it("Notifies when the challenge changes", () => {
        const { observer, entity } = makeTestRig();
        entity.selectedChallenge = "Challenge1";
        entity.selectedChallenge = "Challenge1";
        entity.selectedChallenge = "Challenge1";
        entity.selectedChallenge = "Challenge1";
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Returns the consumer help text", () => {
        const { entity, challenge1 } = makeTestRig();
        expect(entity.selectedChallengeConsumerHelp).toEqual("");
        entity.selectedChallenge = "Challenge1";
        expect(entity.selectedChallengeConsumerHelp).toEqual(challenge1.consumerHelpText);
    });
    it("Returns the heading text", () => {
        const { entity, challenge1 } = makeTestRig();
        expect(entity.selectedChallengeHeading).toEqual("");
        entity.selectedChallenge = "Challenge1";
        expect(entity.selectedChallengeHeading).toEqual(challenge1.helpHeading);
    });
    it("Returns the name", () => {
        const { entity, challenge1 } = makeTestRig();
        expect(entity.selectedChallengeName).toEqual("None");
        entity.selectedChallenge = "Challenge1";
        expect(entity.selectedChallengeName).toEqual(challenge1.name);
    });
    it("Returns the author help", () => {
        const { entity, challenge1 } = makeTestRig();
        expect(entity.selectedChallengeAuthorHelp).toEqual("");
        entity.selectedChallenge = "Challenge1";
        expect(entity.selectedChallengeAuthorHelp).toEqual(challenge1.authorHelpText);
    });
    it("Resets the selected challenge", () => {
        const { entity, challenge1 } = makeTestRig();
        entity.selectedChallenge = "Challenge1";
        entity.resetSelectedChallenge();
        expect(challenge1.reset).toHaveBeenCalled();
    });
});
//# sourceMappingURL=ChallengeEntity.test.js.map