Skip to content

Commit

Permalink
Add a regression test and update types
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinhenderson committed Jul 30, 2021
1 parent deff86a commit 980d745
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
28 changes: 27 additions & 1 deletion src/components/AccordionItem.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { cleanup, render } from '@testing-library/react';
import { cleanup, render, fireEvent } from '@testing-library/react';
import * as React from 'react';
import { default as Accordion } from './Accordion';
import AccordionItem from './AccordionItem';
import AccordionItemButton from './AccordionItemButton';

enum UUIDS {
FOO = 'FOO',
Expand Down Expand Up @@ -74,4 +75,29 @@ describe('AccordionItem', () => {
expect(getByText('Hello World')).toBeTruthy();
});
});

describe('uuid prop', () => {
it('keeps the uuid as 0 even though its falsy', () => {
const testId = 'el-with-zero-uuid';
const zero = 0;
let selected: (string | number)[] = [];
const { getByTestId } = render(
<Accordion
onChange={(latestSelected) => {
selected = latestSelected;
}}
>
<AccordionItem uuid={zero}>
<AccordionItemButton data-testid={testId}>
Click me
</AccordionItemButton>
</AccordionItem>
</Accordion>,
);

fireEvent.click(getByTestId(testId));

expect(selected).toEqual([zero]);
});
});
});
2 changes: 1 addition & 1 deletion src/components/AccordionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const AccordionItem = ({
);
};

assertValidHtmlId(uuid);
assertValidHtmlId(uuid.toString());
if (rest.id) {
assertValidHtmlId(rest.id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ItemContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Consumer as AccordionContextConsumer,
} from './AccordionContext';

export type UUID = string;
export type UUID = string | number;

type ProviderProps = {
children?: React.ReactNode;
Expand Down

0 comments on commit 980d745

Please sign in to comment.