Skip to content

Commit

Permalink
Add unittests for copy, move
Browse files Browse the repository at this point in the history
  • Loading branch information
lookacat committed Jun 13, 2022
1 parent 0dd23cd commit 4568e81
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 84 deletions.
1 change: 0 additions & 1 deletion packages/web-app-files/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export default defineComponent({
...mapMutations('Files', ['UPSERT_RESOURCE']),
handleShortcut(event) {
console.log(event)
const key = event.keyCode || event.which
const ctr = window.navigator.platform.match('Mac') ? event.metaKey : event.ctrlKey
if (!ctr /* CTRL | CMD */) return
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-files/src/helpers/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export * from './privatePreviewBlob'
export * from './publicPreviewUrl'
export * from './resource'
export * from './sameResource'
export * from './move'
export * from './copyMove'
132 changes: 132 additions & 0 deletions packages/web-app-files/tests/unit/helpers/resource/copyMove.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import * as Resource from '../../../../src/helpers/resource'

let resourcesToMove
let targetFolder

describe('copyMove', () => {
beforeEach(() => {
resourcesToMove = [
{
id: 'a',
name: 'a',
webDavPath: '/a'
},
{
id: 'b',
name: 'b',
webDavPath: '/b'
}
]
targetFolder = {
id: 'target',
path: 'target',
webDavPath: '/target'
}
})
it('should copy files if no conflicts exist', async () => {
const client = {
files: {
list: async () => {
return []
},
copy: jest.fn()
}
}
await Resource.copy(
resourcesToMove,
targetFolder,
client,
jest.fn(),
jest.fn(),
jest.fn(),
jest.fn(),
jest.fn(),
jest.fn()
)
expect(client.files.copy).toHaveBeenCalledWith('/a', '/target/a', false)
expect(client.files.copy).toHaveBeenCalledWith('/b', '/target/b', false)
})
it('should move files if no conflicts exist', async () => {
const client = {
files: {
list: async () => {
return []
},
move: jest.fn()
}
}
await Resource.move(
resourcesToMove,
targetFolder,
client,
jest.fn(),
jest.fn(),
jest.fn(),
jest.fn(),
jest.fn(),
jest.fn()
)
expect(client.files.move).toHaveBeenCalledWith('/a', '/target/a', false)
expect(client.files.move).toHaveBeenCalledWith('/b', '/target/b', false)
})
it('should not show message if no conflict exists', async () => {
const client = {
files: {
list: async () => {
return [
{
id: 'c',
path: 'target/c',
webDavPath: '/target/c',
name: '/target/c'
}
]
}
}
}
const resolveFileExistsMethod = jest
.fn()
.mockImplementation(() => Promise.resolve({ strategy: 0 } as Resource.ResolveConflict))
await Resource.resolveAllConflicts(
resourcesToMove,
targetFolder,
client,
jest.fn(),
jest.fn(),
jest.fn(),
jest.fn(),
resolveFileExistsMethod
)
expect(resolveFileExistsMethod).not.toHaveBeenCalled()
})
it('should show message if conflict exists', async () => {
const client = {
files: {
list: async () => {
return [
{
id: 'a',
path: 'target/a',
webDavPath: '/target/a',
name: '/target/a'
}
]
}
}
}
const resolveFileExistsMethod = jest
.fn()
.mockImplementation(() => Promise.resolve({ strategy: 0 } as Resource.ResolveConflict))
await Resource.resolveAllConflicts(
resourcesToMove,
targetFolder,
client,
jest.fn(),
jest.fn(),
jest.fn(),
jest.fn(),
resolveFileExistsMethod
)
expect(resolveFileExistsMethod).toHaveBeenCalled()
})
})
82 changes: 0 additions & 82 deletions packages/web-app-files/tests/unit/helpers/resource/move.spec.ts

This file was deleted.

0 comments on commit 4568e81

Please sign in to comment.