-
Notifications
You must be signed in to change notification settings - Fork 17
[PB-4965] bugfix/".folder" naming issue #311
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
CandelR
merged 3 commits into
release/1.8.3
from
bugfix/PB-4965-move-item-folder-name-issue
Oct 2, 2025
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,321 @@ | ||
| import { DriveItemDataProps } from '../types/drive'; | ||
| import { getDisplayName } from './itemNames'; | ||
|
|
||
| describe('getDisplayName', () => { | ||
| describe('Folders', () => { | ||
| it('should return the folder name as-is', () => { | ||
| const folder = { | ||
| id: 1, | ||
| name: 'Documents', | ||
| isFolder: true, | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(folder)).toBe('Documents'); | ||
| }); | ||
|
|
||
| it('should handle folder names with special characters', () => { | ||
| const folder: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'My Folder (2024)', | ||
| isFolder: true, | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(folder)).toBe('My Folder (2024)'); | ||
| }) as unknown as DriveItemDataProps; | ||
|
|
||
| it('should handle folder names with dots', () => { | ||
| const folder: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'backup.2024', | ||
| isFolder: true, | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(folder)).toBe('backup.2024'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Files without extension in name', () => { | ||
| it('should append the extension to the file name', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'report', | ||
| type: 'pdf', | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('report.pdf'); | ||
| }); | ||
|
|
||
| it('should handle different file extensions', () => { | ||
| const cases = [ | ||
| { name: 'image', type: 'jpg', expected: 'image.jpg' }, | ||
| { name: 'document', type: 'docx', expected: 'document.docx' }, | ||
| { name: 'video', type: 'mp4', expected: 'video.mp4' }, | ||
| { name: 'data', type: 'json', expected: 'data.json' }, | ||
| ]; | ||
|
|
||
| cases.forEach(({ name, type, expected }) => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name, | ||
| type, | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe(expected); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Files with extension already in name', () => { | ||
| it('should not duplicate the extension if already present', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'report.pdf', | ||
| type: 'pdf', | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('report.pdf'); | ||
| }); | ||
|
|
||
| it('should handle case-insensitive extension matching', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'Image.JPG', | ||
| type: 'jpg', | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('Image.JPG'); | ||
| }); | ||
|
|
||
| it('should handle files with multiple dots in name', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'backup.2024.01.15.tar', | ||
| type: 'tar', | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('backup.2024.01.15.tar'); | ||
| }); | ||
|
|
||
| it('should not append extension if name ends with it in mixed case', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'document.PDF', | ||
| type: 'pdf', | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('document.PDF'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Files without type', () => { | ||
| it('should return the name as-is when type is undefined', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'unknown', | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('unknown'); | ||
| }); | ||
|
|
||
| it('should return the name as-is when type is null', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'noextension', | ||
| type: undefined, | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('noextension'); | ||
| }); | ||
|
|
||
| it('should preserve existing extension in name when type is undefined', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'file.txt', | ||
| type: undefined, | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('file.txt'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Edge cases', () => { | ||
| it('should handle empty type string', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'file', | ||
| type: '', | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('file'); | ||
| }); | ||
|
|
||
| it('should handle type with leading/trailing whitespace', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'document', | ||
| type: ' pdf ', | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('document. pdf '); | ||
| }); | ||
|
|
||
| it('should handle files with dots but different extension', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'archive.tar', | ||
| type: 'gz', | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('archive.tar.gz'); | ||
| }); | ||
|
|
||
| it('should handle numeric extensions', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'file', | ||
| type: '001', | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('file.001'); | ||
| }); | ||
|
|
||
| it('should handle special characters in extension', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'document', | ||
| type: 'pdf~', | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('document.pdf~'); | ||
| }); | ||
|
|
||
| it('should handle very long extensions', () => { | ||
| const longExtension = 'verylongextensionname'; | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'file', | ||
| type: longExtension, | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe(`file.${longExtension}`); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Real-world scenarios', () => { | ||
| it('should handle common document files', () => { | ||
| const scenarios = [ | ||
| { name: 'Meeting Notes', type: 'docx', expected: 'Meeting Notes.docx' }, | ||
| { name: 'Budget 2024', type: 'xlsx', expected: 'Budget 2024.xlsx' }, | ||
| { name: 'Presentation', type: 'pptx', expected: 'Presentation.pptx' }, | ||
| ]; | ||
|
|
||
| scenarios.forEach(({ name, type, expected }) => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name, | ||
| type, | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe(expected); | ||
| }); | ||
| }); | ||
|
|
||
| it('should handle compressed archives with double extensions', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'backup.tar', | ||
| type: 'gz', | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('backup.tar.gz'); | ||
| }); | ||
|
|
||
| it('should handle versioned files', () => { | ||
| const file: DriveItemDataProps = { | ||
| id: 1, | ||
| name: 'document.v2', | ||
| type: 'pdf', | ||
| isFolder: false, | ||
| fileId: 'file-1', | ||
| updatedAt: '2025-01-01', | ||
| createdAt: '2025-01-01', | ||
| } as unknown as DriveItemDataProps; | ||
|
|
||
| expect(getDisplayName(file)).toBe('document.v2.pdf'); | ||
| }); | ||
| }); | ||
| }); | ||
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,41 @@ | ||
| import { DriveItemDataProps } from '../types/drive'; | ||
|
|
||
| /** | ||
| * Generates a display name for a drive item (file or folder). | ||
| * For folders, returns the name as-is. | ||
| * For files, appends the extension if it's not already present in the name. | ||
| * | ||
| * @param {DriveItemDataProps} item - The drive item (file or folder) | ||
| * @returns {string} The formatted display name | ||
| * | ||
| * @example | ||
| * // Folder | ||
| * getDisplayName({ name: 'Documents', isFolder: true }) // 'Documents' | ||
| * | ||
| * @example | ||
| * // File without extension in name | ||
| * getDisplayName({ name: 'report', type: 'pdf', isFolder: false }) // 'report.pdf' | ||
| * | ||
| * @example | ||
| * // File with extension already in name | ||
| * getDisplayName({ name: 'report.pdf', type: 'pdf', isFolder: false }) // 'report.pdf' | ||
| * | ||
| * @example | ||
| * // File without type | ||
| * getDisplayName({ name: 'unknown', isFolder: false }) // 'unknown' | ||
| */ | ||
| export const getDisplayName = (item: DriveItemDataProps): string => { | ||
| if (item.isFolder || !item.type) { | ||
| return item.name; | ||
| } | ||
|
|
||
| const normalizedExtension = item.type.trim().toLowerCase(); | ||
| const normalizedName = item.name.toLowerCase(); | ||
|
|
||
| const expectedEnding = `.${normalizedExtension}`; | ||
| if (normalizedName.endsWith(expectedEnding)) { | ||
| return item.name; | ||
| } | ||
|
|
||
| return `${item.name}.${item.type}`; | ||
| }; |
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.