"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MockShowAlert_1 = require("../../Dispatcher/Mocks/MockShowAlert");
const ChallengeEntity_1 = require("../Entities/ChallengeEntity");
const ChallengeMock_1 = require("../Mocks/ChallengeMock");
const ShowChallengeHelpUC_1 = require("./ShowChallengeHelpUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSingletonSpy = jest.spyOn(appObjects, "registerSingleton");
    const ao = appObjects.getOrCreate("AO");
    const challengeEntity = (0, ChallengeEntity_1.makeChallengeEntity)(ao);
    const mockChallenge = new ChallengeMock_1.ChallengeMock("CHALLENGE1");
    challengeEntity.registerChallenge(mockChallenge);
    const mockAlert = (0, MockShowAlert_1.makeMockShowAlert)(appObjects).showAlert;
    const uc = (0, ShowChallengeHelpUC_1.makeShowChallengeHelpUC)(ao);
    return {
        mockAlert,
        uc,
        challengeEntity,
        appObjects,
        registerSingletonSpy,
        mockChallenge,
    };
}
describe("Show Challenge Help", () => {
    it("Gets the singleton", () => {
        const { appObjects, uc } = makeTestRig();
        expect(ShowChallengeHelpUC_1.ShowChallengeHelpUC.get(appObjects)).toEqual(uc);
    });
    it("Register the singleton", () => {
        const { registerSingletonSpy, uc } = makeTestRig();
        expect(registerSingletonSpy).toHaveBeenCalledWith(uc);
    });
    it("Show help if the selected challenge has title and help", () => {
        const { challengeEntity, mockAlert, uc, mockChallenge } = makeTestRig();
        challengeEntity.selectedChallenge = "CHALLENGE1";
        uc.showChallengeHelp();
        expect(mockAlert).toHaveBeenCalledTimes(1);
        const dto = mockAlert.mock.calls[0][0];
        expect(dto.title).toEqual(mockChallenge.helpHeading);
        expect(dto.message).toEqual(mockChallenge.consumerHelpText);
        expect(dto.closeButtonLabel).toEqual("Close");
    });
    it("Warns and does not display if there is no message or title", () => {
        const { mockAlert, uc } = makeTestRig();
        uc.warn = jest.fn();
        uc.showChallengeHelp();
        expect(mockAlert).not.toHaveBeenCalled();
        expect(uc.warn).toHaveBeenCalled();
    });
});
//# sourceMappingURL=ShowChallengeHelpUC.test.js.map