Skip to content

Commit

Permalink
fix: correct condition to accept id equal zero (#3936)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak authored Jun 28, 2023
1 parent 742c7a0 commit a5168ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/List/ListAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const ListAccordion = ({
const expandedInternal = expandedProp !== undefined ? expandedProp : expanded;

const groupContext = React.useContext(ListAccordionGroupContext);
if (groupContext !== null && !id) {
if (groupContext !== null && (id === undefined || id === null || id === '')) {
throw new Error(
'List.Accordion is used inside a List.AccordionGroup without specifying an id prop.'
);
Expand Down
33 changes: 32 additions & 1 deletion src/components/__tests__/ListAccordion.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as React from 'react';
import { StyleSheet } from 'react-native';
import { StyleSheet, View } from 'react-native';

import { render } from '@testing-library/react-native';
import color from 'color';

import { getTheme } from '../../core/theming';
import { red500 } from '../../styles/themes/v2/colors';
import ListAccordion from '../List/ListAccordion';
import ListAccordionGroup from '../List/ListAccordionGroup';
import ListIcon from '../List/ListIcon';
import ListItem from '../List/ListItem';
import { getAccordionColors } from '../List/utils';
Expand Down Expand Up @@ -84,6 +85,36 @@ it('renders list accordion with custom title and description styles', () => {
expect(tree).toMatchSnapshot();
});

describe('ListAccordion', () => {
it('should not throw an error when id={0}', () => {
const ListAccordionTest = () => (
<ListAccordionGroup>
<ListAccordion title="Testing list" id={0}>
<View></View>
</ListAccordion>
</ListAccordionGroup>
);

expect(() => render(<ListAccordionTest />)).not.toThrow(
'List.Accordion is used inside a List.AccordionGroup without specifying an id prop.'
);
});

it('should throw an error when id={""}', () => {
const ListAccordionTest = () => (
<ListAccordionGroup>
<ListAccordion title="Testing list" id={''}>
<View></View>
</ListAccordion>
</ListAccordionGroup>
);

expect(() => render(<ListAccordionTest />)).toThrow(
'List.Accordion is used inside a List.AccordionGroup without specifying an id prop.'
);
});
});

describe('getAccordionColors - title color', () => {
it('should return theme color, for theme version 3', () => {
expect(
Expand Down

0 comments on commit a5168ae

Please sign in to comment.