@@ -7,6 +7,7 @@ import PageLoading from '@src/generic/PageLoading';
77
88import messages from '../messages' ;
99import HonorCode from '../honor-code' ;
10+ import LockPaywall from '../lock-paywall' ;
1011import hooks from './hooks' ;
1112import { modelKeys } from './constants' ;
1213
@@ -23,6 +24,7 @@ jest.mock('react', () => ({
2324} ) ) ;
2425
2526jest . mock ( '../honor-code' , ( ) => 'HonorCode' ) ;
27+ jest . mock ( '../lock-paywall' , ( ) => 'LockPaywall' ) ;
2628jest . mock ( '@src/generic/model-store' , ( ) => ( { useModel : jest . fn ( ) } ) ) ;
2729jest . mock ( '@src/generic/PageLoading' , ( ) => 'PageLoading' ) ;
2830
@@ -60,6 +62,31 @@ describe('UnitSuspense component', () => {
6062 } ) ;
6163 } ) ;
6264 describe ( 'output' , ( ) => {
65+ describe ( 'LockPaywall' , ( ) => {
66+ const testNoPaywall = ( ) => {
67+ it ( 'does not display LockPaywall' , ( ) => {
68+ el = shallow ( < UnitSuspense { ...props } /> ) ;
69+ expect ( el . instance . findByType ( LockPaywall ) . length ) . toEqual ( 0 ) ;
70+ } ) ;
71+ } ;
72+ describe ( 'gating not enabled' , ( ) => { testNoPaywall ( ) ; } ) ;
73+ describe ( 'gating enabled, but no gated content included' , ( ) => {
74+ beforeEach ( ( ) => { mockModels ( true , false ) ; } ) ;
75+ testNoPaywall ( ) ;
76+ } ) ;
77+ describe ( 'gating enabled, gated content included' , ( ) => {
78+ beforeEach ( ( ) => { mockModels ( true , true ) ; } ) ;
79+ it ( 'displays LockPaywall in Suspense wrapper with PageLoading fallback' , ( ) => {
80+ el = shallow ( < UnitSuspense { ...props } /> ) ;
81+ const [ component ] = el . instance . findByType ( LockPaywall ) ;
82+ expect ( component . parent . type ) . toEqual ( 'PluginSlot' ) ;
83+ expect ( component . parent . parent . type ) . toEqual ( 'Suspense' ) ;
84+ expect ( component . parent . parent . props . fallback )
85+ . toEqual ( < PageLoading srMessage = { formatMessage ( messages . loadingLockedContent ) } /> ) ;
86+ expect ( component . props . courseId ) . toEqual ( props . courseId ) ;
87+ } ) ;
88+ } ) ;
89+ } ) ;
6390 describe ( 'HonorCode' , ( ) => {
6491 it ( 'does not display HonorCode if useShouldDisplayHonorCode => false' , ( ) => {
6592 hooks . useShouldDisplayHonorCode . mockReturnValueOnce ( false ) ;
0 commit comments