Add test for SwitchListItem badge

This commit is contained in:
Bill Thornton 2021-11-04 13:18:03 -04:00
parent 884504bd75
commit d3c1e05b88
2 changed files with 21 additions and 5 deletions

View File

@ -24,6 +24,7 @@ const SwitchListItem = ({ item, index }) => (
{(
item.badge &&
<Badge
testID='badge'
value={item.badge.value}
status={item.badge.status}
containerStyle={{ marginStart: 8 }}

View File

@ -12,7 +12,7 @@ describe('SwitchListItem', () => {
it('should render correctly and handle change event', () => {
const onValueChange = jest.fn();
const { getByTestId } = render(
const { getByTestId, queryByTestId } = render(
<SwitchListItem
index={0}
item={{
@ -25,6 +25,8 @@ describe('SwitchListItem', () => {
);
expect(getByTestId('title')).toHaveTextContent('Test Switch');
expect(queryByTestId('subtitle')).toBeNull();
expect(queryByTestId('badge')).toBeNull();
const switchItem = getByTestId('switch');
expect(switchItem).toHaveProp('disabled', false);
@ -35,16 +37,29 @@ describe('SwitchListItem', () => {
expect(onValueChange).toHaveBeenCalled();
});
it('should render a badge if provided', () => {
const { getByTestId } = render(
<SwitchListItem
index={0}
item={{
title: 'Test Switch',
badge: {
value: 'Badge'
}
}}
/>
);
expect(getByTestId('badge')).toHaveTextContent('Badge');
});
it('should render subtitle if provided', () => {
const { getByTestId } = render(
<SwitchListItem
index={0}
item={{
title: 'Test Switch',
subtitle: 'Test Subtitle',
disabled: false,
value: true,
onValueChange: jest.fn()
subtitle: 'Test Subtitle'
}}
/>
);