Skip to content

Commit

Permalink
test: get by role instead of testId on AssignExtensionModal
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva committed Sep 13, 2024
1 parent e758fda commit 54c599d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,25 @@ const root = mockAppRoot()
success: true,
}));

// TODO: it('should load with default user', async () => {});
it.todo('should load with default user');

// TODO: it('should load with default extension', async () => {});
it.todo('should load with default extension');

it('should only enable "Free Extension Numbers" field if username is informed', async () => {
render(<AssignExtensionModal onClose={() => undefined} />, {
legacyRoot: true,
wrapper: root.build(),
});

expect(screen.getByTestId('input-free-extension-numbers')).toHaveClass('disabled');
const extensionsSelect = screen.getByRole('button', { name: /Select_an_option/i });
expect(extensionsSelect).toHaveClass('disabled');
expect(screen.getByLabelText('User_Without_Extensions')).toBeEnabled();

screen.getByLabelText('User_Without_Extensions').focus();
const userOption = await screen.findByRole('option', { name: 'Jane Doe' });
await userEvent.click(userOption);

await waitFor(() => expect(screen.getByTestId('input-free-extension-numbers')).not.toHaveClass('disabled'));
await waitFor(() => expect(extensionsSelect).not.toHaveClass('disabled'));
});

it('should only enable "Associate" button both username and extension is informed', async () => {
Expand All @@ -74,9 +75,10 @@ it('should only enable "Associate" button both username and extension is informe
const userOption = await screen.findByRole('option', { name: 'Jane Doe' });
await userEvent.click(userOption);

await waitFor(() => expect(screen.getByTestId('input-free-extension-numbers')).not.toHaveClass('disabled'));
const extensionsSelect = screen.getByRole('button', { name: /Select_an_option/i });
await waitFor(() => expect(extensionsSelect).not.toHaveClass('disabled'));

screen.getByTestId('input-free-extension-numbers').click();
extensionsSelect.click();
const extOption = await screen.findByRole('option', { name: '1000' });
await userEvent.click(extOption);

Expand All @@ -94,9 +96,10 @@ it('should call onClose when extension is associated', async () => {
const userOption = await screen.findByRole('option', { name: 'Jane Doe' });
await userEvent.click(userOption);

await waitFor(() => expect(screen.getByTestId('input-free-extension-numbers')).not.toHaveClass('disabled'));
const extensionsSelect = screen.getByRole('button', { name: /Select_an_option/i });
await waitFor(() => expect(extensionsSelect).not.toHaveClass('disabled'));

screen.getByTestId('input-free-extension-numbers').click();
extensionsSelect.click();
const extOption = await screen.findByRole('option', { name: '1000' });
await userEvent.click(extOption);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ const AssignExtensionModal = ({ defaultExtension, defaultUsername, onClose }: As
placeholder={t('Select_an_option')}
value={field.value}
onChange={field.onChange}
data-testid='input-free-extension-numbers'
/>
)}
/>
Expand Down

0 comments on commit 54c599d

Please sign in to comment.