Skip to content

Commit 48309c7

Browse files
committed
feat: adding more code needed by lockpaywall
1 parent 71d23af commit 48309c7

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/courseware/course/sequence/Unit/UnitSuspense.test.jsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import PageLoading from '@src/generic/PageLoading';
77

88
import messages from '../messages';
99
import HonorCode from '../honor-code';
10+
import LockPaywall from '../lock-paywall';
1011
import hooks from './hooks';
1112
import { modelKeys } from './constants';
1213

@@ -23,6 +24,7 @@ jest.mock('react', () => ({
2324
}));
2425

2526
jest.mock('../honor-code', () => 'HonorCode');
27+
jest.mock('../lock-paywall', () => 'LockPaywall');
2628
jest.mock('@src/generic/model-store', () => ({ useModel: jest.fn() }));
2729
jest.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);

src/courseware/course/sequence/Unit/index.test.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jest.mock('../../bookmark/BookmarkButton', () => 'BookmarkButton');
2828
jest.mock('./ContentIFrame', () => 'ContentIFrame');
2929
jest.mock('./UnitSuspense', () => 'UnitSuspense');
3030
jest.mock('../honor-code', () => 'HonorCode');
31+
jest.mock('../lock-paywall', () => 'LockPaywall');
3132

3233
jest.mock('@src/generic/model-store', () => ({
3334
useModel: jest.fn(),

0 commit comments

Comments
 (0)