Skip to content

Commit 57e935e

Browse files
committed
refactor: simplify onClick handlers in dropdowns and improve test assertions for editable states
1 parent 65ff3ff commit 57e935e

6 files changed

Lines changed: 24 additions & 10 deletions

File tree

src/schedule-and-details/ScheduleAndDetails.test.jsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe('<ScheduleAndDetails />', () => {
144144
const { getAllByPlaceholderText, getByText } = renderComponent();
145145
let inputs;
146146
await waitFor(() => {
147-
inputs = getAllByPlaceholderText(DATE_FORMAT.toLocaleUpperCase());
147+
inputs = getAllByPlaceholderText(DATE_FORMAT.toUpperCase());
148148
});
149149
// @ts-ignore
150150
fireEvent.change(inputs[0], { target: { value: '06/16/2023' } });
@@ -234,7 +234,7 @@ describe('<ScheduleAndDetails /> permissions', () => {
234234
mockPermissions({ canEditSchedule: false });
235235
const { getAllByPlaceholderText } = renderComponent();
236236
await waitFor(() => {
237-
const dateInputs = getAllByPlaceholderText(DATE_FORMAT.toLocaleUpperCase());
237+
const dateInputs = getAllByPlaceholderText(DATE_FORMAT.toUpperCase());
238238
dateInputs.forEach((input) => expect(input).toBeDisabled());
239239
});
240240
});
@@ -249,12 +249,24 @@ describe('<ScheduleAndDetails /> permissions', () => {
249249
});
250250
});
251251

252+
it('keeps schedule inputs editable while disabling details when only canEditSchedule is granted', async () => {
253+
mockWaffleFlags({ enableAuthzCourseAuthoring: true });
254+
mockPermissions({ canEditDetails: false });
255+
const { getAllByPlaceholderText, getAllByRole } = renderComponent();
256+
await waitFor(() => {
257+
const dateInputs = getAllByPlaceholderText(DATE_FORMAT.toUpperCase());
258+
dateInputs.forEach((input) => expect(input).not.toBeDisabled());
259+
const radios = getAllByRole('radio');
260+
radios.forEach((radio) => expect(radio).toBeDisabled());
261+
});
262+
});
263+
252264
it('save button cannot be triggered when user has no edit permissions', async () => {
253265
mockWaffleFlags({ enableAuthzCourseAuthoring: true });
254266
mockPermissions({ canEditSchedule: false, canEditDetails: false });
255267
const { getAllByPlaceholderText, queryByText } = renderComponent();
256268
// Wait for page to load
257-
const dateInputs = await waitFor(() => getAllByPlaceholderText(DATE_FORMAT.toLocaleUpperCase()));
269+
const dateInputs = await waitFor(() => getAllByPlaceholderText(DATE_FORMAT.toUpperCase()));
258270
// All date inputs must be disabled (no edit_schedule permission)
259271
dateInputs.forEach((input) => expect(input).toBeDisabled());
260272
// No changes can be made so the save button never appears

src/schedule-and-details/details-section/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const DetailsSection = ({
3434
{languageOptions.map((option) => (
3535
<Dropdown.Item
3636
key={option[0]}
37-
onClick={isEditable ? () => onChange(option[0], 'language') : undefined}
37+
onClick={() => onChange(option[0], 'language')}
3838
>
3939
{option[1]}
4040
</Dropdown.Item>

src/schedule-and-details/introducing-section/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ const IntroducingSection = ({
113113
<>
114114
<Form.Group className="form-group-custom">
115115
<Form.Label>{intl.formatMessage(messages.courseOverviewLabel)}</Form.Label>
116+
{/* Generic components (WysiwygEditor, CourseUploadImage) use the standard HTML
117+
`disabled` prop; domain section components use the semantic `isEditable` prop. */}
116118
<WysiwygEditor
117119
initialValue={overview}
118120
onChange={(value) => onChange(value, 'overview')}

src/schedule-and-details/requirements-section/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ const RequirementsSection = ({
4040
<Dropdown.Menu>
4141
<Dropdown.Item
4242
key={intl.formatMessage(messages.dropdownEmptyText)}
43-
onClick={isEditable ? () => onChange([], 'preRequisiteCourses') : undefined}
43+
onClick={() => onChange([], 'preRequisiteCourses')}
4444
>
4545
{intl.formatMessage(messages.dropdownEmptyText)}
4646
</Dropdown.Item>
4747
{possiblePreRequisiteCourses.map((course) => (
4848
<Dropdown.Item
4949
key={course.courseKey}
50-
onClick={isEditable ? () => onChange([course.courseKey], 'preRequisiteCourses') : undefined}
50+
onClick={() => onChange([course.courseKey], 'preRequisiteCourses')}
5151
>
5252
{course.displayName}
5353
</Dropdown.Item>

src/schedule-and-details/schedule-section/ScheduleSection.test.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ describe('<ScheduleSection />', () => {
7474

7575
it('sets all date inputs to disabled when isEditable is false', () => {
7676
const { container } = render(<RootWrapper {...props} isEditable={false} />);
77-
// DatepickerControl uses disabled={readonly}, so inputs get the disabled attribute
78-
const inputs = container.querySelectorAll('input[disabled]');
79-
expect(inputs.length).toBeGreaterThan(0);
77+
// DatepickerControl renders disabled={readonly}; verify the specific fields gated by isEditable
78+
['startDate', 'endDate', 'enrollmentStart'].forEach((controlName) => {
79+
expect(container.querySelector(`#${controlName}-date`)).toBeDisabled();
80+
});
8081
});
8182

8283
it('date inputs are not readonly when isEditable is true', () => {

src/schedule-and-details/schedule-section/index.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ const ScheduleSection = ({
6767
availableDateErrorFeedback: errorFields?.certificateAvailableDate,
6868
certificatesDisplayBehavior,
6969
displayBehaviorErrorFeedback: errorFields?.certificatesDisplayBehavior,
70-
isEditable,
7170
},
7271
{
7372
labels: [

0 commit comments

Comments
 (0)