|
| 1 | +import React from 'react'; |
| 2 | +import {render} from '@testing-library/react-native'; |
| 3 | +import {ChipDriver} from '../chip.driver'; |
| 4 | +import Chip, {ChipProps} from '../index'; |
| 5 | +import Assets from '../../../assets'; |
| 6 | +import {Colors} from '../../../style'; |
| 7 | + |
| 8 | +const testID = 'test-chip'; |
| 9 | + |
| 10 | +const getDriver = (props?: ChipProps) => { |
| 11 | + const renderTree = render(<Chip testID={testID} {...props}/>); |
| 12 | + return ChipDriver({renderTree, testID}); |
| 13 | +}; |
| 14 | + |
| 15 | +describe('Chip', () => { |
| 16 | + describe('sanity', () => { |
| 17 | + it('should render Chip', () => { |
| 18 | + const driver = getDriver(); |
| 19 | + expect(driver.exists()).toBeTruthy(); |
| 20 | + expect(driver.getIcon().exists()).toBeFalsy(); |
| 21 | + expect(driver.getLabel().exists()).toBeFalsy(); |
| 22 | + expect(driver.getDismissIcon().exists()).toBeFalsy(); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + describe('Label', () => { |
| 27 | + it('should render label', () => { |
| 28 | + const driver = getDriver({label: 'test'}); |
| 29 | + expect(driver.getLabel().exists()).toBeTruthy(); |
| 30 | + expect(driver.getLabel().getText()).toEqual('test'); |
| 31 | + expect(driver.getLabel().getStyle().color).toEqual(Colors.$textDefault); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + describe('Dismiss Icon', () => { |
| 36 | + it('should render dismiss icon', () => { |
| 37 | + const driver = getDriver({onDismiss: () => {}}); |
| 38 | + expect(driver.getDismissIcon().exists()).toBeTruthy(); |
| 39 | + expect(driver.getDismissIcon().getStyle().tintColor).toEqual(Colors.$iconDefault); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + describe('Icon', () => { |
| 44 | + it('should render icon', () => { |
| 45 | + const driver = getDriver({iconSource: Assets.internal.icons.check}); |
| 46 | + expect(driver.getIcon().exists()).toBeTruthy(); |
| 47 | + expect(driver.getIcon().getStyle().tintColor).toEqual(Colors.$iconDefault); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should render with label, icon and dismiss icon', () => { |
| 52 | + const driver = getDriver({label: 'test', iconSource: Assets.internal.icons.check, onDismiss: () => {}}); |
| 53 | + expect(driver.getLabel().exists()).toBeTruthy(); |
| 54 | + expect(driver.getIcon().exists()).toBeTruthy(); |
| 55 | + expect(driver.getDismissIcon().exists()).toBeTruthy(); |
| 56 | + }); |
| 57 | +}); |
0 commit comments