|
| 1 | +import 'react-native'; |
| 2 | +import React from 'react'; |
| 3 | +import Flex from '../lib/Flex'; |
| 4 | +import Button from '../lib/Button'; |
| 5 | +import { render } from '@testing-library/react-native'; |
| 6 | +import { keys, toObject } from '../utils'; |
| 7 | + |
| 8 | +const JUSTIFYS: keys = { |
| 9 | + start: 'flex-start', |
| 10 | + end: 'flex-end', |
| 11 | + center: 'center', |
| 12 | + between: 'space-between', |
| 13 | + around: 'space-around', |
| 14 | +}; |
| 15 | + |
| 16 | +const ALIGNS: keys = { |
| 17 | + start: 'flex-start', |
| 18 | + end: 'flex-end', |
| 19 | + center: 'center', |
| 20 | + stretch: 'stretch', |
| 21 | + baseline: 'baseline', |
| 22 | +}; |
| 23 | + |
| 24 | +describe('Flex', () => { |
| 25 | + describe.each` |
| 26 | + direction |
| 27 | + ${'row'} |
| 28 | + ${'column'} |
| 29 | + ${'row-reverse'} |
| 30 | + ${'column-reverse'} |
| 31 | + `('$direction', ({ direction }) => { |
| 32 | + it(`should display direction ${direction} flex`, () => { |
| 33 | + const { getByTestId } = render( |
| 34 | + <Flex direction={direction}> |
| 35 | + <Flex.Item> |
| 36 | + <Button>A</Button> |
| 37 | + </Flex.Item> |
| 38 | + <Flex.Item> |
| 39 | + <Button>B</Button> |
| 40 | + </Flex.Item> |
| 41 | + </Flex>, |
| 42 | + ); |
| 43 | + const component = getByTestId('RNE__Flex__wrap'); |
| 44 | + const styles = toObject(component.props.style); |
| 45 | + expect(styles.flexDirection).toBe(direction); |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + describe.each` |
| 50 | + justify |
| 51 | + ${'start'} |
| 52 | + ${'end'} |
| 53 | + ${'center'} |
| 54 | + ${'between'} |
| 55 | + ${'around'} |
| 56 | + `('$justify', ({ justify }) => { |
| 57 | + it(`should display justify ${justify} flex`, () => { |
| 58 | + const { getByTestId } = render( |
| 59 | + <Flex justify={justify}> |
| 60 | + <Flex.Item> |
| 61 | + <Button>A</Button> |
| 62 | + </Flex.Item> |
| 63 | + <Flex.Item> |
| 64 | + <Button>B</Button> |
| 65 | + </Flex.Item> |
| 66 | + </Flex>, |
| 67 | + ); |
| 68 | + const component = getByTestId('RNE__Flex__wrap'); |
| 69 | + const styles = toObject(component.props.style); |
| 70 | + expect(styles.justifyContent).toBe(JUSTIFYS[justify]); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + describe.each` |
| 75 | + align |
| 76 | + ${'start'} |
| 77 | + ${'end'} |
| 78 | + ${'center'} |
| 79 | + ${'stretch'} |
| 80 | + ${'baseline'} |
| 81 | + `('$align', ({ align }) => { |
| 82 | + it(`should display align ${align} flex`, () => { |
| 83 | + const { getByTestId } = render( |
| 84 | + <Flex align={align}> |
| 85 | + <Flex.Item> |
| 86 | + <Button>A</Button> |
| 87 | + </Flex.Item> |
| 88 | + <Flex.Item> |
| 89 | + <Button>B</Button> |
| 90 | + </Flex.Item> |
| 91 | + </Flex>, |
| 92 | + ); |
| 93 | + const component = getByTestId('RNE__Flex__wrap'); |
| 94 | + const styles = toObject(component.props.style); |
| 95 | + expect(styles.alignItems).toBe(ALIGNS[align]); |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
| 99 | + describe.each` |
| 100 | + wrap |
| 101 | + ${'wrap'} |
| 102 | + ${'nowrap'} |
| 103 | + ${'wrap-reverse'} |
| 104 | + `('$wrap', ({ wrap }) => { |
| 105 | + it(`should display align ${wrap} flex`, () => { |
| 106 | + const { getByTestId } = render( |
| 107 | + <Flex wrap={wrap}> |
| 108 | + <Flex.Item> |
| 109 | + <Button>A</Button> |
| 110 | + </Flex.Item> |
| 111 | + <Flex.Item> |
| 112 | + <Button>B</Button> |
| 113 | + </Flex.Item> |
| 114 | + </Flex>, |
| 115 | + ); |
| 116 | + const component = getByTestId('RNE__Flex__wrap'); |
| 117 | + const styles = toObject(component.props.style); |
| 118 | + expect(styles.flexWrap).toBe(wrap); |
| 119 | + }); |
| 120 | + }); |
| 121 | +}); |
0 commit comments