1
- import React from 'react' ;
2
- import { shallow } from '@edx/react-unit-test-utils ' ;
3
-
1
+ import { render , screen } from '@testing-library/ react' ;
2
+ import { formatMessage } from 'testUtils ' ;
3
+ import { IntlProvider } from '@edx/frontend-platform/i18n' ;
4
4
import hooks from './hooks' ;
5
5
import SelectSessionModal from '.' ;
6
+ import messages from './messages' ;
6
7
7
8
jest . mock ( './hooks' , ( ) => ( {
8
9
__esModule : true ,
9
10
default : jest . fn ( ) ,
10
11
} ) ) ;
11
12
13
+ jest . unmock ( '@edx/frontend-platform/i18n' ) ;
14
+ jest . unmock ( '@openedx/paragon' ) ;
15
+ jest . unmock ( 'react' ) ;
16
+
12
17
const hookReturn = {
13
18
availableSessions : [ ] ,
14
19
showModal : true ,
@@ -25,29 +30,41 @@ const availableSessions = [
25
30
] ;
26
31
27
32
describe ( 'SelectSessionModal' , ( ) => {
28
- describe ( 'snapshot ' , ( ) => {
29
- test ( 'empty modal with leave option ' , ( ) => {
33
+ describe ( 'renders ' , ( ) => {
34
+ it ( 'empty modal with leave option ' , ( ) => {
30
35
hooks . mockReturnValueOnce ( {
31
36
...hookReturn ,
32
37
} ) ;
33
- expect ( shallow ( < SelectSessionModal /> ) . snapshot ) . toMatchSnapshot ( ) ;
38
+ render ( < IntlProvider locale = "en" > < SelectSessionModal /> </ IntlProvider > ) ;
39
+ const sessionOption = screen . queryByDisplayValue ( availableSessions [ 0 ] . courseId ) ;
40
+ expect ( sessionOption ) . toBeNull ( ) ;
41
+ const leaveOption = screen . getByRole ( 'radio' , { name : formatMessage ( messages . leaveSessionOption ) } ) ;
42
+ expect ( leaveOption ) . toBeInTheDocument ( ) ;
34
43
} ) ;
35
44
36
- test ( 'modal with leave option ' , ( ) => {
45
+ it ( 'modal with leave option ' , ( ) => {
37
46
hooks . mockReturnValueOnce ( {
38
47
...hookReturn ,
39
- availableSessions : [ ... availableSessions ] ,
48
+ availableSessions,
40
49
} ) ;
41
- expect ( shallow ( < SelectSessionModal /> ) . snapshot ) . toMatchSnapshot ( ) ;
50
+ render ( < IntlProvider locale = "en" > < SelectSessionModal /> </ IntlProvider > ) ;
51
+ const sessionOption = screen . getByDisplayValue ( availableSessions [ 0 ] . courseId ) ;
52
+ expect ( sessionOption ) . toBeInTheDocument ( ) ;
53
+ const leaveOption = screen . getByRole ( 'radio' , { name : formatMessage ( messages . leaveSessionOption ) } ) ;
54
+ expect ( leaveOption ) . toBeInTheDocument ( ) ;
42
55
} ) ;
43
56
44
- test ( 'modal without leave option ' , ( ) => {
57
+ it ( 'modal without leave option ' , ( ) => {
45
58
hooks . mockReturnValueOnce ( {
46
59
...hookReturn ,
47
60
availableSessions,
48
61
showLeaveOption : false ,
49
62
} ) ;
50
- expect ( shallow ( < SelectSessionModal /> ) . snapshot ) . toMatchSnapshot ( ) ;
63
+ render ( < IntlProvider locale = "en" > < SelectSessionModal /> </ IntlProvider > ) ;
64
+ const sessionOption = screen . getByDisplayValue ( availableSessions [ 0 ] . courseId ) ;
65
+ expect ( sessionOption ) . toBeInTheDocument ( ) ;
66
+ const leaveOption = screen . queryByRole ( 'radio' , { name : formatMessage ( messages . leaveSessionOption ) } ) ;
67
+ expect ( leaveOption ) . toBeNull ( ) ;
51
68
} ) ;
52
69
} ) ;
53
70
} ) ;
0 commit comments