1
- import 'CourseAuthoring/editors/setupEditorTest' ;
2
1
import React from 'react' ;
3
- import { shallow } from '@edx/react-unit-test-utils' ;
4
-
5
- import { formatMessage } from '../../../../../../testUtils' ;
6
- import { actions , selectors } from '../../../../../../data/redux' ;
2
+ import { render , screen , initializeMocks } from '@src/testUtils' ;
3
+ import { formatMessage } from '@src/editors/testUtils' ;
4
+ import { actions , selectors } from '@src/editors/data/redux' ;
7
5
import { HandoutWidgetInternal as HandoutWidget , mapStateToProps , mapDispatchToProps } from '.' ;
8
6
9
- jest . mock ( 'react' , ( ) => ( {
10
- ...jest . requireActual ( 'react' ) ,
11
- useContext : jest . fn ( ( ) => ( { handout : [ 'error.handout' , jest . fn ( ) . mockName ( 'error.setHandout' ) ] } ) ) ,
12
- } ) ) ;
13
-
14
- jest . mock ( '../../../../../../data/redux' , ( ) => ( {
7
+ jest . mock ( '@src/editors/data/redux' , ( ) => ( {
15
8
actions : {
16
9
video : {
17
10
updateField : jest . fn ( ) . mockName ( 'actions.video.updateField' ) ,
@@ -33,48 +26,57 @@ jest.mock('../../../../../../data/redux', () => ({
33
26
34
27
describe ( 'HandoutWidget' , ( ) => {
35
28
const props = {
36
- subtitle : 'SuBTItle' ,
37
- title : 'tiTLE' ,
38
29
intl : { formatMessage } ,
39
30
isLibrary : false ,
40
31
handout : '' ,
32
+ isUploadError : false ,
41
33
getHandoutDownloadUrl : jest . fn ( ) . mockName ( 'args.getHandoutDownloadUrl' ) ,
42
34
updateField : jest . fn ( ) . mockName ( 'args.updateField' ) ,
43
35
} ;
44
36
45
- describe ( 'snapshots' , ( ) => {
46
- test ( 'snapshots: renders as expected with default props' , ( ) => {
47
- expect (
48
- shallow ( < HandoutWidget { ...props } /> ) . snapshot ,
49
- ) . toMatchSnapshot ( ) ;
37
+ describe ( 'renders' , ( ) => {
38
+ beforeEach ( ( ) => {
39
+ initializeMocks ( ) ;
50
40
} ) ;
51
- test ( 'snapshots: renders as expected with isLibrary true' , ( ) => {
52
- expect (
53
- shallow ( < HandoutWidget { ...props } isLibrary /> ) . snapshot ,
54
- ) . toMatchSnapshot ( ) ;
41
+ test ( 'renders as expected with default props' , ( ) => {
42
+ render ( < HandoutWidget { ...props } /> ) ;
43
+ expect ( screen . getByText ( 'Handout' ) ) . toBeInTheDocument ( ) ;
44
+ expect ( screen . getByRole ( 'button' , { name : 'Upload Handout' } ) ) . toBeInTheDocument ( ) ;
45
+ expect ( screen . getByRole ( 'button' , { name : 'Handout' } ) ) . toBeInTheDocument ( ) ;
46
+ expect ( screen . getByRole ( 'button' , { name : 'Collapse' } ) ) . toBeInTheDocument ( ) ;
55
47
} ) ;
56
- test ( 'snapshots: renders as expected with handout' , ( ) => {
57
- expect (
58
- shallow ( < HandoutWidget { ...props } handout = "sOMeUrl " /> ) . snapshot ,
59
- ) . toMatchSnapshot ( ) ;
48
+ test ( 'renders as expected with isLibrary true' , ( ) => {
49
+ const { container } = render ( < HandoutWidget { ...props } isLibrary /> ) ;
50
+ const reduxWrapper = container . firstChild ;
51
+ expect ( reduxWrapper ?. textContent ) . toBe ( '' ) ;
52
+ expect ( screen . queryByText ( 'Handout' ) ) . not . toBeInTheDocument ( ) ;
53
+ } ) ;
54
+ test ( 'renders as expected with handout' , ( ) => {
55
+ const handoutUrl = 'sOMeUrl ' ;
56
+ render ( < HandoutWidget { ...props } handout = { handoutUrl } /> ) ;
57
+ expect ( screen . getByText ( 'Handout' ) ) . toBeInTheDocument ( ) ;
58
+ expect ( screen . getByText ( handoutUrl . trim ( ) ) ) . toBeInTheDocument ( ) ;
60
59
} ) ;
61
60
} ) ;
62
61
describe ( 'mapStateToProps' , ( ) => {
63
62
const testState = { A : 'pple' , B : 'anana' , C : 'ucumber' } ;
64
63
test ( 'isLibrary from app.isLibrary' , ( ) => {
65
64
expect (
66
65
mapStateToProps ( testState ) . isLibrary ,
66
+ // @ts -ignore
67
67
) . toEqual ( selectors . app . isLibrary ( testState ) ) ;
68
68
} ) ;
69
69
test ( 'getHandoutDownloadUrl from video.getHandoutDownloadUrl' , ( ) => {
70
70
expect (
71
71
mapStateToProps ( testState ) . getHandoutDownloadUrl ,
72
+ // @ts -ignore
72
73
) . toEqual ( selectors . video . getHandoutDownloadUrl ( testState ) ) ;
73
74
} ) ;
74
75
} ) ;
75
76
describe ( 'mapDispatchToProps' , ( ) => {
76
77
const dispatch = jest . fn ( ) ;
77
78
test ( 'updateField from actions.video.updateField' , ( ) => {
79
+ // @ts -ignore
78
80
expect ( mapDispatchToProps . updateField ) . toEqual ( dispatch ( actions . video . updateField ) ) ;
79
81
} ) ;
80
82
} ) ;
0 commit comments