diff --git a/tests/js/async-tests.js b/tests/js/async-tests.js index 31fb0e53..d3a40ec8 100644 --- a/tests/js/async-tests.js +++ b/tests/js/async-tests.js @@ -84,6 +84,20 @@ function createCollectionChangeTest(config, createCollection, messages, expected ); }; +const ListObject = { + name: 'ListObject', + properties: { + list: {type: 'list', objectType: 'TestObject'}, + } +}; + +const PrimaryListObject = { + name: 'PrimaryListObject', + properties: { + list: {type: 'list', objectType: 'IntPrimaryObject'}, + } +}; + module.exports = { testChangeNotifications() { var config = { schema: [schemas.TestObject] }; @@ -166,21 +180,13 @@ module.exports = { }, testListAddNotifications() { - let ListObject = { - name: 'ListObject', - primaryKey: 'id', - properties: { - id: 'int', - list: {type: 'list', objectType: 'TestObject'}, - } - }; var config = { schema: [schemas.TestObject, ListObject] }; return createCollectionChangeTest( config, function(realm) { let listObject; realm.write(() => { - listObject = realm.create('ListObject', {id: 0, list: []}) + listObject = realm.create('ListObject', {list: []}) }); return listObject.list; }, @@ -193,4 +199,67 @@ module.exports = { ] ); }, + + testListDeleteNotifications() { + var config = { schema: [schemas.TestObject, ListObject] }; + return createCollectionChangeTest( + config, + function(realm) { + let listObject; + realm.write(() => { + listObject = realm.create('ListObject', {list: [[0], [1], [2]]}) + }); + return listObject.list; + }, + [ + [config, 'list_method', 'ListObject', 'list', 'splice', 1, 2] + ], + [ + [[], [], []], + [[], [1, 2], []] + ] + ); + }, + + testListSpliceNotifications() { + var config = { schema: [schemas.TestObject, ListObject] }; + return createCollectionChangeTest( + config, + function(realm) { + let listObject; + realm.write(() => { + listObject = realm.create('ListObject', {list: [[0], [1], [2]]}) + }); + return listObject.list; + }, + [ + [config, 'list_method', 'ListObject', 'list', 'splice', 1, 1, [2]] + ], + [ + [[], [], []], + [[1], [1], []] + ] + ); + }, + + testListUpdateNotifications() { + var config = { schema: [schemas.IntPrimary, PrimaryListObject] }; + return createCollectionChangeTest( + config, + function(realm) { + let listObject; + realm.write(() => { + listObject = realm.create('PrimaryListObject', {list: [[0, '0'], [1, '1']]}) + }); + return listObject.list; + }, + [ + [config, 'update', 'IntPrimaryObject', [[1, '11']]] + ], + [ + [[], [], []], + [[], [], [1]] + ] + ); + }, };