1+
2+ import userEvent from '@testing-library/user-event' ;
3+ import ReactDOM from 'react-dom' ;
4+ import { saveAs } from 'file-saver' ;
5+
6+ import { camelCaseObject } from '@edx/frontend-platform' ;
7+
18import {
29 render ,
310 fireEvent ,
411 screen ,
512 waitFor ,
613 within ,
7- } from '@testing-library/react' ;
8- import userEvent from '@testing-library/user-event' ;
9- import ReactDOM from 'react-dom' ;
10- import { saveAs } from 'file-saver' ;
11-
12- import { camelCaseObject , initializeMockApp } from '@edx/frontend-platform' ;
13- import MockAdapter from 'axios-mock-adapter' ;
14- import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth' ;
15- import { AppProvider } from '@edx/frontend-platform/react' ;
16- import { IntlProvider } from '@edx/frontend-platform/i18n' ;
17- import { MemoryRouter , Route , Routes } from 'react-router-dom' ;
18-
19- import initializeStore from '../../store' ;
20- import { executeThunk } from '../../utils' ;
21- import { RequestStatus } from '../../data/constants' ;
14+ initializeMocks ,
15+ } from '@src/testUtils' ;
16+ import { CourseAuthoringProvider } from '@src/CourseAuthoringContext' ;
17+ import { executeThunk } from '@src/utils' ;
18+ import { RequestStatus } from '@src/data/constants' ;
2219import FilesPage from './FilesPage' ;
2320import {
2421 generateFetchAssetApiResponse ,
@@ -51,20 +48,16 @@ jest.mock('file-saver');
5148
5249const renderComponent = ( ) => {
5350 render (
54- < IntlProvider locale = "en" >
55- < AppProvider store = { store } wrapWithRouter = { false } >
56- < MemoryRouter initialEntries = { [ `/course/${ courseId } /videos` ] } >
57- < Routes >
58- < Route
59- path = "/course/:courseId/*"
60- element = {
61- < FilesPage courseId = { courseId } />
62- }
63- />
64- </ Routes >
65- </ MemoryRouter >
66- </ AppProvider >
67- </ IntlProvider > ,
51+ < CourseAuthoringProvider courseId = { courseId } >
52+ < FilesPage /> ,
53+ </ CourseAuthoringProvider > ,
54+ {
55+ path : '/course/:courseId/*' ,
56+ routerProps : {
57+ initialEntries : [ `/course/${ courseId } /videos` ] ,
58+ } ,
59+ params : { courseId } ,
60+ } ,
6861 ) ;
6962} ;
7063
@@ -91,24 +84,19 @@ const emptyMockStore = async (status) => {
9184
9285describe ( 'FilesAndUploads' , ( ) => {
9386 describe ( 'empty state' , ( ) => {
94- beforeEach ( async ( ) => {
95- initializeMockApp ( {
96- authenticatedUser : {
97- userId : 3 ,
98- username : 'abc123' ,
99- administrator : false ,
100- roles : [ ] ,
101- } ,
102- } ) ;
103- store = initializeStore ( {
104- ...initialState ,
105- assets : {
106- ...initialState . assets ,
107- assetIds : [ ] ,
87+ beforeEach ( ( ) => {
88+ const mocks = initializeMocks ( {
89+ initialState : {
90+ ...initialState ,
91+ assets : {
92+ ...initialState . assets ,
93+ assetIds : [ ] ,
94+ } ,
95+ models : { } ,
10896 } ,
109- models : { } ,
11097 } ) ;
111- axiosMock = new MockAdapter ( getAuthenticatedHttpClient ( ) ) ;
98+ store = mocks . reduxStore ;
99+ axiosMock = mocks . axiosMock ;
112100 file = new File ( [ '(⌐□_□)' ] , 'download.png' , { type : 'image/png' } ) ;
113101 } ) ;
114102
@@ -152,17 +140,19 @@ describe('FilesAndUploads', () => {
152140 } ) ;
153141
154142 describe ( 'valid assets' , ( ) => {
155- beforeEach ( async ( ) => {
156- initializeMockApp ( {
157- authenticatedUser : {
158- userId : 3 ,
159- username : 'abc123' ,
160- administrator : false ,
161- roles : [ ] ,
143+ beforeEach ( ( ) => {
144+ const mocks = initializeMocks ( {
145+ initialState : {
146+ ...initialState ,
147+ assets : {
148+ ...initialState . assets ,
149+ assetIds : [ ] ,
150+ } ,
151+ models : { } ,
162152 } ,
163153 } ) ;
164- store = initializeStore ( initialState ) ;
165- axiosMock = new MockAdapter ( getAuthenticatedHttpClient ( ) ) ;
154+ store = mocks . reduxStore ;
155+ axiosMock = mocks . axiosMock ;
166156 file = new File ( [ '(⌐□_□)' ] , 'download.png' , { type : 'image/png' } ) ;
167157 global . localStorage . clear ( ) ;
168158 } ) ;
0 commit comments