Skip to content

Commit b953499

Browse files
committed
chore: add whole_course_translation and language to courseware meta
1 parent 60ae8b3 commit b953499

File tree

11 files changed

+98
-16
lines changed

11 files changed

+98
-16
lines changed

package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"classnames": "2.3.2",
4949
"core-js": "3.22.2",
5050
"history": "5.3.0",
51-
"jest": "^26.6.3",
5251
"joi": "^17.11.0",
5352
"js-cookie": "3.0.5",
5453
"lodash.camelcase": "4.3.0",
@@ -80,7 +79,9 @@
8079
"copy-webpack-plugin": "^11.0.0",
8180
"es-check": "6.2.1",
8281
"husky": "7.0.4",
82+
"jest": "^26.6.3",
8383
"jest-console-group-reporter": "^1.0.1",
84+
"jest-when": "^3.6.0",
8485
"rosie": "2.1.1"
8586
}
8687
}

src/courseware/course/Course.test.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ describe('Course', () => {
6363
expect(await screen.findByText('Loading learning sequence...')).toBeInTheDocument();
6464

6565
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
66-
// one from translation product tour
67-
expect(screen.getAllByRole('dialog')).toHaveLength(1);
66+
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
6867
expect(screen.queryByRole('button', { name: 'Learn About Verified Certificates' })).not.toBeInTheDocument();
6968

7069
loadUnit();

src/courseware/course/sequence/Sequence.test.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ describe('Sequence', () => {
137137
render(<Sequence {...mockData} />, { wrapWithRouter: true });
138138
expect(await screen.findByText('Loading learning sequence...')).toBeInTheDocument();
139139
// `Previous`, `Bookmark` and `Close Tray` buttons
140-
// `Change Language`, `Dismiss` and `Try it` buttons from translation selection.
141-
expect(screen.getAllByRole('button')).toHaveLength(6);
140+
expect(screen.getAllByRole('button')).toHaveLength(3);
142141
// Renders `Next` button plus one button for each unit.
143142
expect(screen.getAllByRole('link')).toHaveLength(1 + unitBlocks.length);
144143

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exports[`Unit component output BookmarkButton props not bookmarked, bookmark upd
1616
/>
1717
`;
1818

19-
exports[`Unit component output snapshot: not bookmarked, do not show content 1`] = `
19+
exports[`Unit component output TranslationSelection renders if wholeCourseTranslationEnabled 1`] = `
2020
<div
2121
className="unit"
2222
>
@@ -58,3 +58,41 @@ exports[`Unit component output snapshot: not bookmarked, do not show content 1`]
5858
/>
5959
</div>
6060
`;
61+
62+
exports[`Unit component output snapshot: not bookmarked, do not show content 1`] = `
63+
<div
64+
className="unit"
65+
>
66+
<div
67+
className="mb-0"
68+
>
69+
<h3
70+
className="h3"
71+
>
72+
unit-title
73+
</h3>
74+
</div>
75+
<h2
76+
className="sr-only"
77+
>
78+
Level 2 headings may be created by course providers in the future.
79+
</h2>
80+
<BookmarkButton
81+
isBookmarked={false}
82+
isProcessing={false}
83+
unitId="unit-id"
84+
/>
85+
<UnitSuspense
86+
courseId="test-course-id"
87+
id="test-props-id"
88+
/>
89+
<ContentIFrame
90+
elementId="unit-iframe"
91+
id="test-props-id"
92+
loadingMessage="Loading learning sequence..."
93+
onLoaded={[MockFunction props.onLoaded]}
94+
shouldShowContent={true}
95+
title="unit-title"
96+
/>
97+
</div>
98+
`;

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const Unit = ({
2424
const examAccess = useExamAccess({ id });
2525
const shouldDisplayHonorCode = useShouldDisplayHonorCode({ courseId, id });
2626
const unit = useModel(modelKeys.units, id);
27+
const { wholeCourseTranslationEnabled } = useModel('coursewareMeta', courseId);
2728
const isProcessing = unit.bookmarkedUpdateState === 'loading';
2829
const view = authenticatedUser ? views.student : views.public;
2930
const { selectedLanguage, setSelectedLanguage } = useSelectLanguage(courseId);
@@ -40,11 +41,13 @@ const Unit = ({
4041
<div className="unit">
4142
<div className="mb-0">
4243
<h3 className="h3">{unit.title}</h3>
43-
<TranslationSelection
44-
courseId={courseId}
45-
selectedLanguage={selectedLanguage}
46-
setSelectedLanguage={setSelectedLanguage}
47-
/>
44+
{wholeCourseTranslationEnabled && (
45+
<TranslationSelection
46+
courseId={courseId}
47+
selectedLanguage={selectedLanguage}
48+
setSelectedLanguage={setSelectedLanguage}
49+
/>
50+
)}
4851
</div>
4952
<h2 className="sr-only">{formatMessage(messages.headerPlaceholder)}</h2>
5053
<BookmarkButton

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { when } from 'jest-when';
23
import { formatMessage, shallow } from '@edx/react-unit-test-utils/dist';
34

45
import { useModel } from '../../../../generic/model-store';
@@ -9,7 +10,7 @@ import ContentIFrame from './ContentIFrame';
910
import Unit from '.';
1011
import messages from '../messages';
1112
import { getIFrameUrl } from './urls';
12-
import { views } from './constants';
13+
import { modelKeys, views } from './constants';
1314
import * as hooks from './hooks';
1415

1516
jest.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

8088
let el;
8189
describe('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
});

src/courseware/data/__factories__/courseMetadata.factory.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Factory.define('courseMetadata')
3939
enabled: false,
4040
},
4141
marketing_url: null,
42+
language: 'en',
43+
whole_course_translation_enabled: false,
4244
celebrations: null,
4345
enroll_alert: null,
4446
course_exit_page_is_active: true,

src/courseware/data/api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ function normalizeMetadata(metadata) {
110110
showCalculator: data.show_calculator,
111111
notes: camelCaseObject(data.notes),
112112
marketingUrl: data.marketing_url,
113+
language: data.language,
114+
wholeCourseTranslationEnabled: data.whole_course_translation_enabled,
113115
celebrations: camelCaseObject(data.celebrations),
114116
userHasPassingGrade: data.user_has_passing_grade,
115117
courseExitPageIsActive: data.course_exit_page_is_active,

src/courseware/data/pact-tests/lmsPact.test.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ describe('Courseware Service', () => {
335335
linkedin_add_to_profile_url: null,
336336
user_needs_integrity_signature: boolean(false),
337337
learning_assistant_enabled: boolean(false),
338+
language: string('en'),
339+
whole_course_translation_enabled: boolean(false),
338340
},
339341
},
340342
});

0 commit comments

Comments
 (0)