import { makeAppObjectRepo } from "@vived/core";
import { MockDispatchStateChange } from "../../Dispatcher/Mocks/MockDispatchStateChange";
import { MockUndoRedo } from "../../UndoRedo/Mocks/MockUndoRedo";
import { makeQuestionAnswerEntity, makeQuestionEntity } from "../Entities";
import { ToggleIsCorrectUndoRedo } from "./ToggleIsCorrectUndoRedo";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ao = appObjects.getOrCreate("App");
    const mockUndo = new MockUndoRedo(ao);
    const mockDispatcher = new MockDispatchStateChange(ao);
    const questionEntity = makeQuestionEntity(ao);
    questionEntity.answerFactory = (id) => {
        const answerAO = appObjects.getOrCreate(id ?? "answer");
        return makeQuestionAnswerEntity(answerAO);
    };
    const answer = questionEntity.createNewAnswer();
    return { mockUndo, mockDispatcher, appObjects, answer };
}
describe("Add Answer Undo Redo action", () => {
    it("Submits itself to the entity", () => {
        const { mockUndo, appObjects } = makeTestRig();
        const action = new ToggleIsCorrectUndoRedo("questionID", appObjects);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Undo adds the deleted answer", () => {
        const { appObjects, answer } = makeTestRig();
        expect(answer.isCorrect).toEqual(false);
        const action = new ToggleIsCorrectUndoRedo(answer.id, appObjects);
        action.undoAction();
        expect(answer.isCorrect).toEqual(true);
    });
    it("Redo removes the answer", () => {
        const { appObjects, answer } = makeTestRig();
        const action = new ToggleIsCorrectUndoRedo(answer.id, appObjects);
        expect(answer.isCorrect).toEqual(false);
        action.undoAction();
        action.redoAction();
        expect(answer.isCorrect).toEqual(false);
    });
    it("Dispatches state changes for both the undo and redo action", () => {
        const { appObjects, mockDispatcher, answer } = makeTestRig();
        const action = new ToggleIsCorrectUndoRedo(answer.id, appObjects);
        action.undoAction();
        expect(mockDispatcher.doDispatch).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(mockDispatcher.doDispatch).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=ToggleIsCorrectUndoRedo.test.js.map