-
-
Notifications
You must be signed in to change notification settings - Fork 818
/
Copy pathAppTestProviders.tsx
39 lines (35 loc) · 1.31 KB
/
AppTestProviders.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import type { IAppContext } from '@teable/sdk/context';
import { AppContext, FieldContext, ViewContext } from '@teable/sdk/context';
import { defaultLocale } from '@teable/sdk/context/app/i18n';
import type { IFieldInstance, IViewInstance } from '@teable/sdk/model';
import type { FC, PropsWithChildren } from 'react';
import { I18nextTestStubProvider } from './I18nextTestStubProvider';
export const createAppContext = (context: Partial<IAppContext> = {}) => {
const defaultContext: IAppContext = {
locale: defaultLocale,
};
// eslint-disable-next-line react/display-name
return ({ children }: { children: React.ReactNode }) => (
<AppContext.Provider value={{ ...defaultContext, ...context }}>{children}</AppContext.Provider>
);
};
const MockProvider = createAppContext();
export const AppTestProviders: FC<PropsWithChildren> = ({ children }) => {
return (
<I18nextTestStubProvider>
<MockProvider>{children}</MockProvider>
</I18nextTestStubProvider>
);
};
export const TestAnchorProvider: FC<
PropsWithChildren & {
fields?: IFieldInstance[];
views?: IViewInstance[];
}
> = ({ children, fields = [], views = [] }) => {
return (
<ViewContext.Provider value={{ views }}>
<FieldContext.Provider value={{ fields }}>{children}</FieldContext.Provider>
</ViewContext.Provider>
);
};