|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Akveo. All Rights Reserved. |
| 4 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 5 | + */ |
| 6 | + |
1 | 7 | import React from 'react';
|
2 |
| -import { TouchableOpacity } from 'react-native'; |
3 | 8 | import {
|
4 |
| - render, |
| 9 | + Text, |
| 10 | + TouchableOpacity, |
| 11 | +} from 'react-native'; |
| 12 | +import { |
5 | 13 | fireEvent,
|
6 |
| - waitForElement, |
7 |
| - shallow, |
8 |
| - RenderAPI, |
| 14 | + render, |
9 | 15 | } from 'react-native-testing-library';
|
10 |
| -import { ReactTestInstance } from 'react-test-renderer'; |
11 | 16 | import {
|
12 |
| - ApplicationProvider, |
13 |
| - ApplicationProviderProps, |
14 |
| -} from '@kitten/theme'; |
| 17 | + light, |
| 18 | + mapping, |
| 19 | +} from '@eva-design/eva'; |
| 20 | +import { ApplicationProvider } from '../../theme'; |
15 | 21 | import {
|
16 | 22 | Radio,
|
17 |
| - RadioComponent, |
18 | 23 | RadioProps,
|
19 | 24 | } from './radio.component';
|
20 |
| -import { |
21 |
| - mapping, |
22 |
| - theme, |
23 |
| -} from '../support/tests'; |
24 | 25 |
|
25 |
| -const Mock = (props?: RadioProps): React.ReactElement<ApplicationProviderProps> => { |
26 |
| - return ( |
| 26 | +describe('@radio: component checks', () => { |
| 27 | + |
| 28 | + const TestRadio = (props?: RadioProps) => ( |
27 | 29 | <ApplicationProvider
|
28 | 30 | mapping={mapping}
|
29 |
| - theme={theme}> |
| 31 | + theme={light}> |
30 | 32 | <Radio {...props} />
|
31 | 33 | </ApplicationProvider>
|
32 | 34 | );
|
33 |
| -}; |
34 |
| - |
35 |
| -const renderComponent = (props?: RadioProps): RenderAPI => { |
36 |
| - return render( |
37 |
| - <Mock {...props}/>, |
38 |
| - ); |
39 |
| -}; |
40 |
| - |
41 |
| -describe('@radio: matches snapshot', () => { |
42 | 35 |
|
43 |
| - it('default', () => { |
44 |
| - const component: RenderAPI = renderComponent(); |
45 |
| - const { output } = shallow(component.getByType(RadioComponent)); |
| 36 | + it('should request checking', () => { |
| 37 | + const onCheckedChange = jest.fn(); |
46 | 38 |
|
47 |
| - expect(output).toMatchSnapshot(); |
48 |
| - }); |
| 39 | + const component = render( |
| 40 | + <TestRadio |
| 41 | + checked={false} |
| 42 | + onChange={onCheckedChange} |
| 43 | + />, |
| 44 | + ); |
49 | 45 |
|
50 |
| - it('checked', () => { |
51 |
| - const component: RenderAPI = renderComponent({ checked: true }); |
52 |
| - const { output } = shallow(component.getByType(Radio)); |
| 46 | + fireEvent.press(component.getByType(TouchableOpacity)); |
53 | 47 |
|
54 |
| - expect(output).toMatchSnapshot(); |
| 48 | + expect(onCheckedChange).toBeCalledWith(true); |
55 | 49 | });
|
56 | 50 |
|
57 |
| - it('disabled', () => { |
58 |
| - const component: RenderAPI = renderComponent({ disabled: true }); |
59 |
| - const { output } = shallow(component.getByType(Radio)); |
| 51 | + it('should request unchecking', () => { |
| 52 | + const onCheckedChange = jest.fn(); |
60 | 53 |
|
61 |
| - expect(output).toMatchSnapshot(); |
62 |
| - }); |
| 54 | + const component = render( |
| 55 | + <TestRadio |
| 56 | + checked={true} |
| 57 | + onChange={onCheckedChange} |
| 58 | + />, |
| 59 | + ); |
63 | 60 |
|
64 |
| - it('checked disabled', () => { |
65 |
| - const component: RenderAPI = renderComponent({ |
66 |
| - checked: true, |
67 |
| - disabled: true, |
68 |
| - }); |
69 |
| - const { output } = shallow(component.getByType(Radio)); |
| 61 | + fireEvent.press(component.getByType(TouchableOpacity)); |
70 | 62 |
|
71 |
| - expect(output).toMatchSnapshot(); |
| 63 | + expect(onCheckedChange).toBeCalledWith(false); |
72 | 64 | });
|
73 | 65 |
|
74 |
| - it('active', async () => { |
75 |
| - const component: RenderAPI = renderComponent(); |
| 66 | + it('should render text', () => { |
| 67 | + const component = render( |
| 68 | + <TestRadio text='I love Babel'/>, |
| 69 | + ); |
76 | 70 |
|
77 |
| - fireEvent(component.getByType(TouchableOpacity), 'pressIn'); |
78 |
| - |
79 |
| - const active: ReactTestInstance = await waitForElement(() => { |
80 |
| - return component.getByType(Radio); |
81 |
| - }); |
82 |
| - const { output: activeOutput } = shallow(active); |
83 |
| - |
84 |
| - fireEvent(component.getByType(TouchableOpacity), 'pressOut'); |
| 71 | + const text = component.getByText('I love Babel'); |
85 | 72 |
|
86 |
| - const inactive: ReactTestInstance = await waitForElement(() => { |
87 |
| - return component.getByType(Radio); |
88 |
| - }); |
89 |
| - const { output: inactiveOutput } = shallow(inactive); |
90 |
| - |
91 |
| - expect(activeOutput).toMatchSnapshot(); |
92 |
| - expect(inactiveOutput).toMatchSnapshot('default'); |
| 73 | + expect(text).toBeTruthy(); |
93 | 74 | });
|
94 | 75 |
|
95 |
| - it('active checked', async () => { |
96 |
| - const component: RenderAPI = renderComponent({ checked: true }); |
| 76 | + it('should render text as component', () => { |
| 77 | + const component = render( |
| 78 | + <TestRadio text={props => <Text {...props}>I love Babel</Text>}/>, |
| 79 | + ); |
97 | 80 |
|
98 |
| - fireEvent(component.getByType(TouchableOpacity), 'pressIn'); |
| 81 | + const text = component.getByText('I love Babel'); |
99 | 82 |
|
100 |
| - const active: ReactTestInstance = await waitForElement(() => { |
101 |
| - return component.getByType(Radio); |
102 |
| - }); |
103 |
| - const { output: activeOutput } = shallow(active); |
| 83 | + expect(text).toBeTruthy(); |
| 84 | + }); |
104 | 85 |
|
105 |
| - fireEvent(component.getByType(TouchableOpacity), 'pressOut'); |
| 86 | + it('should call onPressIn', () => { |
| 87 | + const onPressIn = jest.fn(); |
106 | 88 |
|
107 |
| - const inactive: ReactTestInstance = await waitForElement(() => { |
108 |
| - return component.getByType(Radio); |
109 |
| - }); |
110 |
| - const { output: inactiveOutput } = shallow(inactive); |
| 89 | + const component = render( |
| 90 | + <TestRadio onPressIn={onPressIn}/>, |
| 91 | + ); |
111 | 92 |
|
112 |
| - expect(activeOutput).toMatchSnapshot(); |
113 |
| - expect(inactiveOutput).toMatchSnapshot('checked'); |
114 |
| - }); |
| 93 | + fireEvent(component.getByType(TouchableOpacity), 'pressIn'); |
115 | 94 |
|
116 |
| - it('with text (styled)', () => { |
117 |
| - const component: RenderAPI = renderComponent({ |
118 |
| - text: 'Place your text', |
119 |
| - textStyle: { |
120 |
| - fontSize: 22, |
121 |
| - lineHeight: 24, |
122 |
| - }, |
123 |
| - }); |
124 |
| - const { output } = shallow(component.getByType(Radio)); |
125 |
| - |
126 |
| - expect(output).toMatchSnapshot(); |
| 95 | + expect(onPressIn).toBeCalled(); |
127 | 96 | });
|
128 | 97 |
|
129 |
| -}); |
130 |
| - |
131 |
| -describe('@radio: component checks', () => { |
132 |
| - |
133 |
| - it('* emits onChange with correct args', () => { |
134 |
| - const onChange = jest.fn(); |
| 98 | + it('should call onPressOut', () => { |
| 99 | + const onPressOut = jest.fn(); |
135 | 100 |
|
136 |
| - const component: RenderAPI = renderComponent({ |
137 |
| - checked: false, |
138 |
| - onChange: onChange, |
139 |
| - }); |
| 101 | + const component = render( |
| 102 | + <TestRadio onPressOut={onPressOut}/>, |
| 103 | + ); |
140 | 104 |
|
141 |
| - fireEvent.press(component.getByType(TouchableOpacity)); |
| 105 | + fireEvent(component.getByType(TouchableOpacity), 'pressOut'); |
142 | 106 |
|
143 |
| - expect(onChange).toBeCalledWith(true); |
| 107 | + expect(onPressOut).toBeCalled(); |
144 | 108 | });
|
145 | 109 |
|
146 | 110 | });
|
0 commit comments