import { makeAppObjectRepo } from "@vived/core";
import { makeAppDispatcher, AppDispatcher } from "./AppDispatcher";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const dispatcherAO = appObjects.getOrCreate("appDispatcher");
    const mockHandler = jest.fn();
    const dispatcher = makeAppDispatcher(dispatcherAO, mockHandler);
    return { dispatcher, appObjects, mockHandler };
}
describe("App Dispatcher Entity", () => {
    it("Gets the App Dispatcher", () => {
        const { dispatcher, appObjects } = makeTestRig();
        expect(AppDispatcher.get(appObjects)).toEqual(dispatcher);
    });
    it("Dispatches to the host", () => {
        const { dispatcher, mockHandler } = makeTestRig();
        const request = {
            type: "a type",
            version: 1,
            payload: { foo: "bar" },
        };
        dispatcher.dispatch(request);
        expect(mockHandler).toHaveBeenCalledWith(request);
    });
    it("Forms and dispatches a request", () => {
        const { dispatcher, mockHandler } = makeTestRig();
        const request = {
            type: "a type",
            version: 1,
            payload: { foo: "bar" },
        };
        dispatcher.formRequestAndDispatch("a type", 1, { foo: "bar" });
        expect(mockHandler).toHaveBeenCalledWith(request);
    });
});
//# sourceMappingURL=AppDispatcher.test.js.map