| 1 |
import { formTests, SLIDER_CUSTOMIZE, TEXTAREA_CUSTOMIZE } from '@rjsf/snapshot-tests'; |
| 2 |
|
| 3 |
import Form from '../src'; |
| 4 |
|
| 5 |
// 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 |
}); |
| 16 |
|
| 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 only really needs an empty object |
| 32 |
return {}; |
| 33 |
} |
| 34 |
return null; |
| 35 |
}, |
| 36 |
}, |
| 37 |
[SLIDER_CUSTOMIZE]: { |
| 38 |
createNodeMock: (element) => { |
| 39 |
// the `Slider` code expects a ref for a span.root to exist, so use the feature of |
| 40 |
// react-test-renderer to create one |
| 41 |
// See: https://reactjs.org/docs/test-renderer.html#ideas |
| 42 |
if (element.type === 'span' && element.props.id === 'root') { |
| 43 |
// Pretend to be an event listening component inside of an event listening document |
| 44 |
return { |
| 45 |
addEventListener: jest.fn(), |
| 46 |
removeEventListener: jest.fn(), |
| 47 |
ownerDocument: { |
| 48 |
addEventListener: jest.fn(), |
| 49 |
removeEventListener: jest.fn(), |
| 50 |
}, |
| 51 |
}; |
| 52 |
} |
| 53 |
return null; |
| 54 |
}, |
| 55 |
}, |
| 56 |
}); |