catalog: update DefaultCatalogPage test

This test appears to be checking for a regression in which the filter
reset from starred to owned after starring an entity. As a precursor,
it tried to select all three possible filters, but now it's no longer
possible to select filters that don't have any matching entities.

Now that the behaviour of menu items when there are no items in that
filter has changed, this commit updates the test to confirm that the
menu item starts disabled, and then enables when an entity is starred.

Signed-off-by: MT Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
MT Lewis
2022-01-28 10:29:27 +00:00
parent ce383faaef
commit 91ffc2ade2
2 changed files with 14 additions and 10 deletions
@@ -231,6 +231,7 @@ export const UserListPicker = ({
selected={item.id === filters.user?.value}
className={classes.menuItem}
disabled={filterCounts[item.id] === 0}
data-testid={`user-picker-${item.id}`}
>
{item.icon && (
<ListItemIcon className={classes.listIcon}>
@@ -238,12 +239,7 @@ export const UserListPicker = ({
</ListItemIcon>
)}
<ListItemText>
<Typography
variant="body1"
data-testid={`user-picker-${item.id}`}
>
{item.label}
</Typography>
<Typography variant="body1">{item.label}</Typography>
</ListItemText>
<ListItemSecondaryAction>
{filterCounts[item.id] ?? '-'}
@@ -263,10 +263,12 @@ describe('DefaultCatalogPage', () => {
const { getByTestId } = await renderWrapped(<DefaultCatalogPage />);
fireEvent.click(getByTestId('user-picker-owned'));
await expect(screen.findByText(/Owned \(1\)/)).resolves.toBeInTheDocument();
fireEvent.click(screen.getByTestId('user-picker-starred'));
await expect(
screen.findByText(/Starred \(0\)/),
).resolves.toBeInTheDocument();
// The "Starred" menu option should initially be disabled, since there
// aren't any starred entities.
await expect(screen.getByTestId('user-picker-starred')).toHaveAttribute(
'aria-disabled',
'true',
);
fireEvent.click(screen.getByTestId('user-picker-all'));
await expect(screen.findByText(/All \(2\)/)).resolves.toBeInTheDocument();
@@ -274,6 +276,12 @@ describe('DefaultCatalogPage', () => {
fireEvent.click(starredIcons[0]);
await expect(screen.findByText(/All \(2\)/)).resolves.toBeInTheDocument();
// Now that we've starred an entity, the "Starred" menu option should be
// enabled.
await expect(screen.getByTestId('user-picker-starred')).not.toHaveAttribute(
'aria-disabled',
'true',
);
fireEvent.click(screen.getByTestId('user-picker-starred'));
await expect(
screen.findByText(/Starred \(1\)/),