"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MockDispatchStateChange_1 = require("../../Dispatcher/Mocks/MockDispatchStateChange");
const MockUndoRedo_1 = require("../../UndoRedo/Mocks/MockUndoRedo");
const Entities_1 = require("../Entities");
const SetAnswerFeedbackUndoRedo_1 = require("./SetAnswerFeedbackUndoRedo");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("App");
    const mockUndo = new MockUndoRedo_1.MockUndoRedo(ao);
    const mockDispatcher = new MockDispatchStateChange_1.MockDispatchStateChange(ao);
    const questionEntity = (0, Entities_1.makeQuestionEntity)(ao);
    questionEntity.answerFactory = (id) => {
        const answerAO = appObjects.getOrCreate(id ?? "answer");
        return (0, Entities_1.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, answer } = makeTestRig();
        const action = new SetAnswerFeedbackUndoRedo_1.SetAnswerFeedbackUndoRedo("initial feedback", answer.id, appObjects);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Undo adds the deleted answer", () => {
        const { appObjects, answer } = makeTestRig();
        answer.feedbackText = "Hello World";
        const action = new SetAnswerFeedbackUndoRedo_1.SetAnswerFeedbackUndoRedo("Initial Text", answer.id, appObjects);
        action.undoAction();
        expect(answer.feedbackText).toEqual("Initial Text");
    });
    it("Redo removes the answer", () => {
        const { appObjects, answer } = makeTestRig();
        answer.feedbackText = "Hello World";
        const action = new SetAnswerFeedbackUndoRedo_1.SetAnswerFeedbackUndoRedo("Initial Text", answer.id, appObjects);
        expect(answer.isCorrect).toEqual(false);
        action.undoAction();
        action.redoAction();
        expect(answer.feedbackText).toEqual("Hello World");
    });
    it("Dispatches state changes for both the undo and redo action", () => {
        const { appObjects, mockDispatcher, answer } = makeTestRig();
        const action = new SetAnswerFeedbackUndoRedo_1.SetAnswerFeedbackUndoRedo("Initial Text", answer.id, appObjects);
        action.undoAction();
        expect(mockDispatcher.doDispatch).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(mockDispatcher.doDispatch).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=SetAnswerFeedbackUndoRedo.test.js.map