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' ;
44import hooks from './hooks' ;
55import SelectSessionModal from '.' ;
6+ import messages from './messages' ;
67
78jest . mock ( './hooks' , ( ) => ( {
89 __esModule : true ,
910 default : jest . fn ( ) ,
1011} ) ) ;
1112
13+ jest . unmock ( '@edx/frontend-platform/i18n' ) ;
14+ jest . unmock ( '@openedx/paragon' ) ;
15+ jest . unmock ( 'react' ) ;
16+
1217const hookReturn = {
1318 availableSessions : [ ] ,
1419 showModal : true ,
@@ -25,29 +30,41 @@ const availableSessions = [
2530] ;
2631
2732describe ( 'SelectSessionModal' , ( ) => {
28- describe ( 'snapshot ' , ( ) => {
29- test ( 'empty modal with leave option ' , ( ) => {
33+ describe ( 'renders ' , ( ) => {
34+ it ( 'empty modal with leave option ' , ( ) => {
3035 hooks . mockReturnValueOnce ( {
3136 ...hookReturn ,
3237 } ) ;
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 ( ) ;
3443 } ) ;
3544
36- test ( 'modal with leave option ' , ( ) => {
45+ it ( 'modal with leave option ' , ( ) => {
3746 hooks . mockReturnValueOnce ( {
3847 ...hookReturn ,
39- availableSessions : [ ... availableSessions ] ,
48+ availableSessions,
4049 } ) ;
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 ( ) ;
4255 } ) ;
4356
44- test ( 'modal without leave option ' , ( ) => {
57+ it ( 'modal without leave option ' , ( ) => {
4558 hooks . mockReturnValueOnce ( {
4659 ...hookReturn ,
4760 availableSessions,
4861 showLeaveOption : false ,
4962 } ) ;
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 ( ) ;
5168 } ) ;
5269 } ) ;
5370} ) ;
0 commit comments