Skip to content

Commit 6a65c94

Browse files
authored
Merge pull request #478 from yaob421123/yb
test(Flex): add test
2 parents 3c3b584 + 19fbe16 commit 6a65c94

File tree

3 files changed

+124
-3
lines changed

3 files changed

+124
-3
lines changed

packages/core/src/Flex/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default class Flex extends Component<FlexProps> {
5555
sty.alignItems = align.replace(/^start$/g, 'flex-start').replace(/^end$/g, 'flex-end') as FlexStyle['alignItems'];
5656
}
5757
return (
58-
<View style={[sty, style]}>
58+
<View testID="RNE__Flex__wrap" style={[sty, style]}>
5959
{children &&
6060
React.Children.map(children, (child: React.ReactNode) => {
6161
if (!React.isValidElement(child)) {

test-ci/src/__tests__/divider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import renderer from 'react-test-renderer';
33
import 'react-native';
44
import React from 'react';
55
import Divider from '../lib/Divider';
6-
import { render, fireEvent } from '@testing-library/react-native';
7-
import { keys, colorRgb, toObject } from '../utils';
6+
import { render } from '@testing-library/react-native';
7+
import { keys, toObject } from '../utils';
88

99
const TYPES: keys = {
1010
horizontal: 'row',

test-ci/src/__tests__/flex.tsx

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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

Comments
 (0)