test for list item update and deletions

This commit is contained in:
Ari Lazier 2016-08-03 09:27:20 -07:00
parent 5916936db4
commit 4e16075d1e
1 changed files with 78 additions and 9 deletions

View File

@ -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]]
]
);
},
};