diff --git a/package-lock.json b/package-lock.json index a84a98d4f4..4878aac286 100644 --- a/package-lock.json +++ b/package-lock.json @@ -60,7 +60,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", @@ -5035,15 +5035,12 @@ } }, "node_modules/@testing-library/user-event": { - "version": "13.5.0", - "resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-13.5.0.tgz", - "integrity": "sha512-5Kwtbo3Y/NowpkbRuSepbyMFkZmHgD+vPzYB/RJ4oxt5Gj/avFFBYjhw27cqSVPVw/3a67NK1PbiIr9k4Gwmdg==", + "version": "14.5.2", + "resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-14.5.2.tgz", + "integrity": "sha512-YAh82Wh4TIrxYLmfGcixwD18oIjyC1pFQC2Y01F2lzV2HTMiYrI0nze0FD0ocB//CKS/7jIUgae+adPqxK5yCQ==", "dev": true, - "dependencies": { - "@babel/runtime": "^7.12.5" - }, "engines": { - "node": ">=10", + "node": ">=12", "npm": ">=6" }, "peerDependencies": { diff --git a/package.json b/package.json index cad59273d8..3310dbdf7f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/course-home/dates-tab/DatesTab.test.jsx b/src/course-home/dates-tab/DatesTab.test.jsx index 329e23f84c..17dcd34ad4 100644 --- a/src/course-home/dates-tab/DatesTab.test.jsx +++ b/src/course-home/dates-tab/DatesTab.test.jsx @@ -135,6 +135,7 @@ describe('DatesTab', () => { }); it('shows extra info', async () => { + const user = userEvent.setup(); const { items } = await getDay('Sat, Aug 17, 2030'); expect(items).toHaveLength(3); @@ -142,10 +143,12 @@ describe('DatesTab', () => { const tipText = "ORA Dates are set by the instructor, and can't be changed"; expect(screen.queryByText(tipText)).toBeNull(); // tooltip does not start in DOM - userEvent.hover(tipIcon); - const tooltip = screen.getByText(tipText); // now it's there - userEvent.unhover(tipIcon); - await waitForElementToBeRemoved(tooltip); // and it's gone again + await user.hover(tipIcon); + screen.getByText(tipText); // now it's there + await user.unhover(tipIcon); + await waitFor(() => { + expect(screen.queryByText(tipText)).toBeNull(); // and it's gone again + }); }); }); diff --git a/src/course-home/outline-tab/OutlineTab.test.jsx b/src/course-home/outline-tab/OutlineTab.test.jsx index 817612d31e..da1ceb5eb5 100644 --- a/src/course-home/outline-tab/OutlineTab.test.jsx +++ b/src/course-home/outline-tab/OutlineTab.test.jsx @@ -143,6 +143,7 @@ describe('Outline Tab', () => { }); it('handles expand/collapse all button click', async () => { + const user = userEvent.setup(); await fetchAndRender(); // Button renders as "Expand All" const expandButton = screen.getByRole('button', { name: 'Expand all' }); @@ -153,11 +154,11 @@ describe('Outline Tab', () => { expect(collapsedSectionNode).toHaveAttribute('aria-expanded', 'false'); // Click to expand section - userEvent.click(expandButton); + await user.click(expandButton); await waitFor(() => expect(collapsedSectionNode).toHaveAttribute('aria-expanded', 'true')); // Click to collapse section - userEvent.click(expandButton); + await user.click(expandButton); await waitFor(() => expect(collapsedSectionNode).toHaveAttribute('aria-expanded', 'false')); }); @@ -275,16 +276,17 @@ describe('Outline Tab', () => { }); it('renders show more/less button and handles click', async () => { + const user = userEvent.setup(); expect(screen.getByTestId('alert-container-welcome')).toBeInTheDocument(); let showMoreButton = screen.getByRole('button', { name: 'Show More' }); expect(showMoreButton).toBeInTheDocument(); - userEvent.click(showMoreButton); + await user.click(showMoreButton); let showLessButton = screen.getByRole('button', { name: 'Show Less' }); expect(showLessButton).toBeInTheDocument(); expect(screen.getByTestId('long-welcome-message-iframe')).toBeInTheDocument(); - userEvent.click(showLessButton); + await user.click(showLessButton); showLessButton = screen.queryByRole('button', { name: 'Show Less' }); expect(showLessButton).not.toBeInTheDocument(); showMoreButton = screen.getByRole('button', { name: 'Show More' }); diff --git a/src/courseware/course/sidebar/sidebars/course-outline/CourseOutlineTray.test.jsx b/src/courseware/course/sidebar/sidebars/course-outline/CourseOutlineTray.test.jsx index 1454d4f525..10f8315f01 100644 --- a/src/courseware/course/sidebar/sidebars/course-outline/CourseOutlineTray.test.jsx +++ b/src/courseware/course/sidebar/sidebars/course-outline/CourseOutlineTray.test.jsx @@ -85,6 +85,7 @@ describe('', () => { }); it('collapses sidebar correctly when toggle button is clicked', async () => { + const user = userEvent.setup(); const mockToggleSidebar = jest.fn(); await initTestStore(); renderWithProvider({ toggleSidebar: mockToggleSidebar }); @@ -94,33 +95,36 @@ describe('', () => { expect(sidebarBackBtn).toBeInTheDocument(); expect(collapseBtn).toBeInTheDocument(); - userEvent.click(collapseBtn); + await user.click(collapseBtn); expect(mockToggleSidebar).toHaveBeenCalledWith(null); }); it('toggles openSequenceId correctly when a sequence is clicked', async () => { + const user = userEvent.setup(); await initTestStore(); renderWithProvider(); const sequenceButton = screen.getByRole('button', { name: `${sequence.title} , ${courseOutlineMessages.incompleteAssignment.defaultMessage}` }); expect(sequenceButton).toBeInTheDocument(); - userEvent.click(sequenceButton); + await user.click(sequenceButton); expect(screen.getByRole('button', { name: `${sequence.title} , ${courseOutlineMessages.incompleteAssignment.defaultMessage}` })).toHaveAttribute('aria-expanded', 'true'); - userEvent.click(sequenceButton); + await user.click(sequenceButton); expect(screen.getByRole('button', { name: `${sequence.title} , ${courseOutlineMessages.incompleteAssignment.defaultMessage}` })).toHaveAttribute('aria-expanded', 'false'); }); it('updates setOpenSequenceId correctly when toggling sequences', async () => { + const user = userEvent.setup(); await initTestStore(); renderWithProvider(); const sequenceButton = screen.getByRole('button', { name: `${sequence.title} , ${courseOutlineMessages.incompleteAssignment.defaultMessage}` }); expect(sequenceButton).toBeInTheDocument(); - userEvent.click(sequenceButton); + await user.click(sequenceButton); expect(sequenceButton).toHaveAttribute('aria-expanded', 'true'); - userEvent.click(sequenceButton); + await user.click(sequenceButton); expect(sequenceButton).toHaveAttribute('aria-expanded', 'false'); }); it('navigates to section or sequence level correctly on click by back/section button', async () => { + const user = userEvent.setup(); await initTestStore(); renderWithProvider(); @@ -128,11 +132,11 @@ describe('', () => { expect(sidebarBackBtn).toBeInTheDocument(); expect(screen.getByRole('button', { name: `${sequence.title} , ${courseOutlineMessages.incompleteAssignment.defaultMessage}` })).toBeInTheDocument(); - userEvent.click(sidebarBackBtn); + await user.click(sidebarBackBtn); expect(sidebarBackBtn).not.toBeInTheDocument(); expect(screen.queryByText(messages.courseOutlineTitle.defaultMessage)).toBeInTheDocument(); - userEvent.click(screen.getByRole('button', { name: `${section.title} , ${courseOutlineMessages.incompleteSection.defaultMessage}` })); + await user.click(screen.getByRole('button', { name: `${section.title} , ${courseOutlineMessages.incompleteSection.defaultMessage}` })); expect(screen.queryByRole('button', { name: section.title })).toBeInTheDocument(); }); }); diff --git a/src/courseware/course/sidebar/sidebars/course-outline/CourseOutlineTrigger.test.jsx b/src/courseware/course/sidebar/sidebars/course-outline/CourseOutlineTrigger.test.jsx index 328da18ab5..cca273db71 100644 --- a/src/courseware/course/sidebar/sidebars/course-outline/CourseOutlineTrigger.test.jsx +++ b/src/courseware/course/sidebar/sidebars/course-outline/CourseOutlineTrigger.test.jsx @@ -43,6 +43,7 @@ describe('', () => { } it('renders correctly for desktop when sidebar is enabled', async () => { + const user = userEvent.setup(); const mockToggleSidebar = jest.fn(); await initTestStore({ enableNavigationSidebar: { enable_navigation_sidebar: true } }); renderWithProvider({ toggleSidebar: mockToggleSidebar }, { isMobileView: false }); @@ -52,13 +53,14 @@ describe('', () => { }); expect(toggleButton).toBeInTheDocument(); - userEvent.click(toggleButton); + await user.click(toggleButton); expect(mockToggleSidebar).toHaveBeenCalled(); expect(mockToggleSidebar).toHaveBeenCalledWith(outlineSidebarId); }); it('renders correctly for mobile when sidebar is enabled', async () => { + const user = userEvent.setup(); const mockToggleSidebar = jest.fn(); await initTestStore({ enableNavigationSidebar: { enable_navigation_sidebar: true } }); renderWithProvider({ @@ -71,13 +73,14 @@ describe('', () => { }); expect(toggleButton).toBeInTheDocument(); - userEvent.click(toggleButton); + await user.click(toggleButton); expect(mockToggleSidebar).toHaveBeenCalled(); expect(mockToggleSidebar).toHaveBeenCalledWith(outlineSidebarId); }); it('changes current sidebar value on click', async () => { + const user = userEvent.setup(); const mockToggleSidebar = jest.fn(); await initTestStore({ enableNavigationSidebar: { enable_navigation_sidebar: true } }); renderWithProvider({ @@ -91,7 +94,7 @@ describe('', () => { }); expect(toggleButton).toBeInTheDocument(); - userEvent.click(toggleButton); + await user.click(toggleButton); expect(mockToggleSidebar).toHaveBeenCalledTimes(1); expect(mockToggleSidebar).toHaveBeenCalledWith(null); diff --git a/src/courseware/course/sidebar/sidebars/course-outline/components/SidebarSection.test.jsx b/src/courseware/course/sidebar/sidebars/course-outline/components/SidebarSection.test.jsx index 4c48a14b7d..cf3aab7e9b 100644 --- a/src/courseware/course/sidebar/sidebars/course-outline/components/SidebarSection.test.jsx +++ b/src/courseware/course/sidebar/sidebars/course-outline/components/SidebarSection.test.jsx @@ -36,6 +36,7 @@ describe('', () => { }); it('renders correctly when section is incomplete', async () => { + const user = userEvent.setup(); await initTestStore(); const { getByText, container } = render(); @@ -44,12 +45,13 @@ describe('', () => { expect(container.querySelector('.text-success')).not.toBeInTheDocument(); const button = getByText(section.title); - userEvent.click(button); + await user.click(button); expect(mockHandleSelectSection).toHaveBeenCalledTimes(1); expect(mockHandleSelectSection).toHaveBeenCalledWith(section.id); }); it('renders correctly when section is complete', async () => { + const user = userEvent.setup(); await initTestStore(); const { getByText, getByTestId } = render( , @@ -60,7 +62,7 @@ describe('', () => { expect(getByTestId('check-circle-icon')).toBeInTheDocument(); const button = getByText(section.title); - userEvent.click(button); + await user.click(button); expect(mockHandleSelectSection).toHaveBeenCalledTimes(1); expect(mockHandleSelectSection).toHaveBeenCalledWith(section.id); }); diff --git a/src/courseware/course/sidebar/sidebars/course-outline/components/SidebarSequence.test.jsx b/src/courseware/course/sidebar/sidebars/course-outline/components/SidebarSequence.test.jsx index 73d9f3f816..8f2b0dcb16 100644 --- a/src/courseware/course/sidebar/sidebars/course-outline/components/SidebarSequence.test.jsx +++ b/src/courseware/course/sidebar/sidebars/course-outline/components/SidebarSequence.test.jsx @@ -54,6 +54,7 @@ describe('', () => { }); it('renders correctly when sequence is not collapsed and complete', async () => { + const user = userEvent.setup(); await initTestStore(); renderWithProvider({ defaultOpen: true, @@ -67,6 +68,6 @@ describe('', () => { expect(screen.getByText(sequence.title)).toBeInTheDocument(); expect(screen.getByText(sequenceDescription)).toBeInTheDocument(); expect(screen.getByText(`, ${courseOutlineMessages.completedAssignment.defaultMessage}`)).toBeInTheDocument(); - userEvent.click(screen.getByText(sequence.title)); + await user.click(screen.getByText(sequence.title)); }); }); diff --git a/src/courseware/course/sidebar/sidebars/course-outline/components/SidebarUnit.test.jsx b/src/courseware/course/sidebar/sidebars/course-outline/components/SidebarUnit.test.jsx index c46ef0eda2..41776a7e88 100644 --- a/src/courseware/course/sidebar/sidebars/course-outline/components/SidebarUnit.test.jsx +++ b/src/courseware/course/sidebar/sidebars/course-outline/components/SidebarUnit.test.jsx @@ -88,6 +88,7 @@ describe('', () => { }); it('sends log event correctly when unit is clicked', async () => { + const user = userEvent.setup(); await initTestStore(); renderWithProvider({ unit: { ...unit } }); const logData = { @@ -99,7 +100,7 @@ describe('', () => { widget_placement: 'left', }; - userEvent.click(screen.getByText(unit.title)); + await user.click(screen.getByText(unit.title)); expect(sendTrackEvent).toHaveBeenCalledWith('edx.ui.lms.sequence.tab_selected', logData); expect(sendTrackingLogEvent).toHaveBeenCalledWith('edx.ui.lms.sequence.tab_selected', logData);