Skip to content

Commit

Permalink
test: improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Dec 2, 2024
1 parent ea8efc5 commit c838d40
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
13 changes: 5 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"@testing-library/jest-dom": "5.17.0",
"@testing-library/react": "12.1.5",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "13.5.0",
"@testing-library/user-event": "14.5.2",
"axios-mock-adapter": "2.1.0",
"bundlewatch": "^0.4.0",
"eslint-import-resolver-webpack": "^0.13.9",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getConfig } from '@edx/frontend-platform';
import userEvent from '@testing-library/user-event';
import MockAdapter from 'axios-mock-adapter';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { MasqueradeWidget } from './MasqueradeWidget';
Expand Down Expand Up @@ -126,6 +127,7 @@ describe('Masquerade Widget Dropdown', () => {
});

it('can masquerade as a specific user', async () => {
const user = userEvent.setup();
// Configure our mock:
axiosMock.onPost(masqueradeUrl).reply(200, {
...mockResponse,
Expand All @@ -137,18 +139,18 @@ describe('Masquerade Widget Dropdown', () => {

// Select "specific student..."
const dropdownToggle = container.querySelector('.dropdown-toggle')!;
fireEvent.click(dropdownToggle);
await user.click(dropdownToggle);
const dropdownMenu = container.querySelector('.dropdown-menu') as HTMLElement;
const studentOption = getAllByRole(dropdownMenu, 'button', { hidden: true }).filter(
button => (button.textContent === 'Specific Student...'),
)[0];
fireEvent.click(studentOption);
await user.click(studentOption);

// Enter a username
// Enter a username, POST the request to the server
const usernameInput = await screen.findByLabelText(/Username or email/);
fireEvent.change(usernameInput, { target: { value: 'testUser' } });
await user.type(usernameInput, 'testuser');
expect(axiosMock.history.post).toHaveLength(0);
fireEvent.keyDown(usernameInput, { key: 'Enter' });
// await waitFor(() => expect(axiosMock.history.post).toHaveLength(1));
await user.keyboard('{Enter}');
await waitFor(() => expect(axiosMock.history.post).toHaveLength(1));
});
});

0 comments on commit c838d40

Please sign in to comment.