|
| 1 | +import 'react-native'; |
| 2 | +import React from 'react'; |
| 3 | +import Radio from '../lib/Radio'; |
| 4 | +import { render, fireEvent } from '@testing-library/react-native'; |
| 5 | + |
| 6 | +describe('Radio', () => { |
| 7 | + it('disabled', () => { |
| 8 | + const { getByTestId } = render(<Radio disabled />); |
| 9 | + const component = getByTestId('RNE__Radio__view'); |
| 10 | + expect(component.props.accessibilityState.disabled).toBe(true); |
| 11 | + }); |
| 12 | + |
| 13 | + it('borderColor', () => { |
| 14 | + const { getByTestId } = render(<Radio borderColor="#bdc1cc" />); |
| 15 | + const component = getByTestId('RNE__Radio__border'); |
| 16 | + expect(component.props.style.borderColor).toBe('#bdc1cc'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('checkedColor', () => { |
| 20 | + const { getByTestId } = render(<Radio checkedColor="#008EF0" />); |
| 21 | + const component = getByTestId('RNE__Radio__box'); |
| 22 | + expect(component.props.style.backgroundColor).toBe('#008EF0'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('circleSize', () => { |
| 26 | + const { getByTestId } = render(<Radio circleSize={21} />); |
| 27 | + const component = getByTestId('RNE__Radio__border'); |
| 28 | + expect(component.props.style.width).toBe(21); |
| 29 | + expect(component.props.style.height).toBe(21); |
| 30 | + }); |
| 31 | + |
| 32 | + it('onPress events', () => { |
| 33 | + const fn = jest.fn(); |
| 34 | + const { getByTestId } = render(<Radio onPress={fn} />); |
| 35 | + const component = getByTestId('RNE__Radio__view'); |
| 36 | + fireEvent(component, 'press'); |
| 37 | + expect(fn).toHaveBeenCalled(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('disabled onPress events', () => { |
| 41 | + const fn = jest.fn(); |
| 42 | + const { getByTestId } = render(<Radio disabled onPress={fn} />); |
| 43 | + const component = getByTestId('RNE__Radio__view'); |
| 44 | + fireEvent(component, 'press'); |
| 45 | + expect(fn).not.toHaveBeenCalled(); |
| 46 | + }); |
| 47 | +}); |
0 commit comments