Skip to content

Commit

Permalink
tests: fix tests failing after upgrade
Browse files Browse the repository at this point in the history
better than we did in the previous commit.
  • Loading branch information
pomegranited committed Jun 5, 2024
1 parent 65a6807 commit fb86d8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/files-and-videos/files-page/FilesPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down
14 changes: 9 additions & 5 deletions src/files-and-videos/videos-page/VideosPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit fb86d8a

Please sign in to comment.