Skip to content

Commit d2c572f

Browse files
committed
test(Icon): add Icon test
1 parent ad175c0 commit d2c572f

File tree

3 files changed

+92
-28
lines changed

3 files changed

+92
-28
lines changed

packages/core/src/Icon/index.tsx

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,34 @@ export interface IconsProps extends SvgProps {
1919
xml?: string;
2020
}
2121

22-
export default class Icons extends React.Component<IconsProps> {
23-
static displayName = 'uiwm.Icon';
24-
static defaultProps: IconsProps = {
25-
size: 26,
26-
};
27-
render() {
28-
const { name, size, fill = '#000000', stroke, xml, paths, color, ...otherProps } = this.props;
29-
if (xml) {
30-
return <SvgXml xml={xml} height={size} width={size} {...otherProps} />;
31-
}
32-
let pathData = paths;
33-
if (!pathData) {
34-
if (!name || !svgPaths[name]) {
35-
return null;
36-
}
37-
pathData = svgPaths[name] as string[];
22+
export default (props: IconsProps) => {
23+
const { size = 26, name, fill = '#000000', stroke, xml, paths, color, ...otherProps } = props;
24+
25+
if (xml) {
26+
return <SvgXml testID="RNE__Icon__svgXml" xml={xml} height={size} width={size} {...otherProps} />;
27+
}
28+
29+
let pathData = paths;
30+
if (!pathData) {
31+
if (!name || !svgPaths[name]) {
32+
return null;
3833
}
39-
return (
40-
<Svg fill={color || fill} stroke={stroke} height={size} width={size} viewBox="0 0 20 20" {...otherProps}>
41-
{pathData.map((d: string, i: number) => (
42-
<Path key={i} d={d} fillRule="evenodd" />
43-
))}
44-
</Svg>
45-
);
34+
pathData = svgPaths[name] as string[];
4635
}
47-
}
36+
37+
return (
38+
<Svg
39+
testID="RNE__Icon__svg"
40+
fill={color || fill}
41+
stroke={stroke}
42+
height={size}
43+
width={size}
44+
viewBox="0 0 20 20"
45+
{...otherProps}
46+
>
47+
{pathData.map((d: string, i: number) => (
48+
<Path key={i} d={d} fillRule="evenodd" />
49+
))}
50+
</Svg>
51+
);
52+
};

test-ci/src/__tests__/buttonGroup.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// import ButtonGroup from '../lib/ButtonGroup';
2-
// import Button from '../lib/Button';
3-
// import renderer from 'react-test-renderer';
4-
51
import 'react-native';
62
import React from 'react';
73
import ButtonGroup from '../lib/ButtonGroup';

test-ci/src/__tests__/icon.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import 'react-native';
2+
import React from 'react';
3+
import Icon from '../lib/Icon';
4+
import { render, fireEvent } from '@testing-library/react-native';
5+
import svgPaths from '@uiw/icons/fonts/w-icon.json';
6+
7+
describe('Icon', () => {
8+
// it('name', () => {
9+
// const { getByTestId } = render(<Icon name='apple' />);
10+
// const component = getByTestId('RNE__Icon__svg');
11+
// const svg = component.props.children.props.children[0].props.d;
12+
// expect(svg).toBe(svgPaths['apple'][0]);
13+
// });
14+
15+
it('fill', () => {
16+
const { getByTestId } = render(<Icon name="apple" fill="#ff0000" />);
17+
const component = getByTestId('RNE__Icon__svg');
18+
expect(component.props.fill).toBe('#ff0000');
19+
});
20+
21+
it('stroke', () => {
22+
const { getByTestId } = render(<Icon name="apple" stroke="#ffff00" />);
23+
const component = getByTestId('RNE__Icon__svg');
24+
expect(component.props.stroke).toBe('#ffff00');
25+
});
26+
27+
it('xml', () => {
28+
const xml = `
29+
<svg width="20" height="20" viewBox="0 0 20 20">
30+
<path
31+
fill-rule="evenodd"
32+
fill="#000"
33+
d="M19 8h-1.26c-.19-.73-.48-1.42-.85-2.06l.94-.94a.996.996 0 0 0 0-1.41l-1.41-1.41a.996.996 0 0 0-1.41 0l-.94.94c-.65-.38-1.34-.67-2.07-.86V1c0-.55-.45-1-1-1H9c-.55 0-1 .45-1 1v1.26c-.76.2-1.47.5-2.13.89L5 2.28a.972.972 0 0 0-1.36 0L2.28 3.64c-.37.38-.37.98 0 1.36l.87.87c-.39.66-.69 1.37-.89 2.13H1c-.55 0-1 .45-1 1v2c0 .55.45 1 1 1h1.26c.19.73.48 1.42.85 2.06l-.94.94a.996.996 0 0 0 0 1.41l1.41 1.41c.39.39 1.02.39 1.41 0l.94-.94c.64.38 1.33.66 2.06.85V19c0 .55.45 1 1 1h2c.55 0 1-.45 1-1v-1.26c.76-.2 1.47-.5 2.13-.89l.88.87c.37.37.98.37 1.36 0l1.36-1.36c.37-.38.37-.98 0-1.36l-.87-.87c.4-.65.7-1.37.89-2.13H19c.55 0 1-.45 1-1V9c0-.55-.45-1-1-1zm-9 7c-2.76 0-5-2.24-5-5s2.24-5 5-5v10z"
34+
/>
35+
</svg>
36+
`;
37+
const { getByTestId } = render(<Icon xml={xml} />);
38+
const component = getByTestId('RNE__Icon__svgXml');
39+
expect(component.props.xml).toBe(xml);
40+
});
41+
42+
it('size', () => {
43+
const { getByTestId } = render(<Icon name="apple" size={21} />);
44+
const component = getByTestId('RNE__Icon__svg');
45+
expect(component.props.width).toBe(21);
46+
expect(component.props.height).toBe(21);
47+
});
48+
49+
it('width and height', () => {
50+
const { getByTestId } = render(<Icon name="apple" width={21} height={22} />);
51+
const component = getByTestId('RNE__Icon__svg');
52+
expect(component.props.width).toBe(21);
53+
expect(component.props.height).toBe(22);
54+
});
55+
56+
it('onPress', () => {
57+
const fn = jest.fn();
58+
const { getByTestId } = render(<Icon name="apple" onPress={fn} />);
59+
const component = getByTestId('RNE__Icon__svg');
60+
fireEvent(component, 'press');
61+
expect(fn).toHaveBeenCalled();
62+
});
63+
});

0 commit comments

Comments
 (0)