Skip to content

Commit

Permalink
simplify tests (afterEach of Select All tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanMarmelab committed Dec 17, 2024
1 parent c8d447b commit ea989da
Showing 1 changed file with 9 additions and 43 deletions.
52 changes: 9 additions & 43 deletions packages/ra-ui-materialui/src/list/List.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,25 +345,11 @@ describe('<List />', () => {
});

describe('"Select all" button', () => {
const Child = () => {
const [_, selectionModifiers] = useRecordSelection({
resource: 'books',
});
return (
<button onClick={() => selectionModifiers.clearSelection()}>
reset
</button>
);
};
afterEach(() => {
fireEvent.click(screen.getByRole('button', { name: 'reset' }));
fireEvent.click(screen.getByRole('button', { name: 'Unselect' }));
});
it('should be displayed if an item is selected', async () => {
render(
<Default>
<Child />
</Default>
);
render(<Default />);
await waitFor(() => {
expect(screen.queryAllByRole('checkbox')).toHaveLength(11);
});
Expand Down Expand Up @@ -395,9 +381,7 @@ describe('<List />', () => {
total: 2,
}),
})}
>
<Child />
</Default>
/>
);
await waitFor(() => {
expect(screen.queryAllByRole('checkbox')).toHaveLength(3);
Expand All @@ -409,11 +393,7 @@ describe('<List />', () => {
).toBeNull();
});
it('should not be displayed if all item are selected with the "Select all" button', async () => {
render(
<Default>
<Child />
</Default>
);
render(<Default />);
await waitFor(() => {
expect(screen.queryAllByRole('checkbox')).toHaveLength(11);
});
Expand Down Expand Up @@ -455,9 +435,7 @@ describe('<List />', () => {
total: 3,
}),
})}
>
<Child />
</SelectAllLimit>
/>
);
await waitFor(() => {
expect(screen.queryAllByRole('checkbox')).toHaveLength(4);
Expand All @@ -470,11 +448,7 @@ describe('<List />', () => {
).toBeNull();
});
it('should not be displayed if we reached the selectAllLimit by a click on the "Select all" button', async () => {
render(
<SelectAllLimit>
<Child />
</SelectAllLimit>
);
render(<SelectAllLimit />);
await waitFor(() => {
expect(screen.queryAllByRole('checkbox')).toHaveLength(11);
});
Expand All @@ -490,11 +464,7 @@ describe('<List />', () => {
).toBeNull();
});
it('should select all items', async () => {
render(
<Default>
<Child />
</Default>
);
render(<Default />);
await waitFor(() => {
expect(screen.queryAllByRole('checkbox')).toHaveLength(11);
});
Expand All @@ -503,12 +473,8 @@ describe('<List />', () => {
fireEvent.click(screen.getByRole('button', { name: 'Select all' }));
await screen.findByText('13 items selected');
});
it('should select the maximum items possible until we reached the selectAllLimit', async () => {
render(
<SelectAllLimit>
<Child />
</SelectAllLimit>
);
it.only('should select the maximum items possible until we reached the selectAllLimit', async () => {
render(<SelectAllLimit />);
await waitFor(() => {
expect(screen.queryAllByRole('checkbox')).toHaveLength(11);
});
Expand Down

0 comments on commit ea989da

Please sign in to comment.