|
1 | 1 | import React from 'react'; |
2 | 2 | import { fireEvent, render, waitFor } from './test-utils'; |
3 | | -import { Radio, Text } from '../src'; |
| 3 | +import { Radio, RadioCircle, Text } from '../src'; |
4 | 4 | import { View } from 'react-native'; |
| 5 | +import { RADIO_LARGE, RADIO_MEDIUM, RADIO_SMALL } from '../src/components/Radio/constants'; |
5 | 6 |
|
6 | 7 | describe('Radio Component', () => { |
7 | 8 | const mockRadioBaseButtonTestId = 'radio-base-button-test-id'; |
@@ -92,4 +93,110 @@ describe('Radio Component', () => { |
92 | 93 | expect(queryByText('mock-label')).toBeNull(); |
93 | 94 | expect(queryByText('mock-description')).toBeNull(); |
94 | 95 | }); |
| 96 | + |
| 97 | + it('should render the divider component', () => { |
| 98 | + const { getByTestId } = render(<Radio showDivider dividerProps={{ testID: 'divider' }} />); |
| 99 | + |
| 100 | + const divider = getByTestId('divider'); |
| 101 | + expect(divider).toBeDefined(); |
| 102 | + }); |
| 103 | + |
| 104 | + it('should call the onPress function when click on the label component', () => { |
| 105 | + const { getByText } = render(<Radio onPress={mockOnPress} actionType="root" label="label" />); |
| 106 | + |
| 107 | + const label = getByText('label'); |
| 108 | + expect(label).toBeDefined(); |
| 109 | + |
| 110 | + fireEvent(label, 'press', { nativeEvent: {} }); |
| 111 | + |
| 112 | + expect(mockOnPress).toHaveBeenCalled(); |
| 113 | + expect(mockOnPress).toHaveBeenCalledTimes(1); |
| 114 | + }); |
| 115 | + |
| 116 | + it('should call the onPress function when click on the radio button', () => { |
| 117 | + const { getByTestId } = render(<Radio onPress={mockOnPress} radioBaseButtonTestId={mockRadioBaseButtonTestId} />); |
| 118 | + |
| 119 | + const radio = getByTestId(mockRadioBaseButtonTestId); |
| 120 | + |
| 121 | + expect(radio).toBeDefined(); |
| 122 | + |
| 123 | + fireEvent(radio, 'press', { nativeEvent: {} }); |
| 124 | + |
| 125 | + expect(mockOnPress).toHaveBeenCalled(); |
| 126 | + expect(mockOnPress).toHaveBeenCalledTimes(1); |
| 127 | + }); |
| 128 | + |
| 129 | + it('should render the custom radio item if radio isActive', () => { |
| 130 | + const { getByText } = render(<Radio isActive radioItem={<Text>Hello</Text>} />); |
| 131 | + const text = getByText('Hello'); |
| 132 | + expect(text).toBeDefined(); |
| 133 | + }); |
| 134 | + |
| 135 | + it('should render the start adornment component', () => { |
| 136 | + const { getByText } = render(<Radio adornment={<Text>Hello</Text>} adornmentType="start" />); |
| 137 | + |
| 138 | + const text = getByText('Hello'); |
| 139 | + expect(text).toBeDefined(); |
| 140 | + }); |
| 141 | + |
| 142 | + it('should render the start adornment divider component', () => { |
| 143 | + const { getByTestId } = render( |
| 144 | + <Radio showDivider dividerProps={{ testID: 'divider-test-id' }} adornment={<Text>Hello</Text>} adornmentType="start" />, |
| 145 | + ); |
| 146 | + |
| 147 | + const divider = getByTestId('divider-test-id'); |
| 148 | + expect(divider).toBeDefined(); |
| 149 | + }); |
| 150 | + |
| 151 | + it('should render active radio item when radio is active', () => { |
| 152 | + jest.useFakeTimers(); |
| 153 | + const { getByTestId } = render(<Radio isActive />); |
| 154 | + const radioItem = getByTestId('radio-item-test-id'); |
| 155 | + expect(radioItem).toBeDefined(); |
| 156 | + jest.clearAllTimers(); |
| 157 | + }); |
| 158 | +}); |
| 159 | + |
| 160 | +describe('Radio Circle', () => { |
| 161 | + const testID = 'mock-test-id'; |
| 162 | + |
| 163 | + beforeEach(() => { |
| 164 | + jest.clearAllMocks(); |
| 165 | + }); |
| 166 | + |
| 167 | + it('should render small divider component', () => { |
| 168 | + const { getByTestId } = render(<RadioCircle size="small" testID={testID} />); |
| 169 | + |
| 170 | + const radio = getByTestId(testID); |
| 171 | + |
| 172 | + expect(radio).toBeDefined(); |
| 173 | + expect(radio.props.style.width).toEqual(RADIO_SMALL); |
| 174 | + }); |
| 175 | + |
| 176 | + it('should render medium radioCircle component', () => { |
| 177 | + const { getByTestId } = render(<RadioCircle size="medium" testID={testID} />); |
| 178 | + |
| 179 | + const radio = getByTestId(testID); |
| 180 | + |
| 181 | + expect(radio).toBeDefined(); |
| 182 | + expect(radio.props.style.width).toEqual(RADIO_MEDIUM); |
| 183 | + }); |
| 184 | + |
| 185 | + it('should render large radioCircle component', () => { |
| 186 | + const { getByTestId } = render(<RadioCircle size="large" testID={testID} />); |
| 187 | + |
| 188 | + const radio = getByTestId(testID); |
| 189 | + |
| 190 | + expect(radio).toBeDefined(); |
| 191 | + expect(radio.props.style.width).toEqual(RADIO_LARGE); |
| 192 | + }); |
| 193 | + |
| 194 | + it('should render small radioCircle component when invalid size passed', () => { |
| 195 | + const { getByTestId } = render(<RadioCircle size={'invalid' as any} testID={testID} />); |
| 196 | + |
| 197 | + const radio = getByTestId(testID); |
| 198 | + |
| 199 | + expect(radio).toBeDefined(); |
| 200 | + expect(radio.props.style.width).toEqual(RADIO_SMALL); |
| 201 | + }); |
95 | 202 | }); |
0 commit comments