Skip to content

Commit 316ad40

Browse files
ffxingyuefeng
authored andcommitted
fix resolve conflict
1 parent 7b54599 commit 316ad40

File tree

3 files changed

+78
-27
lines changed

3 files changed

+78
-27
lines changed

test-ci/package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,31 @@
1717
"@babel/core": "^7.20.7",
1818
"@babel/runtime": "^7.20.7",
1919
"@react-native-community/eslint-config": "^2.0.0",
20+
"@testing-library/react-native": "^11.5.0",
2021
"@tsconfig/react-native": "^2.0.2",
22+
"@types/color": "~3.0.3",
2123
"@types/jest": "^26.0.23",
24+
"@types/lodash": "4.14.172",
2225
"@types/react": "^18.0.21",
2326
"@types/react-native": "^0.70.6",
2427
"@types/react-test-renderer": "^18.0.0",
2528
"@typescript-eslint/eslint-plugin": "^5.37.0",
2629
"@typescript-eslint/parser": "^5.37.0",
27-
"babel-jest": "^26.6.3",
28-
"eslint": "^7.32.0",
29-
"jest": "^26.6.3",
30-
"metro-react-native-babel-preset": "0.73.6",
31-
"react-test-renderer": "18.1.0",
32-
"typescript": "^4.8.3",
33-
"@types/color": "~3.0.3",
34-
"@types/lodash": "4.14.172",
3530
"@uiw/icons": "2.5.3",
3631
"@validator.tool/hook": "2.2.4",
3732
"ahooks": "2.10.14",
33+
"babel-jest": "^26.6.3",
3834
"color": "4.2.3",
35+
"eslint": "^7.32.0",
36+
"jest": "^26.6.3",
3937
"lodash": "4.17.21",
38+
"metro-react-native-babel-preset": "0.72.3",
4039
"prop-types": "15.7.2",
4140
"react-native-gesture-handler": "2.8.0",
4241
"react-native-root-siblings": "4.1.1",
43-
"react-native-svg": "12.1.1"
42+
"react-native-svg": "12.1.1",
43+
"react-test-renderer": "18.1.0",
44+
"typescript": "^4.8.3"
4445
},
4546
"jest": {
4647
"preset": "react-native",
@@ -53,4 +54,4 @@
5354
"node"
5455
]
5556
}
56-
}
57+
}

test-ci/src/__tests__/button.tsx

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,48 @@
55
import 'react-native';
66
import React from 'react';
77
import Button from '../lib/Button';
8+
import { colors } from '../lib/utils';
89
// Note: test renderer must be required after react-native.
9-
import renderer from 'react-test-renderer';
10-
11-
it('Button', () => {
12-
// const component = TestRenderer.create(<Radio value="1">Radio</Radio>);
13-
const component = renderer.create(
14-
<Button type="primary" rounded disabled loading={true} size="large" bordered color="red">
15-
按钮
16-
</Button>,
17-
);
18-
expect(component.root.props.type).toBe('primary');
19-
expect(component.root.props.color).toBe('red');
20-
expect(component.root.props.rounded).toBeTruthy();
21-
expect(component.root.props.disabled).toBeTruthy();
22-
expect(component.root.props.loading).toBeTruthy();
23-
expect(component.root.props.bordered).toBeTruthy();
24-
expect(component.root.props.size).toBe('large');
25-
expect(component.root.props.children).toBe('按钮');
10+
import TestRenderer from 'react-test-renderer';
11+
import { colorRgb } from '../utils';
12+
import { render, screen, fireEvent } from '@testing-library/react-native';
13+
14+
describe('Button', () => {
15+
test('renders with color', () => {
16+
const testInstance = TestRenderer.create(
17+
<>
18+
<Button type="primary">主要按钮</Button>
19+
<Button type="success">成功按钮</Button>
20+
<Button color="#1EABCD">自定义颜色</Button>
21+
</>,
22+
) as any;
23+
expect(testInstance.toJSON()[0].props.style.backgroundColor).toBe(colorRgb(colors.blue));
24+
expect(testInstance.toJSON()[1].props.style.backgroundColor).toBe(colorRgb(colors.green));
25+
expect(testInstance.toJSON()[2].props.style.backgroundColor).toBe(colorRgb('#1EABCD'));
26+
});
27+
test('loading with ActivityIndicator', () => {
28+
const testInstance = TestRenderer.create(<Button loading>加载中按钮</Button>) as any;
29+
const testRoot = testInstance.root;
30+
31+
expect(testRoot.props.loading).toBeTruthy();
32+
expect(testInstance.toJSON().children[0].type).toBe('ActivityIndicator');
33+
});
34+
35+
// test('renders with onClick', () => {
36+
// const DefaultButton = () => {
37+
// const [loading, setLoading] = React.useState(true)
38+
// return (
39+
// <Button onPress={() => setLoading(false)} loading={loading}>
40+
// click loading
41+
// </Button>
42+
// )
43+
// }
44+
45+
// render(<DefaultButton />);
46+
47+
// const { getByText } = render(<DefaultButton />)
48+
49+
// const btn = getByText('click loading')
50+
51+
// })
2652
});

test-ci/src/utils.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const colorRgb = (color: string): string => {
2+
var sColor = color.toLowerCase();
3+
//十六进制颜色值的正则表达式
4+
var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
5+
// 如果是16进制颜色
6+
if (sColor && reg.test(sColor)) {
7+
if (sColor.length === 4) {
8+
var sColorNew = '#';
9+
for (var i = 1; i < 4; i += 1) {
10+
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
11+
}
12+
sColor = sColorNew;
13+
}
14+
//处理六位的颜色值
15+
var sColorChange = [];
16+
for (var i = 1; i < 7; i += 2) {
17+
sColorChange.push(parseInt('0x' + sColor.slice(i, i + 2)));
18+
}
19+
return 'rgb(' + sColorChange.join(', ') + ')';
20+
}
21+
return sColor;
22+
};
23+
24+
export { colorRgb };

0 commit comments

Comments
 (0)