import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { MockQuestionAnswerEntity } from "../Mocks/MockQuestionAnswerEntity";
import { makeToggleQuestionChallengeAnswerIsCorrectUC } from "./ToggleQuestionAnswerIsCorrect";
import { mocked } from "jest-mock";
import { ToggleIsCorrectUndoRedo } from "./ToggleIsCorrectUndoRedo";
jest.mock("./ToggleIsCorrectUndoRedo", () => {
    return {
        ToggleIsCorrectUndoRedo: jest.fn().mockImplementation(() => {
            return;
        }),
    };
});
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ansAO = appObjects.getOrCreate("Ans");
    const mockAns = new MockQuestionAnswerEntity(ansAO);
    const appAO = appObjects.getOrCreate("App");
    const mockDispatch = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    mockAns.isCorrect = true;
    const MockedUndoRedoAction = mocked(ToggleIsCorrectUndoRedo);
    const toggleUC = 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();
        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