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' ;
7
- import { QueryClient , QueryClientProvider } from '@tanstack/react-query' ;
1
+ import { thunkActions } from '@src/editors/data/redux' ;
8
2
import VideoEditorModal from './VideoEditorModal' ;
9
- import { thunkActions } from '../../../data/redux' ;
3
+ import { initializeMocks , waitFor , act } from '@src/testUtils' ;
4
+ import editorRender , { getEditorStore , PartialEditorState } from '@src/editors/editorTestRender' ;
10
5
11
- jest . mock ( '../../../data/redux' , ( ) => ( {
12
- ...jest . requireActual ( '../../../data/redux' ) ,
13
- thunkActions : {
14
- video : {
15
- loadVideoData : jest
16
- . fn ( )
17
- . mockImplementation ( ( ) => ( { type : 'MOCK_ACTION' } ) ) ,
18
- } ,
19
- } ,
20
- } ) ) ;
6
+ thunkActions . video . loadVideoData = jest . fn ( ) . mockImplementation ( ( ) => ( { type : 'MOCK_ACTION' } ) ) ;
21
7
22
- const queryClient = new QueryClient ( {
23
- defaultOptions : {
24
- queries : {
25
- retry : false ,
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 : null ,
28
+ transcripts : [ ] ,
29
+ selectedVideoTranscriptUrls : { } ,
30
+ allowTranscriptDownloads : false ,
31
+ duration : {
32
+ startTime : '00:00:00' ,
33
+ stopTime : '00:00:00' ,
34
+ total : '00:00:00' ,
26
35
} ,
27
36
} ,
28
- } ) ;
37
+ } ;
29
38
30
39
describe ( 'VideoUploader' , ( ) => {
31
- let store ;
32
-
33
40
beforeEach ( async ( ) => {
34
- store = configureStore ( {
35
- reducer : ( state , action ) => ( action && action . newState ? action . newState : state ) ,
36
- preloadedState : {
37
- app : {
38
- videos : [ ] ,
39
- learningContextId : 'course-v1:test+test+test' ,
40
- blockId : 'some-block-id' ,
41
- courseDetails : { } ,
42
- } ,
43
- requests : {
44
- uploadAsset : { status : 'inactive' } ,
45
- uploadTranscript : { status : 'inactive' } ,
46
- deleteTranscript : { status : 'inactive' } ,
47
- fetchVideos : { status : 'inactive' } ,
48
- } ,
49
- video : {
50
- videoSource : '' ,
51
- videoId : '' ,
52
- fallbackVideos : [ '' , '' ] ,
53
- allowVideoDownloads : false ,
54
- allowVideoSharing : { level : 'block' , value : false } ,
55
- thumbnail : null ,
56
- transcripts : [ ] ,
57
- transcriptHandlerUrl : '' ,
58
- selectedVideoTranscriptUrls : { } ,
59
- allowTranscriptDownloads : false ,
60
- duration : {
61
- startTime : '00:00:00' ,
62
- stopTime : '00:00:00' ,
63
- total : '00:00:00' ,
64
- } ,
65
- } ,
66
- } ,
67
- } ) ;
68
- initializeMockApp ( {
69
- authenticatedUser : {
70
- userId : 3 ,
71
- username : 'test-user' ,
72
- administrator : true ,
73
- roles : [ ] ,
74
- } ,
75
- } ) ;
41
+ initializeMocks ( ) ;
76
42
} ) ;
77
43
78
- const renderComponent = async ( ) => render (
79
- < AppProvider store = { store } wrapWithRouter = { false } >
80
- < IntlProvider locale = "en" >
81
- < QueryClientProvider client = { queryClient } >
82
- < MemoryRouter
83
- initialEntries = { [
84
- '/some/path?selectedVideoId=id_1&selectedVideoUrl=https://video.com' ,
85
- ] }
86
- >
87
- < VideoEditorModal isLibrary = { false } />
88
- </ MemoryRouter >
89
- </ QueryClientProvider >
90
- </ IntlProvider >
91
- </ AppProvider > ,
44
+ const renderComponent = ( ) => editorRender (
45
+ < VideoEditorModal isLibrary = { false } /> ,
46
+ {
47
+ path : '/some/path' ,
48
+ routerProps : {
49
+ initialEntries : [ '/some/path?selectedVideoId=id_1&selectedVideoUrl=https://video.com' ] ,
50
+ } ,
51
+ initialState,
52
+ }
92
53
) ;
93
54
94
55
it ( 'should render the component and call loadVideoData with correct parameters' , async ( ) => {
95
- await renderComponent ( ) ;
56
+ renderComponent ( ) ;
96
57
await waitFor ( ( ) => {
97
58
expect ( thunkActions . video . loadVideoData ) . toHaveBeenCalledWith (
98
59
'id_1' ,
@@ -102,10 +63,11 @@ describe('VideoUploader', () => {
102
63
} ) ;
103
64
104
65
it ( 'should call loadVideoData again when isLoaded state changes' , async ( ) => {
105
- await renderComponent ( ) ;
66
+ renderComponent ( ) ;
106
67
await waitFor ( ( ) => {
107
- expect ( thunkActions . video . loadVideoData ) . toHaveBeenCalledTimes ( 2 ) ;
68
+ expect ( thunkActions . video . loadVideoData ) . toHaveBeenCalledTimes ( 1 ) ;
108
69
} ) ;
70
+ const store = getEditorStore ( ) ;
109
71
110
72
act ( ( ) => {
111
73
store . dispatch ( {
@@ -121,7 +83,7 @@ describe('VideoUploader', () => {
121
83
} ) ;
122
84
123
85
await waitFor ( ( ) => {
124
- expect ( thunkActions . video . loadVideoData ) . toHaveBeenCalledTimes ( 3 ) ;
86
+ expect ( thunkActions . video . loadVideoData ) . toHaveBeenCalledTimes ( 2 ) ;
125
87
} ) ;
126
88
} ) ;
127
89
} ) ;
0 commit comments