import { makeAppObjectRepo } from "@vived/core";
import { makeMockShowAlert } from "../../Dispatcher/Mocks/MockShowAlert";
import { makeChallengeEntity } from "../Entities/ChallengeEntity";
import { ChallengeMock } from "../Mocks/ChallengeMock";
import { makeShowChallengeHelpUC, ShowChallengeHelpUC, } from "./ShowChallengeHelpUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSingletonSpy = jest.spyOn(appObjects, "registerSingleton");
    const ao = appObjects.getOrCreate("AO");
    const challengeEntity = makeChallengeEntity(ao);
    const mockChallenge = new ChallengeMock("CHALLENGE1");
    challengeEntity.registerChallenge(mockChallenge);
    const mockAlert = makeMockShowAlert(appObjects).showAlert;
    const uc = makeShowChallengeHelpUC(ao);
    return {
        mockAlert,
        uc,
        challengeEntity,
        appObjects,
        registerSingletonSpy,
        mockChallenge,
    };
}
describe("Show Challenge Help", () => {
    it("Gets the singleton", () => {
        const { appObjects, uc } = makeTestRig();
        expect(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