Skip to content

Commit

Permalink
chore: update watcher field disabled condition & editable for course …
Browse files Browse the repository at this point in the history
…authors (#905)
  • Loading branch information
AfaqShuaib09 authored Aug 22, 2023
1 parent 22172f5 commit ca17123
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 25 deletions.
51 changes: 26 additions & 25 deletions src/components/EditCoursePage/EditCourseForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Collapsible from '../Collapsible';
import PriceList from '../PriceList';

import {
PUBLISHED, REVIEWED, EXECUTIVE_EDUCATION_SLUG, REVIEW_BY_INTERNAL,
PUBLISHED, REVIEWED, EXECUTIVE_EDUCATION_SLUG, UNPUBLISHED, IN_REVIEW_STATUS,
} from '../../data/constants';
import {
titleHelp, typeHelp, getUrlSlugHelp, productSourceHelp,
Expand Down Expand Up @@ -372,30 +372,31 @@ export class BaseEditCourseForm extends React.Component {
disabled={disabled || !administrator}
optional
/>
{administrator && (
<Field
name="watchers_list"
component={ReduxFormCreatableSelect}
label={(
<FieldLabel
id="watchers.label"
text="Watchers"
helpText={(
<p>
A list of email addresses that will receive
notifications when the course run of the course is published or reviewed.
</p>
)}
optional
/>
)}
isMulti
disabled={!(courseInfo?.data?.course_run_statuses?.includes(REVIEW_BY_INTERNAL) && administrator)}
optional
isCreatable
createOptionValidator={emailValidate}
/>
)}
<Field
name="watchers_list"
component={ReduxFormCreatableSelect}
label={(
<FieldLabel
id="watchers.label"
text="Watchers"
helpText={(
<p>
A list of email addresses that will receive
notifications when the course run of the course is published or reviewed.
</p>
)}
optional
/>
)}
isMulti
disabled={
!(courseInfo?.data?.course_run_statuses?.some(status => IN_REVIEW_STATUS.includes(status)
|| status === UNPUBLISHED))
}
optional
isCreatable
createOptionValidator={emailValidate}
/>
<div>
<FieldLabel helpText={productSourceHelp} id="productSource" text="Product Source" className="mb-2" />
<div className="mb-3">{parsedProductSource}</div>
Expand Down
56 changes: 56 additions & 0 deletions src/components/EditCoursePage/EditCourseForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,62 @@ describe('BaseEditCourseForm', () => {
expect(disabledFields).toHaveLength(1);
});

it('Check if watchers field is disabled after being reviewed', () => {
const courseInfoWithCourseRunStatuses = {
...courseInfo,
data: {
...courseInfo.data,
course_run_statuses: [REVIEWED],
},
};
const component = shallow(<BaseEditCourseForm
handleSubmit={() => null}
title={initialValuesFull.title}
initialValues={initialValuesFull}
currentFormValues={initialValuesFull}
number="Test101x"
entitlement={{ sku: 'ABC1234' }}
courseStatuses={[REVIEWED]}
courseInfo={courseInfoWithCourseRunStatuses}
courseOptions={courseOptions}
courseRunOptions={courseRunOptions}
uuid={initialValuesFull.uuid}
type={initialValuesFull.type}
id="edit-course-form"
/>);

const watchersField = component.find({ name: 'watchers_list', disabled: true });
expect(watchersField).toHaveLength(1);
});

it('Check if watchers field is enabled when any of the course run is in pre-reviewed status', () => {
const courseInfoWithCourseRunStatuses = {
...courseInfo,
data: {
...courseInfo.data,
course_run_statuses: [REVIEW_BY_LEGAL, UNPUBLISHED],
},
};
const component = shallow(<BaseEditCourseForm
handleSubmit={() => null}
title={initialValuesFull.title}
initialValues={initialValuesFull}
currentFormValues={initialValuesFull}
number="Test101x"
entitlement={{ sku: 'ABC1234' }}
courseStatuses={[REVIEW_BY_LEGAL, UNPUBLISHED]}
courseInfo={courseInfoWithCourseRunStatuses}
courseOptions={courseOptions}
courseRunOptions={courseRunOptions}
uuid={initialValuesFull.uuid}
type={initialValuesFull.type}
id="edit-course-form"
/>);

const watchersField = component.find({ name: 'watchers_list', disabled: false });
expect(watchersField).toHaveLength(1);
});

it('renders with course type disabled once a sku exists, even if course is unpublished', () => {
const component = shallow(<BaseEditCourseForm
handleSubmit={() => null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,29 @@ exports[`BaseEditCourseForm override slug format when IS_NEW_SLUG_FORMAT_ENABLED
pattern="^[a-z0-9_]+(?:-[a-z0-9_]+)*$"
type="text"
/>
<Field
component={[Function]}
createOptionValidator={[Function]}
disabled={true}
isCreatable={true}
isMulti={true}
label={
<FieldLabel
className=""
extraText=""
helpText={
<p>
A list of email addresses that will receive notifications when the course run of the course is published or reviewed.
</p>
}
id="watchers.label"
optional={true}
text="Watchers"
/>
}
name="watchers_list"
optional={true}
/>
<div>
<FieldLabel
className="mb-2"
Expand Down Expand Up @@ -1994,6 +2017,29 @@ exports[`BaseEditCourseForm renders correctly when submitting for review 1`] = `
pattern="^[a-z0-9_]+(?:-[a-z0-9_]+)*$"
type="text"
/>
<Field
component={[Function]}
createOptionValidator={[Function]}
disabled={true}
isCreatable={true}
isMulti={true}
label={
<FieldLabel
className=""
extraText=""
helpText={
<p>
A list of email addresses that will receive notifications when the course run of the course is published or reviewed.
</p>
}
id="watchers.label"
optional={true}
text="Watchers"
/>
}
name="watchers_list"
optional={true}
/>
<div>
<FieldLabel
className="mb-2"
Expand Down Expand Up @@ -3818,6 +3864,29 @@ exports[`BaseEditCourseForm renders html correctly while submitting 1`] = `
pattern="^[a-z0-9_]+(?:-[a-z0-9_]+)*$"
type="text"
/>
<Field
component={[Function]}
createOptionValidator={[Function]}
disabled={true}
isCreatable={true}
isMulti={true}
label={
<FieldLabel
className=""
extraText=""
helpText={
<p>
A list of email addresses that will receive notifications when the course run of the course is published or reviewed.
</p>
}
id="watchers.label"
optional={true}
text="Watchers"
/>
}
name="watchers_list"
optional={true}
/>
<div>
<FieldLabel
className="mb-2"
Expand Down Expand Up @@ -7877,6 +7946,29 @@ exports[`BaseEditCourseForm renders html correctly with all data present 1`] = `
pattern="^[a-z0-9_]+(?:-[a-z0-9_]+)*$"
type="text"
/>
<Field
component={[Function]}
createOptionValidator={[Function]}
disabled={true}
isCreatable={true}
isMulti={true}
label={
<FieldLabel
className=""
extraText=""
helpText={
<p>
A list of email addresses that will receive notifications when the course run of the course is published or reviewed.
</p>
}
id="watchers.label"
optional={true}
text="Watchers"
/>
}
name="watchers_list"
optional={true}
/>
<div>
<FieldLabel
className="mb-2"
Expand Down Expand Up @@ -9742,6 +9834,29 @@ exports[`BaseEditCourseForm renders html correctly with minimal data 1`] = `
pattern="^[a-z0-9_]+(?:-[a-z0-9_]+)*$"
type="text"
/>
<Field
component={[Function]}
createOptionValidator={[Function]}
disabled={true}
isCreatable={true}
isMulti={true}
label={
<FieldLabel
className=""
extraText=""
helpText={
<p>
A list of email addresses that will receive notifications when the course run of the course is published or reviewed.
</p>
}
id="watchers.label"
optional={true}
text="Watchers"
/>
}
name="watchers_list"
optional={true}
/>
<div>
<FieldLabel
className="mb-2"
Expand Down Expand Up @@ -11108,6 +11223,29 @@ exports[`BaseEditCourseForm renders html correctly with skills data when skills
pattern="^[a-z0-9_]+(?:-[a-z0-9_]+)*$"
type="text"
/>
<Field
component={[Function]}
createOptionValidator={[Function]}
disabled={true}
isCreatable={true}
isMulti={true}
label={
<FieldLabel
className=""
extraText=""
helpText={
<p>
A list of email addresses that will receive notifications when the course run of the course is published or reviewed.
</p>
}
id="watchers.label"
optional={true}
text="Watchers"
/>
}
name="watchers_list"
optional={true}
/>
<div>
<FieldLabel
className="mb-2"
Expand Down

0 comments on commit ca17123

Please sign in to comment.