Skip to content

Commit

Permalink
feat: add Restriction Type in EditCoursePage
Browse files Browse the repository at this point in the history
  • Loading branch information
zawan-ila committed Apr 29, 2024
1 parent 01c2184 commit 2a50205
Show file tree
Hide file tree
Showing 8 changed files with 1,549 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/components/EditCoursePage/CollapsibleCourseRun.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import FieldLabel from '../FieldLabel';
import {
courseRunIsArchived, localTimeZone, formatDate, isSafari, getDateWithDashes,
getDateWithSlashes, isNonExemptChanged, isPristine, hasMastersTrack, jsonDeepEqual, utcTimeZone, isExternalCourse,
restrictionTypeOptions,
} from '../../utils';
import Pill from '../Pill';
import RenderInputTextField from '../RenderInputTextField';
Expand All @@ -33,7 +34,7 @@ import {
PUBLISHED, DATE_INPUT_PATTERN, FORMAT_DATE_MATCHER, NORMALIZE_DATE_MATCHER, REVIEWED,
} from '../../data/constants';
import {
dateEditHelp, runTypeHelp, pacingEditHelp, publishDateHelp, courseRunVariantIdHelp,
dateEditHelp, runTypeHelp, pacingEditHelp, publishDateHelp, courseRunVariantIdHelp, courseRunRestrictionTypeHelp,
} from '../../helpText';
import RichEditor from '../RichEditor';
import ListField from '../ListField';
Expand Down Expand Up @@ -301,6 +302,16 @@ class CollapsibleCourseRun extends React.Component {
optional
/>
)}
{isExternalCourse(productSource, courseType) && (
<Field
name={`${courseId}.restriction_type`}
component={RenderSelectField}
options={restrictionTypeOptions}
label={<FieldLabel text="Restriction Type" helpText={courseRunRestrictionTypeHelp} />}
disabled={disabled}
props={{ name: `${courseId}.restriction_type` }}
/>
)}
{/* TODO this should be refactored when paragon supports safari */}
{/* text inputs for safari */}
{isSafari
Expand Down
30 changes: 30 additions & 0 deletions src/components/EditCoursePage/CollapsibleCourseRun.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,36 @@ describe('Collapsible Course Run', () => {
expect(variantIdField.exists()).toBe(true);
expect(shallowToJson(component)).toMatchSnapshot();
});
it.each(['custom-b2c', ''])('renders correctly restriction type field for external course\'s course run', (restrictionType) => {
const courseInfo = {
data: {
product_source: {
slug: 'test-source',
name: 'Test Source',
description: 'Test Source Description',
},
course_type: EXECUTIVE_EDUCATION_SLUG,
},
};
const courseRun = { ...unpublishedCourseRun, restriction_type: restrictionType };
const component = shallow(
<CollapsibleCourseRun
languageOptions={languageOptions}
pacingTypeOptions={pacingTypeOptions}
courseRun={courseRun}
courseId="test-course"
courseUuid="11111111-1111-1111-1111-111111111111"
type="8a8f30e1-23ce-4ed3-a361-1325c656b67b"
currentFormValues={currentFormValues}
courseRunTypeOptions={courseRunTypeOptions}
index={1}
courseInfo={courseInfo}
/>,
);
const restrictionTypeField = component.find('Field[name="test-course.restriction_type"]');
expect(restrictionTypeField.exists()).toBe(true);
expect(shallowToJson(component)).toMatchSnapshot();
});

it('renders correctly with external key field enabled', () => {
const runTypeModes = {
Expand Down
46 changes: 44 additions & 2 deletions src/components/EditCoursePage/EditCoursePage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { shallowToJson } from 'enzyme-to-json';
import configureStore from 'redux-mock-store';
import { Alert } from '@edx/paragon';
import { IntlProvider } from '@edx/frontend-platform/i18n';

import { createStore } from 'redux';
import EditCoursePage from './index';

import ConfirmationModal from '../ConfirmationModal';
Expand All @@ -15,6 +15,7 @@ import {
PUBLISHED, REVIEW_BY_INTERNAL, REVIEW_BY_LEGAL, UNPUBLISHED, EXECUTIVE_EDUCATION_SLUG,
} from '../../data/constants';
import { courseOptions, courseRunOptions } from '../../data/constants/testData';
import createRootReducer from '../../data/reducers';
import { jsonDeepCopy } from '../../utils';

// Need to mock the Editor as we don't want to test TinyMCE
Expand All @@ -27,6 +28,7 @@ describe('EditCoursePage', () => {
const defaultEnd = '2019-08-14T00:00:00Z';
const defaultUpgradeDeadlineOverride = '2019-09-14T00:00:00Z';
const variantId = '00000000-0000-0000-0000-000000000000';
const restrictionType = 'custom-b2b-enterprise';
const watchers = ['[email protected]'];

const courseInfo = {
Expand Down Expand Up @@ -64,6 +66,7 @@ describe('EditCoursePage', () => {
end: defaultEnd,
upgrade_deadline_override: '2019-05-10T00:00:00Z',
variant_id: null,
restriction_type: restrictionType,
expected_program_type: 'micromasters',
expected_program_name: 'Test Program Name',
go_live_date: '2019-05-06T00:00:00Z',
Expand All @@ -89,6 +92,7 @@ describe('EditCoursePage', () => {
end: defaultEnd,
upgrade_deadline_override: '2019-05-10T00:00:00Z',
variant_id: null,
restriction_type: null,
expected_program_type: null,
expected_program_name: '',
go_live_date: '2019-05-06T00:00:00Z',
Expand Down Expand Up @@ -213,6 +217,42 @@ describe('EditCoursePage', () => {
expect(shallowToJson(component)).toMatchSnapshot();
});

it('renders course run restriction_type correctly for executive education course', () => {
const store = createStore(createRootReducer());
const courseInfoExecEd = {
...courseInfo,
data: {
...courseInfo.data,
product_source: {
slug: 'test-source',
name: 'Test Source',
description: 'Test Source Description',
},
course_type: EXECUTIVE_EDUCATION_SLUG,
},
};
const EditCoursePageWrapper = (props) => (
<MemoryRouter>
<Provider store={store}>
<IntlProvider locale="en">
<EditCoursePage
{...props}
courseInfo={courseInfoExecEd}
courseOptions={courseOptions}
courseRunOptions={courseRunOptions}
/>
</IntlProvider>
</Provider>
</MemoryRouter>
);

const wrapper = mount(EditCoursePageWrapper());
const firstSelect = wrapper.find('select[name="course_runs[0].restriction_type"]');
expect(firstSelect.props().value).toBe('custom-b2b-enterprise');
const secondSelect = wrapper.find('select[name="course_runs[1].restriction_type"]');
expect(secondSelect.props().value).toBe('');
});

it('renders page correctly with courseInfo error', () => {
const component = shallow(<EditCoursePage
courseInfo={{
Expand Down Expand Up @@ -326,6 +366,7 @@ describe('EditCoursePage', () => {
end: defaultEnd,
upgrade_deadline_override: defaultUpgradeDeadlineOverride,
variant_id: variantId,
restriction_type: restrictionType,
expected_program_type: null,
expected_program_name: '',
go_live_date: '2019-05-06T00:00:00Z',
Expand Down Expand Up @@ -474,6 +515,7 @@ describe('EditCoursePage', () => {
weeks_to_complete: '100',
upgrade_deadline_override: defaultUpgradeDeadlineOverride,
variant_id: variantId,
restriction_type: restrictionType,
},
{
content_language: 'en-us',
Expand All @@ -496,6 +538,7 @@ describe('EditCoursePage', () => {
weeks_to_complete: '100',
upgrade_deadline_override: defaultUpgradeDeadlineOverride,
variant_id: variantId,
restriction_type: restrictionType,
},
];

Expand Down Expand Up @@ -933,7 +976,6 @@ describe('EditCoursePage', () => {
.toEqual({});
}, 0);
});

const expectedSendCourseExEdCourses = {
additional_information: '<p>Stuff</p>',
additional_metadata: {
Expand Down
Loading

0 comments on commit 2a50205

Please sign in to comment.