From 9132f8cbe1f400ad8c29b4727982b52447b7deba Mon Sep 17 00:00:00 2001 From: Braden MacDonald Date: Mon, 2 Dec 2024 13:52:29 -0800 Subject: [PATCH] test: improve test coverage --- .../masquerade-widget/MasqueradeWidget.test.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/instructor-toolbar/masquerade-widget/MasqueradeWidget.test.tsx b/src/instructor-toolbar/masquerade-widget/MasqueradeWidget.test.tsx index 3e12486a84..46bf5cfac0 100644 --- a/src/instructor-toolbar/masquerade-widget/MasqueradeWidget.test.tsx +++ b/src/instructor-toolbar/masquerade-widget/MasqueradeWidget.test.tsx @@ -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'; @@ -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, @@ -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)); }); });