"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const MockUndoRedo_1 = require("../../UndoRedo/Mocks/MockUndoRedo");
const CalloutRepo_1 = require("../Entities/CalloutRepo");
const DeleteAllCalloutsUndoRedo_1 = require("./DeleteAllCalloutsUndoRedo");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appAO = appObjects.getOrCreate("App");
    const mockUndo = (0, MockUndoRedo_1.makeMockUndoRedo)(appObjects);
    const submitActionMock = jest.fn();
    mockUndo.submitAction = submitActionMock;
    const mockDispatcher = (0, Dispatcher_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatcher.doDispatch = doDispatchMock;
    const repo1 = (0, CalloutRepo_1.makeCalloutRepoEntity)(appObjects.getOrCreate("parent1"));
    const repo2 = (0, CalloutRepo_1.makeCalloutRepoEntity)(appObjects.getOrCreate("parent2"));
    const callout1 = repo1.makeCallout("callout1");
    const callout2 = repo2.makeCallout("callout2");
    repo1.deleteCallout("callout1");
    repo2.deleteCallout("callout2");
    return {
        appObjects,
        mockUndo,
        submitActionMock,
        callout1,
        callout2,
        mockDispatcher,
        doDispatchMock,
        repo1,
        repo2,
    };
}
describe("Delete All Callouts Undo Redo action", () => {
    it("Submits itself to the entity", () => {
        const { submitActionMock, callout1, callout2, appObjects } = makeTestRig();
        const deletedCallouts = [callout1.data, callout2.data];
        const action = new DeleteAllCalloutsUndoRedo_1.DeleteAllCalloutsUndoRedo(deletedCallouts, appObjects);
        expect(submitActionMock).toHaveBeenCalledWith(action);
    });
    it("Undo Add last callouts", () => {
        const { repo1, repo2, callout1, callout2, appObjects } = makeTestRig();
        const deletedCallouts = [callout1.data, callout2.data];
        const action = new DeleteAllCalloutsUndoRedo_1.DeleteAllCalloutsUndoRedo(deletedCallouts, appObjects);
        action.undoAction();
        expect(repo1.getAll().length).toEqual(1);
        expect(repo2.getAll().length).toEqual(1);
    });
    it("Redo Delete All callouts", () => {
        const { repo1, repo2, callout1, callout2, appObjects } = makeTestRig();
        const deletedCallouts = [callout1.data, callout2.data];
        const action = new DeleteAllCalloutsUndoRedo_1.DeleteAllCalloutsUndoRedo(deletedCallouts, appObjects);
        action.undoAction();
        action.redoAction();
        expect(repo1.getAll().length).toEqual(0);
        expect(repo2.getAll().length).toEqual(0);
    });
    it("Dispatches state changes for both the undo and redo action", () => {
        const { callout1, callout2, appObjects, doDispatchMock } = makeTestRig();
        const deletedCallouts = [callout1.data, callout2.data];
        const action = new DeleteAllCalloutsUndoRedo_1.DeleteAllCalloutsUndoRedo(deletedCallouts, appObjects);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=DeleteAllCalloutsUndoRedo.test.js.map