Skip to content

Commit

Permalink
test: adjusted UserTable unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva committed Sep 18, 2024
1 parent 7eec447 commit f4d5a44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
33 changes: 21 additions & 12 deletions apps/meteor/client/views/admin/users/UsersTable/UsersTable.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const createFakeAdminUser = (freeSwitchExtension?: string) =>
freeSwitchExtension,
});

it('should not render "Voice Call Extension" column when VoIP is disabled', () => {
it('should not render "Voice call extension" column when voice call is disabled', async () => {
const user = createFakeAdminUser('1000');

render(
Expand All @@ -33,12 +33,15 @@ it('should not render "Voice Call Extension" column when VoIP is disabled', () =
},
);

expect(screen.queryByText('Voice_Call_Extension')).not.toBeInTheDocument();
expect(screen.queryByTitle('Remove_Association')).not.toBeInTheDocument();
expect(screen.queryByTitle('Associate_Extension')).not.toBeInTheDocument();
expect(screen.queryByText('Voice_call_extension')).not.toBeInTheDocument();

screen.getByRole('button', { name: 'More_actions' }).click();
expect(await screen.findByRole('listbox')).toBeInTheDocument();
expect(screen.queryByRole('option', { name: /Assign_extension/ })).not.toBeInTheDocument();
expect(screen.queryByRole('option', { name: /Unassign_extension/ })).not.toBeInTheDocument();
});

it('should render "Remove_Association" button when user has a associated extension', () => {
it('should render "Unassign_extension" button when user has a associated extension', async () => {
const user = createFakeAdminUser('1000');

render(
Expand All @@ -58,12 +61,15 @@ it('should render "Remove_Association" button when user has a associated extensi
},
);

expect(screen.getByText('Voice_Call_Extension')).toBeInTheDocument();
expect(screen.queryByTitle('Associate_Extension')).not.toBeInTheDocument();
expect(screen.getByTitle('Remove_Association')).toBeEnabled();
expect(screen.getByText('Voice_call_extension')).toBeInTheDocument();

screen.getByRole('button', { name: 'More_actions' }).click();
expect(await screen.findByRole('listbox')).toBeInTheDocument();
expect(screen.queryByRole('option', { name: /Assign_extension/ })).not.toBeInTheDocument();
expect(screen.getByRole('option', { name: /Unassign_extension/ })).toBeInTheDocument();
});

it('should render "Associate_Extension" button when user has no associated extension', () => {
it('should render "Assign_extension" button when user has no associated extension', async () => {
const user = createFakeAdminUser();

render(
Expand All @@ -83,7 +89,10 @@ it('should render "Associate_Extension" button when user has no associated exten
},
);

expect(screen.getByText('Voice_Call_Extension')).toBeInTheDocument();
expect(screen.queryByTitle('Remove_Association')).not.toBeInTheDocument();
expect(screen.getByTitle('Associate_Extension')).toBeEnabled();
expect(screen.getByText('Voice_call_extension')).toBeInTheDocument();

screen.getByRole('button', { name: 'More_actions' }).click();
expect(await screen.findByRole('listbox')).toBeInTheDocument();
expect(screen.getByRole('option', { name: /Assign_extension/ })).toBeInTheDocument();
expect(screen.queryByRole('option', { name: /Unassign_extension/ })).not.toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ const UsersTableRow = ({
placement='bottom-start'
flexShrink={0}
key='menu'
aria-label={t('More_actions')}
title={t('More_actions')}
renderItem={({ label: { label, icon }, ...props }): ReactElement => (
<Option label={label} title={label} icon={icon} variant={label === 'Delete' ? 'danger' : ''} {...props} />
)}
Expand Down

0 comments on commit f4d5a44

Please sign in to comment.