11import React from 'react' ;
2+ import { when } from 'jest-when' ;
23import { formatMessage , shallow } from '@edx/react-unit-test-utils/dist' ;
34
45import { useModel } from '../../../../generic/model-store' ;
@@ -9,7 +10,7 @@ import ContentIFrame from './ContentIFrame';
910import Unit from '.' ;
1011import messages from '../messages' ;
1112import { getIFrameUrl } from './urls' ;
12- import { views } from './constants' ;
13+ import { modelKeys , views } from './constants' ;
1314import * as hooks from './hooks' ;
1415
1516jest . mock ( './hooks' , ( ) => ( { useUnitData : jest . fn ( ) } ) ) ;
@@ -75,7 +76,14 @@ const unit = {
7576 bookmarked : false ,
7677 bookmarkedUpdateState : 'pending' ,
7778} ;
78- useModel . mockReturnValue ( unit ) ;
79+ const mockCoursewareMetaFn = jest . fn ( ( ) => ( { wholeCourseTranslationEnabled : false } ) ) ;
80+ const mockUnitsFn = jest . fn ( ( ) => unit ) ;
81+
82+ when ( useModel )
83+ . calledWith ( 'coursewareMeta' , props . courseId )
84+ . mockImplementation ( mockCoursewareMetaFn )
85+ . calledWith ( modelKeys . units , props . id )
86+ . mockImplementation ( mockUnitsFn ) ;
7987
8088let el ;
8189describe ( 'Unit component' , ( ) => {
@@ -118,7 +126,7 @@ describe('Unit component', () => {
118126 } ) ;
119127 describe ( 'bookmarked, bookmark update pending' , ( ) => {
120128 beforeEach ( ( ) => {
121- useModel . mockReturnValueOnce ( { ...unit , bookmarked : true } ) ;
129+ mockUnitsFn . mockReturnValueOnce ( { ...unit , bookmarked : true } ) ;
122130 renderComponent ( ) ;
123131 } ) ;
124132 test ( 'snapshot' , ( ) => {
@@ -192,5 +200,18 @@ describe('Unit component', () => {
192200 } ) ;
193201 } ) ;
194202 } ) ;
203+ describe ( 'TranslationSelection' , ( ) => {
204+ test ( 'renders if wholeCourseTranslationEnabled' , ( ) => {
205+ mockCoursewareMetaFn . mockReturnValueOnce ( { wholeCourseTranslationEnabled : true } ) ;
206+ el = shallow ( < Unit { ...props } /> ) ;
207+ expect ( el . snapshot ) . toMatchSnapshot ( ) ;
208+ expect ( el . instance . findByType ( 'TranslationSelection' ) ) . toHaveLength ( 1 ) ;
209+ } ) ;
210+ test ( 'does not render if wholeCourseTranslationEnabled is false' , ( ) => {
211+ mockCoursewareMetaFn . mockReturnValueOnce ( { wholeCourseTranslationEnabled : false } ) ;
212+ el = shallow ( < Unit { ...props } /> ) ;
213+ expect ( el . instance . findByType ( 'TranslationSelection' ) ) . toHaveLength ( 0 ) ;
214+ } ) ;
215+ } ) ;
195216 } ) ;
196217} ) ;
0 commit comments