fix: show/hide add unit button based on childAddable flag of parent in unit page (#2351)

Course unit page shows Add Unit option without checking whether the parent subsection allows adding children. This fixes it.
This commit is contained in:
Navin Karkera
2025-08-07 01:11:05 +05:30
committed by GitHub
parent 0e1550a45b
commit 92c3a98a3d
2 changed files with 27 additions and 1 deletions

View File

@@ -792,6 +792,28 @@ describe('<CourseUnit />', () => {
.toHaveBeenCalledWith(`/course/${courseId}/container/${blockId}/${updatedAncestorsChild.id}`, { replace: true });
});
it('Show or hide new unit button based on parent sequence childAddable action', async () => {
render(<RootWrapper />);
// The new unit button should be visible when childAddable is true
await screen.findByRole('button', { name: courseSequenceMessages.newUnitBtnText.defaultMessage });
const updatedCourseSectionVerticalData = cloneDeep(courseSectionVerticalMock);
// Set childAddable to false for sequence i.e. current units parent.
set(updatedCourseSectionVerticalData, 'xblock_info.ancestor_info.ancestors[0].actions.childAddable', false);
axiosMock
.onGet(getCourseSectionVerticalApiUrl(blockId))
.reply(200, {
...updatedCourseSectionVerticalData,
});
render(<RootWrapper />);
// to wait for loading
screen.findByTestId('unit-header-title');
// The new unit button should not be visible when childAddable is false
expect(
screen.queryByRole('button', { name: courseSequenceMessages.newUnitBtnText.defaultMessage }),
).not.toBeInTheDocument();
});
it('the sequence unit is updated after changing the unit header', async () => {
const user = userEvent.setup();
render(<RootWrapper />);