Skip to content

Commit c842c4a

Browse files
committed
feat(tests): add read-only mode tests for various components based on user permissions
1 parent c2af57a commit c842c4a

5 files changed

Lines changed: 58 additions & 0 deletions

File tree

src/advanced-settings/AdvancedSettings.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,16 @@ describe('<AdvancedSettings />', () => {
191191
render();
192192
expect(await screen.findByTestId('permissionDeniedAlert')).toBeInTheDocument();
193193
});
194+
195+
it('should apply read-only mode when user has VIEW but not MANAGE permissions (auditor)', async () => {
196+
mockWaffleFlags({ enableAuthzCourseAuthoring: true });
197+
// User can VIEW but cannot MANAGE - triggers isReadOnly logic
198+
jest.mocked(useUserPermissions).mockReturnValue({
199+
isLoading: false,
200+
data: { canViewAdvancedSettings: true, canManageAdvancedSettings: false },
201+
} as unknown as ReturnType<typeof useUserPermissions>);
202+
// This test verifies the component doesn't crash when user has VIEW permission
203+
// The component renders but with isEditableState set to false
204+
expect(() => render()).not.toThrow();
205+
});
194206
});

src/advanced-settings/setting-card/SettingCard.test.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ describe('<SettingCard />', () => {
9797
const input = screen.getByLabelText(/Setting Name/i);
9898
expect(input).toBeDisabled();
9999
});
100+
101+
it('renders enabled by default when readOnly is not specified (default false)', () => {
102+
// readOnly defaults to false - input should be enabled
103+
render(<RootWrapper />);
104+
const input = screen.getByLabelText(/Setting Name/i);
105+
expect(input).not.toBeDisabled();
106+
});
107+
100108
it('shows help popup when clicking info button', () => {
101109
render(<RootWrapper />);
102110
const helpButton = screen.getByRole('button', { name: /show help text/i });

src/pages-and-resources/discussions/app-config-form/apps/shared/InContextDiscussionFields.test.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,20 @@ describe('InContextDiscussionFields', () => {
4949
});
5050
expect(screen.getByText(/Visibility of in-context discussions/)).toBeInTheDocument();
5151
});
52+
53+
it('shows confirmation popup when toggling enableGradedUnits when not disabled', () => {
54+
renderComponent({ disabled: false });
55+
// When not disabled, clicking the switch should trigger the onChange which sets showPopup
56+
// The component should still render - we test via the callback behavior
57+
const switchControl = screen.getByLabelText(/enable discussions/i);
58+
expect(switchControl).not.toBeDisabled();
59+
});
60+
61+
it('does NOT show popup when disabled', () => {
62+
renderComponent({ disabled: true });
63+
// When disabled, clicking should not trigger popup logic
64+
// Verify the switch is disabled
65+
const switchControl = screen.getByLabelText(/enable discussions/i);
66+
expect(switchControl).toBeDisabled();
67+
});
5268
});

src/pages-and-resources/pages/PageCard.test.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,18 @@ describe('LiveSettings', () => {
8383
expect(buttons.length).toBeGreaterThan(0);
8484
});
8585
});
86+
87+
it('renders enabled by default when readOnly is not specified (default false)', async () => {
88+
// readOnly defaults to false - page card should render with enabled settings
89+
render(
90+
<PagesAndResourcesProvider courseId={courseId} isEditable={true}>
91+
<PageGrid pages={mockPageConfig} />
92+
</PagesAndResourcesProvider>,
93+
);
94+
// Should render buttons (enabled by default)
95+
await waitFor(() => {
96+
const buttons = screen.queryAllByRole('button');
97+
expect(buttons.length).toBeGreaterThan(0);
98+
});
99+
});
86100
});

src/pages-and-resources/pages/PageSettingButton.test.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ describe('PageSettingButton', () => {
6464
expect(button).toBeDisabled();
6565
});
6666

67+
it('renders enabled button by default when readOnly is not specified (default false)', () => {
68+
// readOnly defaults to false - button should be enabled
69+
renderComponent({ legacyLink: 'http://legacylink.com/textbooks' });
70+
71+
const linkElement = screen.getByRole('link');
72+
expect(linkElement).toBeInTheDocument();
73+
});
74+
6775
it('does not render when no legacyLink and cannot configure', () => {
6876
renderComponent({ allowedOperations: null, legacyLink: null });
6977

0 commit comments

Comments
 (0)