From 3f53e96268bd7e5090c48238f0fae642c0eb3802 Mon Sep 17 00:00:00 2001 From: Jillian Vogel Date: Wed, 5 Jun 2024 10:06:50 +0930 Subject: [PATCH] test: fix tests failing after upgrade better than we did in the previous commit. --- src/files-and-videos/files-page/FilesPage.test.jsx | 14 +++++++++----- .../videos-page/VideosPage.test.jsx | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/files-and-videos/files-page/FilesPage.test.jsx b/src/files-and-videos/files-page/FilesPage.test.jsx index 5e9e320e92..2a316ff293 100644 --- a/src/files-and-videos/files-page/FilesPage.test.jsx +++ b/src/files-and-videos/files-page/FilesPage.test.jsx @@ -43,9 +43,6 @@ import messages from '../generic/messages'; import filesPageMessages from './messages'; import { updateFileValues } from './data/utils'; -// eslint-disable-next-line no-promise-executor-return -const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); - let axiosMock; let store; let file; @@ -74,8 +71,15 @@ const mockStore = async ( } renderComponent(); await executeThunk(fetchAssets(courseId), store.dispatch); - // Wait a couple seconds to finish loading files into the data table - await sleep(2); + + // Finish loading the expected files into the data table before returning, + // because loading new files can disrupt things like accessing file menus. + if (status === RequestStatus.SUCCESSFUL) { + const numFiles = skipNextPageFetch ? 13 : 15; + await waitFor(() => { + expect(screen.getByText(`Showing ${numFiles} of ${numFiles}`)).toBeInTheDocument(); + }); + } }; const emptyMockStore = async (status) => { diff --git a/src/files-and-videos/videos-page/VideosPage.test.jsx b/src/files-and-videos/videos-page/VideosPage.test.jsx index d1fa6b2767..f000c317db 100644 --- a/src/files-and-videos/videos-page/VideosPage.test.jsx +++ b/src/files-and-videos/videos-page/VideosPage.test.jsx @@ -40,9 +40,6 @@ import * as api from './data/api'; import videoMessages from './messages'; import messages from '../generic/messages'; -// eslint-disable-next-line no-promise-executor-return -const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); - const { getVideosUrl, getCourseVideosApiUrl, getApiBaseUrl } = api; let axiosMock; @@ -73,8 +70,15 @@ const mockStore = async ( renderComponent(); await executeThunk(fetchVideos(courseId), store.dispatch); - // Wait a couple seconds to finish loading video files into the data table - await sleep(2); + + // Finish loading the expected files into the data table before returning, + // because loading new files can disrupt things like accessing file menus. + if (status === RequestStatus.SUCCESSFUL) { + const numFiles = 3; + await waitFor(() => { + expect(screen.getByText(`Showing ${numFiles} of ${numFiles}`)).toBeInTheDocument(); + }); + } }; const emptyMockStore = async (status) => {