import { makeAppObjectRepo } from "@vived/core";
import { AppDispatcher } from "../Entities/AppDispatcher";
import { ShowMarkdownEditorUC, makeShowMarkdownEditorUC, } from "./ShowMarkdownEditorUC";
class MockDispatcher extends AppDispatcher {
    constructor() {
        super(...arguments);
        this.dispatch = jest.fn();
        this.formRequestAndDispatch = jest.fn();
    }
}
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const dispatcher = appObjects.getOrCreate("Dispatcher");
    const mockDispatcher = new MockDispatcher(dispatcher, AppDispatcher.type);
    const uc = makeShowMarkdownEditorUC(dispatcher);
    return { uc, dispatcher, appObjects, mockDispatcher };
}
describe("Dispatch Show Confirm", () => {
    it("Gets the UC", () => {
        const { uc, appObjects } = makeTestRig();
        expect(ShowMarkdownEditorUC.get(appObjects)).toEqual(uc);
    });
    it("Dispatches the correct type", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        const submitCB = jest.fn();
        const validationCB = jest.fn();
        const confirmDTO = {
            initialText: "initial text",
            submitCallback: submitCB,
            validateString: validationCB,
        };
        uc.showMarkdownEditor(confirmDTO);
        expect(spy).toHaveBeenCalledTimes(1);
        expect(spy.mock.calls[0][0]).toEqual(uc.requestType);
    });
    it("Dispatches the correct version", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        const submitCB = jest.fn();
        const validationCB = jest.fn();
        const confirmDTO = {
            initialText: "initial text",
            submitCallback: submitCB,
            validateString: validationCB,
        };
        uc.showMarkdownEditor(confirmDTO);
        expect(spy).toHaveBeenCalledTimes(1);
        expect(spy.mock.calls[0][1]).toEqual(1);
    });
    it("Dispatches the correct payload", () => {
        const { uc, mockDispatcher } = makeTestRig();
        const spy = jest.spyOn(mockDispatcher, "formRequestAndDispatch");
        const submitCB = jest.fn();
        const validationCB = jest.fn();
        const dto = {
            initialText: "initial text",
            submitCallback: submitCB,
            validateString: validationCB,
        };
        uc.showMarkdownEditor(dto);
        expect(spy).toHaveBeenCalledTimes(1);
        expect(spy.mock.calls[0][2]).toEqual(dto);
    });
});
//# sourceMappingURL=ShowMarkdownEditorUC.test.js.map