Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dottorblaster committed Sep 1, 2023
1 parent ec2c3da commit 8516b59
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion assets/js/components/Table/Table.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('Table component', () => {
});
});

test('should return empty state message when data is empty', () => {
it('should return empty state message when data is empty', () => {
const data = [];
const emptyStateText = faker.random.words(5);
render(
Expand All @@ -157,4 +157,30 @@ describe('Table component', () => {
expect(tableCell).toHaveTextContent(emptyStateText);
});
});

describe('rowKey function', () => {
it('is used to determine keys for rows', async () => {
const rowKey = jest.fn((_item, index) => index);
const data = tableDataFactory.buildList(5);

render(
<Table
config={tableConfig}
data={data}
setSearchParams={() => {}}
rowKey={rowKey}
/>
);

await waitFor(() => {
const table = screen.getByRole('table');
expect(table.querySelectorAll('tbody > tr')).toHaveLength(5);
});

expect(rowKey).toHaveBeenCalledTimes(5);
expect(rowKey).toHaveBeenCalledWith(data[0], 0);
expect(rowKey).toHaveBeenCalledWith(data[1], 1);
expect(rowKey).toHaveBeenCalledWith(data[2], 2);
});
});
});

0 comments on commit 8516b59

Please sign in to comment.