generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 5
feat(authz): [FC-0099] create toggle to make a library plublic read #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
brian-smith-tcril
merged 9 commits into
openedx:master
from
eduNEXT:dcoa/toggle-plublic-read
Oct 29, 2025
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
87dcf70
refactor: modify actions to add splitter
dcoa 4ed28ad
feat: add API function to update the library metadata
dcoa 0e5b53f
feat: create a toggle component to make the library public read
dcoa 757f76f
refactor: update behaviour depending on user permissions
dcoa b387aba
feat: add success toast
dcoa 968e317
refactor: use stack to display the actions
dcoa 82b5f05
style: fix typo
dcoa 8ee18c3
style: add mx-5 to divider to avoid wide growth
dcoa 1ce31ac
chore: update paragon to work with useMediaQuery
dcoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | |
| import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
| import { | ||
| useLibrary, usePermissionsByRole, useTeamMembers, useAssignTeamMembersRole, useRevokeUserRoles, | ||
| useUpdateLibrary, | ||
| } from './hooks'; | ||
|
|
||
| jest.mock('@edx/frontend-platform/auth', () => ({ | ||
|
|
@@ -340,3 +341,80 @@ describe('useRevokeUserRoles', () => { | |
| expect(calledUrl.searchParams.get('scope')).toBe(revokeRoleData.scope); | ||
| }); | ||
| }); | ||
|
|
||
| describe('useUpdateLibrary', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests appear to only be testing that the title can be updated properly. Not blocking, but it'd be nice to have tests verifying each part of |
||
| const queryKeyTest = ['org.openedx.frontend.app.adminConsole', 'authz', 'library', 'lib:123']; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('calls updateLibrary with correct params and updates cache', async () => { | ||
| const mockData = { id: 'lib:123', title: 'Library Test' }; | ||
| getAuthenticatedHttpClient.mockReturnValue({ | ||
| patch: jest.fn().mockResolvedValue({ data: mockData }), | ||
| }); | ||
| const { result } = renderHook(() => useUpdateLibrary(), { wrapper: createWrapper() }); | ||
|
|
||
| await act(async () => { | ||
| await result.current.mutateAsync({ | ||
| libraryId: 'lib:123', | ||
| updatedData: { title: 'Library Test' }, | ||
| }); | ||
| }); | ||
|
|
||
| expect(getAuthenticatedHttpClient).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('sets query data on success', async () => { | ||
| const mockData = { id: 'lib:123', title: 'Updated Library' }; | ||
| getAuthenticatedHttpClient.mockReturnValue({ | ||
| patch: jest.fn().mockResolvedValue({ data: mockData }), | ||
| }); | ||
|
|
||
| const queryClient = new QueryClient(); | ||
| const wrapper = ({ children }: { children: ReactNode }) => ( | ||
| <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
| ); | ||
|
|
||
| const { result } = renderHook(() => useUpdateLibrary(), { wrapper }); | ||
|
|
||
| await act(async () => { | ||
| await result.current.mutateAsync({ | ||
| libraryId: 'lib:123', | ||
| updatedData: { title: 'Updated Library' }, | ||
| }); | ||
| }); | ||
|
|
||
| // verify cache updated with the returned data | ||
| expect(queryClient.getQueryData(queryKeyTest)).toEqual(mockData); | ||
| expect(getAuthenticatedHttpClient).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('invalidates query on settled', async () => { | ||
| const mockData = { id: 'lib:123', title: 'Final Title' }; | ||
| getAuthenticatedHttpClient.mockReturnValue({ | ||
| patch: jest.fn().mockResolvedValue({ data: mockData }), | ||
| }); | ||
| const queryClient = new QueryClient(); | ||
| const invalidateSpy = jest.spyOn(queryClient, 'invalidateQueries'); | ||
|
|
||
| const wrapper = ({ children }: { children: ReactNode }) => ( | ||
| <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
| ); | ||
|
|
||
| const { result } = renderHook(() => useUpdateLibrary(), { wrapper }); | ||
|
|
||
| await act(async () => { | ||
| await result.current.mutateAsync({ | ||
| libraryId: 'lib:123', | ||
| updatedData: { title: 'Final Title' }, | ||
| }); | ||
| }); | ||
|
|
||
| expect(invalidateSpy).toHaveBeenCalledWith({ | ||
| queryKey: queryKeyTest, | ||
| }); | ||
| expect(getAuthenticatedHttpClient).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.