"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const MockQuestionAnswerEntity_1 = require("../Mocks/MockQuestionAnswerEntity");
const ToggleQuestionAnswerIsCorrect_1 = require("./ToggleQuestionAnswerIsCorrect");
const jest_mock_1 = require("jest-mock");
const ToggleIsCorrectUndoRedo_1 = require("./ToggleIsCorrectUndoRedo");
jest.mock("./ToggleIsCorrectUndoRedo", () => {
    return {
        ToggleIsCorrectUndoRedo: jest.fn().mockImplementation(() => {
            return;
        }),
    };
});
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ansAO = appObjects.getOrCreate("Ans");
    const mockAns = new MockQuestionAnswerEntity_1.MockQuestionAnswerEntity(ansAO);
    const appAO = appObjects.getOrCreate("App");
    const mockDispatch = (0, Dispatcher_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    mockAns.isCorrect = true;
    const MockedUndoRedoAction = (0, jest_mock_1.mocked)(ToggleIsCorrectUndoRedo_1.ToggleIsCorrectUndoRedo);
    const toggleUC = (0, ToggleQuestionAnswerIsCorrect_1.makeToggleQuestionChallengeAnswerIsCorrectUC)(ansAO);
    return {
        mockAns,
        toggleUC,
        appObjects,
        mockDispatch,
        doDispatchMock,
        MockedUndoRedoAction,
    };
}
describe("Toggle answer is correct use case", () => {
    it("Sets the text", () => {
        const { mockAns, toggleUC } = makeTestRig();
        expect(mockAns.isCorrect).toEqual(true);
        toggleUC.toggleIsCorrect();
        expect(mockAns.isCorrect).toEqual(false);
        toggleUC.toggleIsCorrect();
        expect(mockAns.isCorrect).toEqual(true);
    });
    it("Warns if it is added to an App Object that does not have an Answer Entity", () => {
        const { appObjects } = makeTestRig();
        appObjects.submitWarning = jest.fn();
        (0, ToggleQuestionAnswerIsCorrect_1.makeToggleQuestionChallengeAnswerIsCorrectUC)(appObjects.getOrCreate("AnotherAO"));
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Dispatches a state change", () => {
        const { mockAns, toggleUC, doDispatchMock } = makeTestRig();
        toggleUC.toggleIsCorrect();
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Creates an Undo Redo action", () => {
        const { toggleUC, MockedUndoRedoAction, appObjects, mockAns } = makeTestRig();
        MockedUndoRedoAction.mockClear();
        toggleUC.toggleIsCorrect();
        expect(MockedUndoRedoAction).toHaveBeenCalledTimes(1);
        expect(MockedUndoRedoAction).toHaveBeenCalledWith(mockAns.id, appObjects);
    });
});
//# sourceMappingURL=ToggleQuestionAnswerIsCorrect.test.js.map