This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow uploading a folder to My Studies (#475)
- Loading branch information
Showing
8 changed files
with
140 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
59 changes: 59 additions & 0 deletions
59
...don-base-raas-ui/packages/base-raas-ui/src/models/files/__tests__/FileUploadGroup.test.js
This file contains 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,59 @@ | ||
import FileUploadGroup from '../FileUploadGroup'; | ||
|
||
describe('FileUploadGroup', () => { | ||
const currentTimeFromEpoch = Date.now(); | ||
const fileName = 'sample.json'; | ||
const size = 0; | ||
const file = { | ||
lastModified: currentTimeFromEpoch, | ||
lastModifiedDate: new Date(currentTimeFromEpoch), | ||
name: fileName, | ||
size, | ||
type: 'application/json', | ||
}; | ||
|
||
const resourceId = 'abcd'; | ||
|
||
function getFileUploadObject(fullFilePath) { | ||
const fileWithTopLevelFolder = JSON.parse(JSON.stringify(file)); | ||
fileWithTopLevelFolder.webkitRelativePath = fullFilePath; | ||
|
||
const fileUploadGroup = FileUploadGroup.create({ resourceId, state: 'PENDING' }); | ||
|
||
fileUploadGroup.add({ file: fileWithTopLevelFolder }); | ||
|
||
return fileUploadGroup.fileUploadObjects[0]; | ||
} | ||
|
||
it('should handle top level folder correctly', () => { | ||
const fileUploadObj = getFileUploadObject(`sampleFolder/${fileName}`); | ||
|
||
// OPERATE & CHECK | ||
expect(fileUploadObj.size).toEqual(size); | ||
expect(fileUploadObj.name).toEqual(fileName); | ||
expect(fileUploadObj.folder).toEqual('sampleFolder'); | ||
expect(fileUploadObj.fullFilePath).toEqual(`sampleFolder/${fileName}`); | ||
}); | ||
|
||
it('should handle sub level folder correctly', () => { | ||
// BUILD | ||
const fileUploadObj = getFileUploadObject(`sampleFolder/subfolder/${fileName}`); | ||
|
||
// OPERATE & CHECK | ||
expect(fileUploadObj.size).toEqual(size); | ||
expect(fileUploadObj.name).toEqual(fileName); | ||
expect(fileUploadObj.folder).toEqual('sampleFolder/subfolder'); | ||
expect(fileUploadObj.fullFilePath).toEqual(`sampleFolder/subfolder/${fileName}`); | ||
}); | ||
|
||
it('should handle uploading a file correctly', () => { | ||
// BUILD | ||
const fileUploadObj = getFileUploadObject(''); | ||
|
||
// OPERATE & CHECK | ||
expect(fileUploadObj.size).toEqual(size); | ||
expect(fileUploadObj.name).toEqual(fileName); | ||
expect(fileUploadObj.folder).toEqual(''); | ||
expect(fileUploadObj.fullFilePath).toEqual(fileName); | ||
}); | ||
}); |
This file contains 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 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 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 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 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 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