|
1 | | -import { formTests, SLIDER_CUSTOMIZE, TEXTAREA_CUSTOMIZE } from '@rjsf/snapshot-tests'; |
| 1 | +import { formTests } from '@rjsf/snapshot-tests'; |
2 | 2 |
|
3 | 3 | import Form from '../src'; |
| 4 | +import { COMPUTED_STYLE_MOCK, FORM_RENDER_OPTIONS } from './snapshotConstants'; |
4 | 5 |
|
5 | 6 | // The `TextareaAutosize` code reads the following data from the `getComputedStyle()` function in a useEffect hook |
6 | | -jest.spyOn(window, 'getComputedStyle').mockImplementation(() => { |
7 | | - return { |
8 | | - width: 100, |
9 | | - 'box-sizing': 10, |
10 | | - 'padding-bottom': 1, |
11 | | - 'padding-top': 1, |
12 | | - 'border-bottom-width': 1, |
13 | | - 'border-top-width': 1, |
14 | | - } as unknown as CSSStyleDeclaration; |
15 | | -}); |
| 7 | +jest.spyOn(window, 'getComputedStyle').mockImplementation(() => COMPUTED_STYLE_MOCK); |
16 | 8 |
|
17 | | -formTests(Form, { |
18 | | - [TEXTAREA_CUSTOMIZE]: { |
19 | | - createNodeMock: (element) => { |
20 | | - if (element.type === 'textarea') { |
21 | | - // the `TextareaAutosize` code expects a ref for two textareas to exist, so use the feature of |
22 | | - // react-test-renderer to create one |
23 | | - // See: https://reactjs.org/docs/test-renderer.html#ideas |
24 | | - if (element.props['aria-hidden']) { |
25 | | - // The hidden one reads the following values |
26 | | - return { |
27 | | - style: { width: 10 }, |
28 | | - scrollHeight: 100, |
29 | | - }; |
30 | | - } |
31 | | - // The other one needs to look like an input node with focus and style elements |
32 | | - return { |
33 | | - nodeName: 'INPUT', |
34 | | - focus: jest.fn(), |
35 | | - style: {}, |
36 | | - }; |
37 | | - } |
38 | | - return null; |
39 | | - }, |
40 | | - }, |
41 | | - [SLIDER_CUSTOMIZE]: { |
42 | | - createNodeMock: (element) => { |
43 | | - // the `Slider` code expects a ref for a span.root to exist, so use the feature of |
44 | | - // react-test-renderer to create one |
45 | | - // See: https://reactjs.org/docs/test-renderer.html#ideas |
46 | | - if (element.type === 'span' && element.props.id === 'root') { |
47 | | - // Pretend to be an event listening component inside of an event listening document |
48 | | - return { |
49 | | - addEventListener: jest.fn(), |
50 | | - removeEventListener: jest.fn(), |
51 | | - ownerDocument: { |
52 | | - addEventListener: jest.fn(), |
53 | | - removeEventListener: jest.fn(), |
54 | | - }, |
55 | | - }; |
56 | | - } |
57 | | - return null; |
58 | | - }, |
59 | | - }, |
60 | | -}); |
| 9 | +formTests(Form, FORM_RENDER_OPTIONS); |
0 commit comments