-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mespapiers): Normalize File usage instead Blob
This is the only existing case in Blob, and it will be easier to work only with Files.
- Loading branch information
Showing
7 changed files
with
44 additions
and
74 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
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
14 changes: 0 additions & 14 deletions
14
packages/cozy-mespapiers-lib/src/helpers/makeBlobWithCustomAttrs.js
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
packages/cozy-mespapiers-lib/src/helpers/makeBlobWithCustomAttrs.spec.js
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
packages/cozy-mespapiers-lib/src/helpers/makeFileWithBlob.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,12 @@ | ||
/** | ||
* @param {Blob} blobFile - Blob file | ||
* @param {Object} attrs - Custom attributes | ||
* @param {string} attrs.name - File name | ||
* @returns {File} | ||
*/ | ||
export const makeFileWithBlob = (blobFile, { name } = {}) => { | ||
const defaultName = `${name || 'temp'}.${blobFile.type.split('/')[1]}` | ||
const newFile = new File([blobFile], defaultName, { type: blobFile.type }) | ||
|
||
return newFile | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/cozy-mespapiers-lib/src/helpers/makeFileWithBlob.spec.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,25 @@ | ||
import { makeFileWithBlob } from './makeFileWithBlob' | ||
|
||
describe('makeFileWithBlob', () => { | ||
const blob = new Blob(['data'], { type: 'image/png' }) | ||
|
||
it('should return File constructor', () => { | ||
const res = makeFileWithBlob(blob, {}) | ||
expect(res.constructor).toBe(File) | ||
}) | ||
|
||
it('should set the name provided', () => { | ||
const res = makeFileWithBlob(blob, { name: 'my file' }) | ||
expect(res.name).toBe('my file.png') | ||
}) | ||
|
||
it('should set a default name', () => { | ||
const res = makeFileWithBlob(blob) | ||
expect(res.name).toBe('temp.png') | ||
}) | ||
|
||
it('should return File with original type', () => { | ||
const res = makeFileWithBlob(blob, {}) | ||
expect(res.type).toBe('image/png') | ||
}) | ||
}) |