|
8 | 8 | waitFor, |
9 | 9 | } from '@src/testUtils'; |
10 | 10 | import { CourseAuthoringProvider } from '@src/CourseAuthoringContext'; |
| 11 | +import { mockWaffleFlags } from '@src/data/apiHooks.mock'; |
| 12 | +import { useCourseUserPermissions } from '@src/authz/hooks'; |
11 | 13 | import { courseId } from '@src/schedule-and-details/__mocks__/courseDetails'; |
12 | 14 | import { userEvent } from '@testing-library/user-event'; |
13 | 15 | import { renderCard, setupCardTestMocks } from '../__mocks__/testSetup'; |
@@ -39,6 +41,14 @@ jest.mock('@src/course-outline/data/apiHooks', () => ({ |
39 | 41 | useUpdateCourseBlockName: () => useUpdateCourseBlockNameMock, |
40 | 42 | })); |
41 | 43 |
|
| 44 | +jest.mock('@src/authz/hooks', () => ({ |
| 45 | + useCourseUserPermissions: jest.fn().mockReturnValue({ |
| 46 | + isLoading: false, |
| 47 | + canEditCourseContent: true, |
| 48 | + canPublishCourseContent: true, |
| 49 | + }), |
| 50 | +})); |
| 51 | + |
42 | 52 | const cardHeaderProps = { |
43 | 53 | title: 'Some title', |
44 | 54 | status: ITEM_BADGE_STATUS.live, |
@@ -66,6 +76,11 @@ const cardHeaderProps = { |
66 | 76 | }, |
67 | 77 | }; |
68 | 78 |
|
| 79 | +const mockPermissions = (mockedPermissions) => { |
| 80 | + mockWaffleFlags({ enableAuthzCourseAuthoring: !!mockedPermissions }); |
| 81 | + jest.mocked(useCourseUserPermissions).mockReturnValue(mockedPermissions); |
| 82 | +}; |
| 83 | + |
69 | 84 | const renderComponent = (props?: object, entry = '/') => { |
70 | 85 | const titleComponent = ( |
71 | 86 | <TitleButton |
@@ -579,4 +594,30 @@ describe('<CardHeader />', () => { |
579 | 594 | await act(async () => fireEvent.click(unlinkMenuItem)); |
580 | 595 | expect(onClickUnlinkMock).toHaveBeenCalled(); |
581 | 596 | }); |
| 597 | + |
| 598 | + describe('canEditCourseContent permission', () => { |
| 599 | + it('renders the rename button and actions menu when canEditCourseContent is true', async () => { |
| 600 | + renderComponent({ canEditCourseContent: true }); |
| 601 | + |
| 602 | + expect(await screen.findByTestId('subsection-edit-button')).toBeInTheDocument(); |
| 603 | + expect(await screen.findByTestId('subsection-card-header__menu')).toBeInTheDocument(); |
| 604 | + }); |
| 605 | + |
| 606 | + it('does not render the rename button when canEditCourseContent is false', async () => { |
| 607 | + mockPermissions({ canEditCourseContent: false }); |
| 608 | + renderComponent(); |
| 609 | + |
| 610 | + expect(await screen.findByText(cardHeaderProps.title)).toBeInTheDocument(); |
| 611 | + expect(screen.queryByTestId('subsection-edit-button')).not.toBeInTheDocument(); |
| 612 | + }); |
| 613 | + |
| 614 | + it('does not render the actions menu when canEditCourseContent is false', async () => { |
| 615 | + mockPermissions({ canEditCourseContent: false }); |
| 616 | + renderComponent(); |
| 617 | + |
| 618 | + expect(await screen.findByText(cardHeaderProps.title)).toBeInTheDocument(); |
| 619 | + expect(screen.queryByTestId('subsection-card-header__menu')).not.toBeInTheDocument(); |
| 620 | + expect(screen.queryByTestId('subsection-card-header__menu-button')).not.toBeInTheDocument(); |
| 621 | + }); |
| 622 | + }); |
582 | 623 | }); |
0 commit comments