-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplugin-box.test.tsx
74 lines (62 loc) · 2.04 KB
/
plugin-box.test.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React from 'react';
import { render } from '@testing-library/react';
import { Formik } from 'formik';
import { ChakraProvider } from '@chakra-ui/react';
import { PluginBox } from './plugin-box';
const mockPlugin = {
name: 'TestPlugin',
editSchema: jest.fn()
};
// Custom renderer to add context or providers if needed
const renderWithProviders = (
ui: React.ReactNode,
{ renderOptions = {} } = {}
) => {
// You can wrap the component with any context providers here
return render(ui, {
wrapper: ({ children }) => (
<ChakraProvider>
<Formik initialValues={{}} onSubmit={() => {}}>
{children}
</Formik>
</ChakraProvider>
),
...renderOptions
});
};
describe('PluginBox', () => {
it.only('renders ErrorBox when editSchema is null', () => {
mockPlugin.editSchema.mockReturnValue(null);
const { getByTestId } = renderWithProviders(
<Formik initialValues={{}} onSubmit={() => {}}>
<PluginBox plugin={mockPlugin as any}>
{({ field }) => <div>{field.label}</div>}
</PluginBox>
</Formik>
);
expect(getByTestId('plugin-box-error')).toMatchSnapshot();
});
it('renders nothing when editSchema is Plugin.HIDDEN', () => {
mockPlugin.editSchema.mockReturnValue('HIDDEN');
const { container } = renderWithProviders(
<Formik initialValues={{}} onSubmit={() => {}}>
<PluginBox plugin={mockPlugin as any}>
{({ field }) => <div>{field.label}</div>}
</PluginBox>
</Formik>
);
expect(container.firstChild).toBeNull();
});
it('renders children when editSchema is valid', () => {
const mockSchema = { type: 'string', label: 'testField' };
mockPlugin.editSchema.mockReturnValue(mockSchema);
const { getByText } = renderWithProviders(
<Formik initialValues={{}} onSubmit={() => {}}>
<PluginBox plugin={mockPlugin as any}>
{({ field }) => <div>{field.label}</div>}
</PluginBox>
</Formik>
);
expect(getByText(/testField/i)).toBeInTheDocument();
});
});