diff --git a/squarenotsquare/__mock__/mockMaterialIcons.js b/squarenotsquare/__mock__/mockMaterialIcons.js new file mode 100644 index 0000000..3f3d1b9 --- /dev/null +++ b/squarenotsquare/__mock__/mockMaterialIcons.js @@ -0,0 +1,7 @@ +class MaterialIcon { + loadFont(){ + return true; + } +} + +export default MaterialIcon; \ No newline at end of file diff --git a/squarenotsquare/__mock__/mockRealm.js b/squarenotsquare/__mock__/mockRealm.js deleted file mode 100644 index e9fe715..0000000 --- a/squarenotsquare/__mock__/mockRealm.js +++ /dev/null @@ -1,135 +0,0 @@ -// https://github.com/realm/realm-js/issues/370#issuecomment-270849466 -export default class MockRealm { - constructor(params) { - this.schema = {}; - this.schemaVersion = params.schemaVersion; - this.callbackList = []; - this.data = {}; - this.schemaCallbackList = {}; - params.schema.forEach((schema) => { - this.data[schema.name] = {}; - }); - params.schema.forEach((schema) => { - this.schema[schema.name] = schema; - }); - this.lastLookedUpModel = null; - } - - objects(schemaName) { - this.lastLookedUpModel = schemaName; - const objects = Object.values(this.data[schemaName]); - objects.values = () => objects; - objects.sorted = () => this.compareFunc ? objects.sort(this.compareFunc) : objects.sort(); - objects.addListener = (cb) => { - if (this.schemaCallbackList[schemaName]) { - this.schemaCallbackList[schemaName].push(cb); - } else { - this.schemaCallbackList[schemaName] = [cb]; - } - }; - objects.removeListener = () => {}; - objects.filtered = this.filtered ? this.filtered.bind(this, schemaName) : () => objects; - return objects; - } - - write(fn) { - this.writing = true; - fn(); - this.writing = false; - } - - create(schemaName, object) { - const modelObject = object; - const properties = this.schema[schemaName].schema.properties; - Object.keys(properties).forEach((key) => { - if (modelObject[key] && modelObject[key].model) { - this.data[modelObject[key].model][modelObject[key].id] = this.create( - modelObject[key].model, modelObject[key], - ); - } else if (modelObject[key] && modelObject[key].length && modelObject[key][0].model) { - modelObject[key].forEach((obj) => { - this.data[modelObject[key][0].model][obj.id] = obj; - }); - modelObject[key].filtered = this.filtered ? this.filtered : () => modelObject[key]; - modelObject[key].sorted = () => modelObject[key].sort(); - } else if (modelObject[key] === undefined) { - if (typeof properties[key] === 'object' && properties[key].optional) { - modelObject[key] = null; - } - if (typeof properties[key] === 'object' && ['list', 'linkingObjects'].includes(properties[key].type)) { - modelObject[key] = []; - modelObject[key].filtered = () => []; - modelObject[key].sorted = () => []; - } - } - }); - - this.data[schemaName][modelObject.id] = modelObject; - if (this.writing) { - if (this.schemaCallbackList[schemaName]) { - this.schemaCallbackList[schemaName].forEach(cb => cb(schemaName, { - insertions: { length: 1 }, - modifications: { length: 0 }, - deletions: { length: 0 }, - })); - } - this.callbackList.forEach((cb) => { cb(); }); - } - return modelObject; - } - - objectForPrimaryKey(model, id) { - this.lastLookedUpModel = model; - return this.data[model][id]; - } - - delete(object) { - if (this.lastLookedUpModel || object.model) { - const model = object.model ? object.model : this.lastLookedUpModel - if (Array.isArray(object)) { - object.forEach((item) => { - delete this.data[model][item.id]; - }); - } - delete this.data[model][object.id]; - if (this.writing) { - if (this.schemaCallbackList[model]) { - this.schemaCallbackList[model].forEach(cb => cb(model, { - insertions: { length: 0 }, - modifications: { length: 0 }, - deletions: { length: 1 }, - })); - } - this.callbackList.forEach((cb) => { cb(); }); - } - } - } - - deleteAll() { - Object.keys(this.schema).forEach((key) => { - if (this.writing && this.schemaCallbackList[this.schema[key].name]) { - this.schemaCallbackList[this.schema[key].name].forEach(cb => cb(key, { - insertions: { length: 0 }, - modifications: { length: 0 }, - deletions: { length: Object.values(this.data[this.schema[key].name]).length }, - })); - } - this.data[this.schema[key].name] = {}; - }); - if (this.writing) this.callbackList.forEach((cb) => { cb(); }); - } - - addListener(event, callback) { - this.callbackList.push(callback); - } - - prepareData(schemaName, objects) { - objects.forEach((object) => { - this.create(schemaName, object); - }); - } - } - - MockRealm.Object = class Object { - isValid() { return true; } - }; \ No newline at end of file diff --git a/squarenotsquare/__mock__/mockRealmObject.js b/squarenotsquare/__mock__/mockRealmObject.js index cebcc79..3337e6a 100644 --- a/squarenotsquare/__mock__/mockRealmObject.js +++ b/squarenotsquare/__mock__/mockRealmObject.js @@ -19,6 +19,7 @@ export default class MockRealm{ objects(repoName){ let objects = this[repoName]; objects.filtered = this.filtered ? this.filtered.bind(this, repoName) : () => objects; + objects.sorted = this.sorted ? this.sorted.bind(this, repoName) : () => objects; return objects; } diff --git a/squarenotsquare/__tests__/DB-test.js b/squarenotsquare/__tests__/DB-test.js index a34b916..0907577 100644 --- a/squarenotsquare/__tests__/DB-test.js +++ b/squarenotsquare/__tests__/DB-test.js @@ -30,7 +30,7 @@ test('Realm DB returns null after exceptions', () => { }); test('dbAPI calls system repo getAllSystemValues()', () => { - return initDB('isNull', 'isNull') + return DbAPI.initDB('isNull', 'isNull') .then( () => { let returned = DbAPI.getAllSystemValues(); expect(returned).toEqual({}); @@ -38,7 +38,7 @@ test('dbAPI calls system repo getAllSystemValues()', () => { }); test('dbAPI calls system repo createSystemValue()', () => { - return initDB('isNull', 'isNull') + return DbAPI.initDB('isNull', 'isNull') .then( () => { let returned = DbAPI.createSystemValue(); expect(returned).toEqual(true); @@ -46,7 +46,7 @@ test('dbAPI calls system repo createSystemValue()', () => { }); test('dbAPI calls system repo deleteSystemValue()', () => { - return initDB('isNull', 'isNull') + return DbAPI.initDB('isNull', 'isNull') .then( () => { let returned = DbAPI.deleteSystemValue(); expect(returned).toEqual(true); @@ -54,7 +54,7 @@ test('dbAPI calls system repo deleteSystemValue()', () => { }); test('dbAPI calls system repo getSystemValue()', () => { - return initDB('isNull', 'isNull') + return DbAPI.initDB('isNull', 'isNull') .then( () => { let returned = DbAPI.getSystemValue('notakey'); expect(returned.id).toEqual(null); diff --git a/squarenotsquare/__tests__/Migration-test.js b/squarenotsquare/__tests__/Migration-test.js index 0448971..262e634 100644 --- a/squarenotsquare/__tests__/Migration-test.js +++ b/squarenotsquare/__tests__/Migration-test.js @@ -20,7 +20,7 @@ test('Realm migrates to V1', () => { migratev1(oldRealm, newRealm); expect(newRealm[SystemEntity.name][0].key).toBe('username'); - expect(newRealm[SystemEntity.name][0].value).toBe('changeme'); + expect(newRealm[SystemEntity.name][0].value).toBe('noname'); }) test('Realm halts V1 migration when schema is V2+', () => { diff --git a/squarenotsquare/jest.config.js b/squarenotsquare/jest.config.js index 3b8666c..9a7b2dd 100644 --- a/squarenotsquare/jest.config.js +++ b/squarenotsquare/jest.config.js @@ -8,7 +8,8 @@ module.exports = { // '@react-native-firebase/messaging: '/__mock__/mockFirebase.js', 'react-native-keychain': '/__mock__/mockKeyStore.js', '\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '/__mock__/file.js', - '^(realm)': '/__mock__/mockRealmObject' + '^(realm)': '/__mock__/mockRealmObject', + 'react-native-vector-icons/MaterialCommunityIcons': '/__mock__/mockMaterialIcons' }, transform: { '^.+\\.(ts|tsx)?$': 'ts-jest',