Skip to content

Commit f4b90d8

Browse files
fix: handle boolean flag from MFE Config API in CourseImportHomePage
The ENABLE_COURSE_IMPORT_IN_LIBRARY flag check used strict string comparison (=== 'true'), which fails when the value comes from the MFE Config API at runtime (JSON boolean true instead of string 'true'). Use the same [true, 'true'].includes() pattern already in other library components for this case. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8d5842b commit f4b90d8

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/library-authoring/import-course/CourseImportHomePage.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { setConfig, getConfig } from '@edx/frontend-platform';
12
import {
23
initializeMocks,
34
render as testRender,
@@ -53,4 +54,23 @@ describe('<CourseImportHomePage>', () => {
5354
expect(screen.queryByRole('heading', { name: 'Previous Imports' })).not.toBeInTheDocument();
5455
expect(screen.getByText('You have not imported any courses into this library.')).toBeInTheDocument();
5556
});
57+
58+
it('should show the import course button when flag is the string "true"', async () => {
59+
setConfig({ ...getConfig(), ENABLE_COURSE_IMPORT_IN_LIBRARY: 'true' });
60+
render(mockGetCourseImports.emptyLibraryId);
61+
expect(await screen.findByRole('button', { name: /import course/i })).toBeInTheDocument();
62+
});
63+
64+
it('should show the import course button when flag is the boolean true (MFE Config API)', async () => {
65+
setConfig({ ...getConfig(), ENABLE_COURSE_IMPORT_IN_LIBRARY: true });
66+
render(mockGetCourseImports.emptyLibraryId);
67+
expect(await screen.findByRole('button', { name: /import course/i })).toBeInTheDocument();
68+
});
69+
70+
it('should not show the import course button when flag is disabled', async () => {
71+
setConfig({ ...getConfig(), ENABLE_COURSE_IMPORT_IN_LIBRARY: 'false' });
72+
render(mockGetCourseImports.emptyLibraryId);
73+
await screen.findByText('You have not imported any courses into this library.');
74+
expect(screen.queryByRole('button', { name: /import course/i })).not.toBeInTheDocument();
75+
});
5676
});

src/library-authoring/import-course/CourseImportHomePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import messages from './messages';
2323
const ImportCourseButton = () => {
2424
const navigate = useNavigate();
2525

26-
if (getConfig().ENABLE_COURSE_IMPORT_IN_LIBRARY === 'true') {
26+
if ([true, 'true'].includes(getConfig().ENABLE_COURSE_IMPORT_IN_LIBRARY)) {
2727
return (
2828
<Button iconBefore={Add} onClick={() => navigate('courses')}>
2929
<FormattedMessage {...messages.importCourseButton} />

0 commit comments

Comments
 (0)