This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle read permissions on runtime when seedvault is imported (Androi…
- Loading branch information
1 parent
12c972e
commit 637c5a8
Showing
2 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/mobile/__tests__/ui/components/SeedVaultImportComponent.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,81 @@ | ||
import assign from 'lodash/assign'; | ||
import noop from 'lodash/noop'; | ||
import React from 'react'; | ||
import { PermissionsAndroid } from 'react-native'; | ||
import { shallow } from 'enzyme'; | ||
import { SeedVaultImportComponent } from 'ui/components/SeedVaultImportComponent'; | ||
|
||
jest.mock('rn-fetch-blob', () => ({ DocumentDir: () => {} })); | ||
jest.mock('nodejs-mobile-react-native', () => ({ | ||
start: () => {}, | ||
channel: { | ||
addListener: () => {}, | ||
removeListener: () => {}, | ||
}, | ||
})); | ||
|
||
const getProps = (overrides) => | ||
assign( | ||
{}, | ||
{ | ||
theme: { input: {}, body: {}, primary: {} }, | ||
t: () => '', | ||
generateAlert: noop, | ||
openPasswordValidationModal: noop, | ||
onSeedImport: noop, | ||
onRef: noop, | ||
}, | ||
overrides, | ||
); | ||
|
||
describe('Testing SeedVaultImportComponent component', () => { | ||
describe('instance methods', () => { | ||
describe('when called', () => { | ||
describe('#grantPermissions', () => { | ||
beforeEach(() => { | ||
jest.mock('PermissionsAndroid', () => ({ | ||
request: jest.fn(() => Promise.resolve(true)), | ||
PERMISSIONS: {}, | ||
RESULTS: { | ||
GRANTED: 'granted', | ||
}, | ||
})); | ||
}); | ||
|
||
describe('when read permission is already granted', () => { | ||
it('should resolve true', () => { | ||
const props = getProps(); | ||
|
||
const instance = shallow(<SeedVaultImportComponent {...props} />).instance(); | ||
|
||
return instance.grantPermissions().then((result) => expect(result).toEqual(true)); | ||
}); | ||
}); | ||
|
||
describe('when read permission is granted by user', () => { | ||
it('should resolve "granted"', () => { | ||
PermissionsAndroid.request.mockReturnValueOnce(Promise.resolve('granted')); | ||
const props = getProps(); | ||
|
||
const instance = shallow(<SeedVaultImportComponent {...props} />).instance(); | ||
|
||
return instance.grantPermissions().then((result) => expect(result).toEqual('granted')); | ||
}); | ||
}); | ||
|
||
describe('when read permission is denied by user', () => { | ||
it('should throw an error with message "Read permissions not granted."', () => { | ||
PermissionsAndroid.request.mockReturnValueOnce(Promise.resolve('denied')); | ||
const props = getProps(); | ||
|
||
const instance = shallow(<SeedVaultImportComponent {...props} />).instance(); | ||
|
||
return instance | ||
.grantPermissions() | ||
.catch((err) => expect(err).toEqual(new Error('Read permissions not granted.'))); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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