|
| 1 | +import React from 'react'; |
| 2 | +import {mountWithApp} from 'tests/utilities'; |
| 3 | + |
| 4 | +import {Box} from '..'; |
| 5 | + |
| 6 | +const text = 'This is a box'; |
| 7 | + |
| 8 | +describe('Box', () => { |
| 9 | + it('renders children', () => { |
| 10 | + const box = mountWithApp( |
| 11 | + <Box> |
| 12 | + <p>{text}</p> |
| 13 | + </Box>, |
| 14 | + ); |
| 15 | + |
| 16 | + expect(box).toContainReactComponent('p', {children: text}); |
| 17 | + }); |
| 18 | + |
| 19 | + it('does not render custom properties by default', () => { |
| 20 | + const box = mountWithApp( |
| 21 | + <Box> |
| 22 | + <p>{text}</p> |
| 23 | + </Box>, |
| 24 | + ); |
| 25 | + |
| 26 | + expect(box).toContainReactComponent('div', {style: undefined}); |
| 27 | + }); |
| 28 | + |
| 29 | + it('only renders the custom property that matches the property passed in', () => { |
| 30 | + const box = mountWithApp( |
| 31 | + <Box marginLeft="2"> |
| 32 | + <p>{text}</p> |
| 33 | + </Box>, |
| 34 | + ); |
| 35 | + |
| 36 | + expect(box).toContainReactComponent('div', { |
| 37 | + style: { |
| 38 | + '--pc-box-margin-left': 'var(--p-space-2)', |
| 39 | + } as React.CSSProperties, |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + it('renders custom properties combined with any overrides if they are passed in', () => { |
| 44 | + const box = mountWithApp( |
| 45 | + <Box margin="1" marginLeft="2"> |
| 46 | + <p>{text}</p> |
| 47 | + </Box>, |
| 48 | + ); |
| 49 | + |
| 50 | + expect(box).toContainReactComponent('div', { |
| 51 | + style: { |
| 52 | + '--pc-box-margin-bottom': 'var(--p-space-1)', |
| 53 | + '--pc-box-margin-left': 'var(--p-space-2)', |
| 54 | + '--pc-box-margin-right': 'var(--p-space-1)', |
| 55 | + '--pc-box-margin-top': 'var(--p-space-1)', |
| 56 | + } as React.CSSProperties, |
| 57 | + }); |
| 58 | + }); |
| 59 | +}); |
0 commit comments