-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for permissions helper
- Loading branch information
1 parent
c778eda
commit d56f702
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
packages/web-app-files/tests/unit/helpers/permissions.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,51 @@ | ||
import { canBeMoved } from '@files/src/helpers/permissions.js' | ||
|
||
describe('permissions helper', () => { | ||
describe('canBeMoved function', () => { | ||
it.each([ | ||
{ isReceivedShare: false, isMounted: false, canBeDeleted: true, parentPath: '' }, | ||
{ isReceivedShare: false, isMounted: false, canBeDeleted: true, parentPath: 'folder' }, | ||
{ isReceivedShare: true, isMounted: false, canBeDeleted: true, parentPath: 'folder' }, | ||
{ isReceivedShare: false, isMounted: true, canBeDeleted: true, parentPath: 'folder' } | ||
])( | ||
'should return true if the given resource can be deleted and if it is not mounted in root', | ||
input => { | ||
// a resource is supposed to be external if it is a received share or resource is mounted | ||
// a resource is supposed to be `mounted in root` if parentPath is empty string and resource is external | ||
expect( | ||
canBeMoved( | ||
{ | ||
isReceivedShare: () => input.isReceivedShare, | ||
isMounted: () => input.isMounted, | ||
canBeDeleted: () => input.canBeDeleted | ||
}, | ||
input.parentPath | ||
) | ||
).toBeTruthy() | ||
} | ||
) | ||
it.each([ | ||
{ isReceivedShare: false, isMounted: false, canBeDeleted: false, parentPath: '' }, | ||
{ isReceivedShare: false, isMounted: false, canBeDeleted: false, parentPath: 'folder' }, | ||
{ isReceivedShare: true, isMounted: false, canBeDeleted: false, parentPath: 'folder' }, | ||
{ isReceivedShare: false, isMounted: true, canBeDeleted: false, parentPath: 'folder' }, | ||
{ isReceivedShare: false, isMounted: true, canBeDeleted: true, parentPath: '' }, | ||
{ isReceivedShare: true, isMounted: false, canBeDeleted: true, parentPath: '' }, | ||
{ isReceivedShare: true, isMounted: true, canBeDeleted: true, parentPath: '' } | ||
])( | ||
'should return false if the given resource cannot be deleted or if it is mounted in root', | ||
input => { | ||
expect( | ||
canBeMoved( | ||
{ | ||
isReceivedShare: () => input.isReceivedShare, | ||
isMounted: () => input.isMounted, | ||
canBeDeleted: () => input.canBeDeleted | ||
}, | ||
input.parentPath | ||
) | ||
).toBeFalsy() | ||
} | ||
) | ||
}) | ||
}) |