The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/tests/mocks/client/RouterContextMock.tsx

44 lines
1.7 KiB

import React, { ContextType, ReactElement, ReactNode, useMemo } from 'react';
import { Subscription } from 'use-subscription';
import { RouterContext } from '../../../client/contexts/RouterContext';
type RouterContextMockProps = {
children?: ReactNode;
pushRoute?: (name: string, parameters?: Record<string, string>, queryStringParameters?: Record<string, string>) => void;
replaceRoute?: (name: string, parameters?: Record<string, string>, queryStringParameters?: Record<string, string>) => void;
};
const RouterContextMock = ({ children, pushRoute, replaceRoute }: RouterContextMockProps): ReactElement => {
const value = useMemo<ContextType<typeof RouterContext>>(
() => ({
queryRoutePath: (): Subscription<undefined> => ({
getCurrentValue: (): undefined => undefined,
subscribe: () => (): void => undefined,
}),
queryRouteUrl: (): Subscription<undefined> => ({
getCurrentValue: (): undefined => undefined,
subscribe: () => (): void => undefined,
}),
pushRoute: pushRoute ?? ((): void => undefined),
replaceRoute: replaceRoute ?? ((): void => undefined),
queryRouteParameter: (): Subscription<undefined> => ({
getCurrentValue: (): undefined => undefined,
subscribe: () => (): void => undefined,
}),
queryQueryStringParameter: (): Subscription<undefined> => ({
getCurrentValue: (): undefined => undefined,
subscribe: () => (): void => undefined,
}),
queryCurrentRoute: (): Subscription<[undefined, {}, {}, undefined]> => ({
getCurrentValue: (): [undefined, {}, {}, undefined] => [undefined, {}, {}, undefined],
subscribe: () => (): void => undefined,
}),
}),
[pushRoute, replaceRoute],
);
return <RouterContext.Provider children={children} value={value} />;
};
export default RouterContextMock;