-
Notifications
You must be signed in to change notification settings - Fork 131
fix: Display correct right click menu in file viewer 🐛 #3598
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
lethemanh
merged 1 commit into
master
from
display-correct-right-click-menu-in-file-viewer
Nov 5, 2025
Merged
Changes from all commits
Commits
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
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
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 |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| import { | ||
| navigateToModal, | ||
| navigateToModalWithMultipleFile, | ||
| getContextMenuActions | ||
| } from './helpers' | ||
|
|
||
| jest.mock('@/lib/path', () => ({ | ||
| joinPath: jest.fn((...paths) => paths.join('/')) | ||
| })) | ||
|
|
||
| describe('actions helpers', () => { | ||
| describe('navigateToModal', () => { | ||
| let mockNavigate | ||
|
|
||
| beforeEach(() => { | ||
| mockNavigate = jest.fn() | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| it('should navigate to modal with pathname and single file', () => { | ||
| const params = { | ||
| navigate: mockNavigate, | ||
| pathname: '/folder/123', | ||
| files: { id: 'file-123', name: 'test.pdf' }, | ||
| path: 'preview' | ||
| } | ||
|
|
||
| navigateToModal(params) | ||
|
|
||
| expect(mockNavigate).toHaveBeenCalledWith( | ||
| '/folder/123/file/file-123/preview' | ||
| ) | ||
| }) | ||
|
|
||
| it('should navigate to modal with pathname and array of files', () => { | ||
| const params = { | ||
| navigate: mockNavigate, | ||
| pathname: '/folder/456', | ||
| files: [ | ||
| { id: 'file-1', name: 'first.pdf' }, | ||
| { id: 'file-2', name: 'second.pdf' } | ||
| ], | ||
| path: 'edit' | ||
| } | ||
|
|
||
| navigateToModal(params) | ||
|
|
||
| expect(mockNavigate).toHaveBeenCalledWith('/folder/456/file/file-1/edit') | ||
| }) | ||
| }) | ||
|
|
||
| describe('navigateToModalWithMultipleFile', () => { | ||
| let mockNavigate | ||
|
|
||
| beforeEach(() => { | ||
| mockNavigate = jest.fn() | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| it('should navigate with pathname, multiple files, and search params', () => { | ||
| const params = { | ||
| navigate: mockNavigate, | ||
| pathname: '/folder/123', | ||
| files: [ | ||
| { id: 'file-1', name: 'doc1.pdf' }, | ||
| { id: 'file-2', name: 'doc2.pdf' }, | ||
| { id: 'file-3', name: 'doc3.pdf' } | ||
| ], | ||
| path: 'share', | ||
| search: 'tab=link' | ||
| } | ||
|
|
||
| navigateToModalWithMultipleFile(params) | ||
|
|
||
| expect(mockNavigate).toHaveBeenCalledWith( | ||
| { | ||
| pathname: '/folder/123/share', | ||
| search: '?tab=link' | ||
| }, | ||
| { | ||
| state: { fileIds: ['file-1', 'file-2', 'file-3'] } | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it('should navigate with pathname and multiple files without search params', () => { | ||
| const params = { | ||
| navigate: mockNavigate, | ||
| pathname: '/recent', | ||
| files: [ | ||
| { id: 'file-a', name: 'image1.jpg' }, | ||
| { id: 'file-b', name: 'image2.jpg' } | ||
| ], | ||
| path: 'move' | ||
| } | ||
|
|
||
| navigateToModalWithMultipleFile(params) | ||
|
|
||
| expect(mockNavigate).toHaveBeenCalledWith( | ||
| { | ||
| pathname: '/recent/move', | ||
| search: '' | ||
| }, | ||
| { | ||
| state: { fileIds: ['file-a', 'file-b'] } | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it('should handle empty search parameter', () => { | ||
| const params = { | ||
| navigate: mockNavigate, | ||
| pathname: '/folder/456', | ||
| files: [ | ||
| { id: 'file-1', name: 'test1.pdf' }, | ||
| { id: 'file-2', name: 'test2.pdf' } | ||
| ], | ||
| path: 'delete', | ||
| search: '' | ||
| } | ||
|
|
||
| navigateToModalWithMultipleFile(params) | ||
|
|
||
| expect(mockNavigate).toHaveBeenCalledWith( | ||
| { | ||
| pathname: '/folder/456/delete', | ||
| search: '' | ||
| }, | ||
| { | ||
| state: { fileIds: ['file-1', 'file-2'] } | ||
| } | ||
| ) | ||
| }) | ||
| }) | ||
|
|
||
| describe('getContextMenuActions', () => { | ||
| it('should return all actions when all have displayInContextMenu !== false', () => { | ||
| const actions = [ | ||
| { download: { displayInContextMenu: true, name: 'Download' } }, | ||
| { share: { name: 'Share' } }, // undefined displayInContextMenu should be included | ||
| { rename: { displayInContextMenu: undefined, name: 'Rename' } } | ||
| ] | ||
|
|
||
| const result = getContextMenuActions(actions) | ||
|
|
||
| expect(result).toEqual(actions) | ||
| expect(result).toHaveLength(3) | ||
| }) | ||
|
|
||
| it('should filter out actions with displayInContextMenu: false', () => { | ||
| const actions = [ | ||
| { download: { displayInContextMenu: true, name: 'Download' } }, | ||
| { share: { displayInContextMenu: false, name: 'Share' } }, | ||
| { rename: { name: 'Rename' } }, | ||
| { delete: { displayInContextMenu: false, name: 'Delete' } } | ||
| ] | ||
|
|
||
| const result = getContextMenuActions(actions) | ||
|
|
||
| expect(result).toEqual([ | ||
| { download: { displayInContextMenu: true, name: 'Download' } }, | ||
| { rename: { name: 'Rename' } } | ||
| ]) | ||
| expect(result).toHaveLength(2) | ||
| }) | ||
| }) | ||
| }) |
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.
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.