1- import { render , waitFor , act } from '@testing-library/react' ;
2- import { configureStore } from '@reduxjs/toolkit' ;
3- import { MemoryRouter } from 'react-router-dom' ;
4- import { AppProvider } from '@edx/frontend-platform/react' ;
5- import { IntlProvider } from '@edx/frontend-platform/i18n' ;
6- import { initializeMockApp } from '@edx/frontend-platform' ;
1+ import { PartialEditorState , thunkActions } from '@src/editors/data/redux' ;
2+ import { initializeMocks , waitFor , act } from '@src/testUtils' ;
3+ import { editorRender , getEditorStore } from '@src/editors/editorTestRender' ;
74import VideoEditorModal from './VideoEditorModal' ;
8- import { thunkActions } from '../../../data/redux' ;
95
10- jest . mock ( '../../../data/redux' , ( ) => ( {
11- ...jest . requireActual ( '../../../data/redux' ) ,
12- thunkActions : {
13- video : {
14- loadVideoData : jest
15- . fn ( )
16- . mockImplementation ( ( ) => ( { type : 'MOCK_ACTION' } ) ) ,
6+ thunkActions . video . loadVideoData = jest . fn ( ) . mockImplementation ( ( ) => ( { type : 'MOCK_ACTION' } ) ) ;
7+
8+ const initialState : PartialEditorState = {
9+ app : {
10+ videos : { } ,
11+ learningContextId : 'course-v1:test+test+test' ,
12+ blockId : 'some-block-id' ,
13+ courseDetails : { } ,
14+ } ,
15+ requests : {
16+ uploadAsset : { status : 'inactive' , response : { } as any } ,
17+ uploadTranscript : { status : 'inactive' , response : { } as any } ,
18+ deleteTranscript : { status : 'inactive' , response : { } as any } ,
19+ fetchVideos : { status : 'inactive' , response : { } as any } ,
20+ } ,
21+ video : {
22+ videoSource : '' ,
23+ videoId : '' ,
24+ fallbackVideos : [ '' , '' ] ,
25+ allowVideoDownloads : false ,
26+ allowVideoSharing : { level : 'block' , value : false } ,
27+ thumbnail : undefined ,
28+ transcripts : [ ] ,
29+ selectedVideoTranscriptUrls : { } ,
30+ allowTranscriptDownloads : false ,
31+ duration : {
32+ startTime : '00:00:00' ,
33+ stopTime : '00:00:00' ,
34+ total : '00:00:00' ,
1735 } ,
1836 } ,
19- } ) ) ;
37+ } ;
2038
2139describe ( 'VideoUploader' , ( ) => {
22- let store ;
23-
2440 beforeEach ( async ( ) => {
25- store = configureStore ( {
26- reducer : ( state , action ) => ( action && action . newState ? action . newState : state ) ,
27- preloadedState : {
28- app : {
29- videos : [ ] ,
30- learningContextId : 'course-v1:test+test+test' ,
31- blockId : 'some-block-id' ,
32- courseDetails : { } ,
33- } ,
34- requests : {
35- uploadAsset : { status : 'inactive' } ,
36- uploadTranscript : { status : 'inactive' } ,
37- deleteTranscript : { status : 'inactive' } ,
38- fetchVideos : { status : 'inactive' } ,
39- } ,
40- video : {
41- videoSource : '' ,
42- videoId : '' ,
43- fallbackVideos : [ '' , '' ] ,
44- allowVideoDownloads : false ,
45- allowVideoSharing : { level : 'block' , value : false } ,
46- thumbnail : null ,
47- transcripts : [ ] ,
48- transcriptHandlerUrl : '' ,
49- selectedVideoTranscriptUrls : { } ,
50- allowTranscriptDownloads : false ,
51- duration : {
52- startTime : '00:00:00' ,
53- stopTime : '00:00:00' ,
54- total : '00:00:00' ,
55- } ,
56- } ,
57- } ,
58- } ) ;
59- initializeMockApp ( {
60- authenticatedUser : {
61- userId : 3 ,
62- username : 'test-user' ,
63- administrator : true ,
64- roles : [ ] ,
65- } ,
66- } ) ;
41+ initializeMocks ( ) ;
6742 } ) ;
6843
69- const renderComponent = async ( ) =>
70- render (
71- < AppProvider store = { store } wrapWithRouter = { false } >
72- < IntlProvider locale = "en" >
73- < MemoryRouter
74- initialEntries = { [
75- '/some/path?selectedVideoId=id_1&selectedVideoUrl=https://video.com' ,
76- ] }
77- >
78- < VideoEditorModal isLibrary = { false } />
79- </ MemoryRouter >
80- </ IntlProvider >
81- </ AppProvider > ,
82- ) ;
44+ const renderComponent = ( ) => (
45+ editorRender (
46+ < VideoEditorModal isLibrary = { false } /> ,
47+ {
48+ routerProps : {
49+ initialEntries : [ '/some/path?selectedVideoId=id_1&selectedVideoUrl=https://video.com' ] ,
50+ } ,
51+ initialState,
52+ } ,
53+ )
54+ ) ;
8355
8456 it ( 'should render the component and call loadVideoData with correct parameters' , async ( ) => {
85- await renderComponent ( ) ;
57+ renderComponent ( ) ;
8658 await waitFor ( ( ) => {
8759 expect ( thunkActions . video . loadVideoData ) . toHaveBeenCalledWith (
8860 'id_1' ,
@@ -92,10 +64,11 @@ describe('VideoUploader', () => {
9264 } ) ;
9365
9466 it ( 'should call loadVideoData again when isLoaded state changes' , async ( ) => {
95- await renderComponent ( ) ;
67+ renderComponent ( ) ;
9668 await waitFor ( ( ) => {
97- expect ( thunkActions . video . loadVideoData ) . toHaveBeenCalledTimes ( 2 ) ;
69+ expect ( thunkActions . video . loadVideoData ) . toHaveBeenCalledTimes ( 1 ) ;
9870 } ) ;
71+ const store = getEditorStore ( ) ;
9972
10073 act ( ( ) => {
10174 store . dispatch ( {
@@ -111,7 +84,7 @@ describe('VideoUploader', () => {
11184 } ) ;
11285
11386 await waitFor ( ( ) => {
114- expect ( thunkActions . video . loadVideoData ) . toHaveBeenCalledTimes ( 3 ) ;
87+ expect ( thunkActions . video . loadVideoData ) . toHaveBeenCalledTimes ( 2 ) ;
11588 } ) ;
11689 } ) ;
11790} ) ;
0 commit comments