-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: updated upload component to typescript
It is believed this will help integrating with the existing store logic. No runtime changes are intended, only typings so everything is as clear as possible when reusing the already existing mobile upload flow
- Loading branch information
Showing
17 changed files
with
1,516 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,8 @@ | |
"react/display-name": "off" | ||
} | ||
} | ||
] | ||
], | ||
"parserOptions": { | ||
"project": "tsconfig.json" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
presets: ['cozy-app', '@babel/env'] | ||
presets: ['cozy-app'] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'cozy-ui/*' |
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 was deleted.
Oops, something went wrong.
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,40 @@ | ||
import CozyClient from 'cozy-client' | ||
|
||
export interface Folder { | ||
_id: string | ||
} | ||
|
||
export interface FileForQueue { | ||
file: FileFromNative | ||
isDirectory: false | ||
} | ||
|
||
export interface DumbUploadProps { | ||
t: (key: string, options?: { smart_count: number }) => string | ||
stopMediaBackup: () => void | ||
navigate: (path: string) => void | ||
uploadFilesFromNative: DispatchProps['uploadFilesFromNative'] | ||
client: CozyClient | ||
vaultClient: CozyClient | ||
startMediaBackup: () => void | ||
items: FileFromNative[] | ||
} | ||
|
||
export interface DispatchProps { | ||
uploadFilesFromNative: ( | ||
files: FileForQueue[], | ||
folderId: string, | ||
successCallback: () => void, | ||
options: { client: CozyClient; vaultClient?: CozyClient }, | ||
alternateUploader?: ( | ||
files: FileForQueue[], | ||
folderId: string | ||
) => Promise<void> | ||
) => Promise<void> | ||
stopMediaBackup: () => void | ||
startMediaBackup: () => void | ||
} | ||
|
||
export interface FileFromNative { | ||
fileName: string | ||
} |
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,5 @@ | ||
import type { FileFromNative, FileForQueue } from './UploadTypes' | ||
|
||
export const generateForQueue = (files: FileFromNative[]): FileForQueue[] => { | ||
return files.map(file => ({ file: file, isDirectory: false })) | ||
} |
61 changes: 61 additions & 0 deletions
61
src/drive/web/modules/views/Upload/UploaderComponent.spec.tsx
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,61 @@ | ||
import React from 'react' | ||
import { render, RenderResult, waitFor } from '@testing-library/react' | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { DumbUpload } from 'drive/mobile/modules/upload' | ||
import { generateForQueue } from './UploadUtils' | ||
|
||
jest.mock('cozy-keys-lib', () => ({ | ||
withVaultClient: jest.fn().mockReturnValue({}) | ||
})) | ||
|
||
const tSpy = jest.fn() | ||
const uploadFilesFromNativeSpy = jest.fn() | ||
|
||
describe('DumbUpload component', () => { | ||
const defaultItems = [{ fileName: 'File1.pdf' }] | ||
|
||
const setupComponent = (): RenderResult< | ||
typeof import('/home/anc/cozy/cozy-drive/node_modules/@testing-library/dom/types/queries'), | ||
HTMLElement | ||
> => { | ||
const props = { | ||
client: {}, | ||
vaultClient: {}, | ||
t: tSpy, | ||
uploadFilesFromNative: uploadFilesFromNativeSpy, | ||
stopMediaBackup: jest.fn(), | ||
router: jest.fn(), | ||
navigate: jest.fn() | ||
} | ||
|
||
return render(<DumbUpload {...props} />) | ||
} | ||
|
||
describe('generateForQueue', () => { | ||
it('should generate the right object for the Drive queue', () => { | ||
const genetaredForQueue = generateForQueue(defaultItems) | ||
expect(genetaredForQueue).toEqual([ | ||
{ file: defaultItems[0], isDirectory: false } | ||
]) | ||
}) | ||
}) | ||
|
||
describe('Upload files', () => { | ||
it('should call uploadFileFromNative with the right arguments', async () => { | ||
const { rerender } = setupComponent() | ||
const folderId = 'io.cozy.root' | ||
|
||
rerender(<DumbUpload items={defaultItems} folder={{ _id: folderId }} />) | ||
|
||
await waitFor(() => { | ||
const genetaredForQueue = generateForQueue(defaultItems) | ||
expect(uploadFilesFromNativeSpy).toHaveBeenCalledWith( | ||
genetaredForQueue, | ||
folderId, | ||
expect.any(Function), | ||
{ client: {}, vaultClient: {} } | ||
) | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.