mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-02-18 14:56:26 -05:00
* Get a few mocks working in __mocks__ folder * Move more mocks into __mocks__ * Move mocks * Move zustand mock * Add more mocks to __mocks__ * More mocks * Move more files to __mocks__ and audit existing mocks * Mock react navigation in __mocks__ * Restore test to help with imports after jest env torn down * Add fake timer to integration test with userEvent * Add RN paper mock
78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
class RNSInfo {
|
|
static stores = new Map();
|
|
|
|
static getServiceName( o = {} ) {
|
|
return o.sharedPreferencesName
|
|
|| o.keychainService
|
|
|| "default";
|
|
}
|
|
|
|
static validateString( s ) {
|
|
if ( typeof s !== "string" ) { throw new Error( "Invalid string:", s ); }
|
|
}
|
|
|
|
static getItem = jest.fn( async ( k, o ) => {
|
|
RNSInfo.validateString( k );
|
|
|
|
const serviceName = RNSInfo.getServiceName( o );
|
|
const service = RNSInfo.stores.get( serviceName );
|
|
|
|
if ( service ) { return service.get( k ) || null; }
|
|
return null;
|
|
} );
|
|
|
|
static getAllItems = jest.fn( async o => {
|
|
const serviceName = RNSInfo.getServiceName( o );
|
|
const service = RNSInfo.stores.get( serviceName );
|
|
let mappedValues = [];
|
|
|
|
if ( service?.size ) {
|
|
// for ( const [k, v] of service.entries() ) {
|
|
// mappedValues.push( { key: k, value: v, service: serviceName } );
|
|
// }
|
|
mappedValues = service.entries( ).map(
|
|
( key, value ) => ( { key, value, service: serviceName } )
|
|
);
|
|
}
|
|
|
|
return mappedValues;
|
|
} );
|
|
|
|
static setItem = jest.fn( async ( k, v, o ) => {
|
|
RNSInfo.validateString( k );
|
|
RNSInfo.validateString( v );
|
|
|
|
const serviceName = RNSInfo.getServiceName( o );
|
|
let service = RNSInfo.stores.get( serviceName );
|
|
|
|
if ( !service ) {
|
|
RNSInfo.stores.set( serviceName, new Map() );
|
|
service = RNSInfo.stores.get( serviceName );
|
|
}
|
|
|
|
service.set( k, v );
|
|
|
|
return null;
|
|
} );
|
|
|
|
static deleteItem = jest.fn( async ( k, o ) => {
|
|
RNSInfo.validateString( k );
|
|
|
|
const serviceName = RNSInfo.getServiceName( o );
|
|
const service = RNSInfo.stores.get( serviceName );
|
|
|
|
if ( service ) { service.delete( k ); }
|
|
|
|
return null;
|
|
} );
|
|
|
|
static hasEnrolledFingerprints = jest.fn( async () => true );
|
|
|
|
static setInvalidatedByBiometricEnrollment = jest.fn();
|
|
|
|
// "Touch ID" | "Face ID" | false
|
|
static isSensorAvailable = jest.fn( async () => "Face ID" );
|
|
}
|
|
|
|
module.exports = RNSInfo;
|