/** @jest-environment jsdom */
import { render } from '@testing-library/react';
import React, { Fragment, type ReactNode } from 'react';
import templateMiddleware from './templateMiddleware';
type ButtonProps = Readonly<{ children?: ReactNode | undefined }>;
type LinkProps = Readonly<{ children?: ReactNode | undefined; href: string }>;
const ButtonImpl = ({ children }: ButtonProps) => ;
const ExternalLinkImpl = ({ children, href }: LinkProps) => (
{children}
);
const InternalLinkImpl = ({ children, href }: LinkProps) => {children};
// User story for using templateMiddleware as a building block for uber middleware.
test('an uber middleware', () => {
const {
initMiddleware: initButtonMiddleware,
Provider: ButtonProvider,
Proxy: Button,
types: buttonTypes
} = templateMiddleware<'button', void, ButtonProps>('Button');
type ButtonMiddleware = typeof buttonTypes.middleware;
const {
initMiddleware: initLinkMiddleware,
Provider: LinkProvider,
Proxy: Link,
types: linkTypes
} = templateMiddleware<'link', { external: boolean }, LinkProps>('Link');
type LinkMiddleware = typeof linkTypes.middleware;
const buttonMiddleware: ButtonMiddleware[] = [init => init === 'button' && (() => () => ButtonImpl)];
const linkMiddleware: LinkMiddleware[] = [
init => init === 'link' && (next => request => (request.external ? ExternalLinkImpl : next(request))),
init => init === 'link' && (() => () => InternalLinkImpl)
];
const App = ({
children,
middleware
}: Readonly<{
children?: ReactNode | undefined;
middleware: ReadonlyArray;
}>) => (
{/* TODO: Should not case middleware to any */}
{/* TODO: Should not case middleware to any */}
{children}
);
const result = render(
{/* TODO: If "request" is of type "void", we should not need it specified. */}
{'Internal link'}
{'External link'}
);
expect(result.container).toMatchInlineSnapshot(`
`);
});