|
| 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