|
1 | 1 | import $ from 'jquery'; |
2 | 2 | import ArrayStore from 'common/data/array_store'; |
| 3 | +import Guid from 'core/guid'; |
3 | 4 | import config from 'core/config'; |
4 | 5 | import ErrorHandlingHelper from '../../helpers/data.errorHandlingHelper.js'; |
5 | 6 |
|
@@ -1115,6 +1116,45 @@ QUnit.test('prevent passing data as non-array', function(assert) { |
1115 | 1116 | }); |
1116 | 1117 | }); |
1117 | 1118 |
|
| 1119 | +QUnit.module('Push changes'); |
| 1120 | + |
| 1121 | +QUnit.test('push update preserves custom object instances inside arrays', function(assert) { |
| 1122 | + function createPerson(id, name) { |
| 1123 | + return { |
| 1124 | + id, |
| 1125 | + name, |
| 1126 | + guidArray: [new Guid(), new Guid(), new Guid()] |
| 1127 | + }; |
| 1128 | + } |
| 1129 | + |
| 1130 | + const guidPerson1 = new Guid(); |
| 1131 | + const guidPerson2 = new Guid(); |
| 1132 | + const person1 = createPerson(guidPerson1, 'Paul'); |
| 1133 | + const person2 = createPerson(guidPerson2, 'George'); |
| 1134 | + |
| 1135 | + const store = new ArrayStore({ |
| 1136 | + key: 'id', |
| 1137 | + data: [person1, person2] |
| 1138 | + }); |
| 1139 | + |
| 1140 | + const originalGuidArray = store.createQuery().toArray()[0].guidArray; |
| 1141 | + assert.ok(originalGuidArray[0] instanceof Guid, 'Guid instance is preserved before push'); |
| 1142 | + |
| 1143 | + person1.name = 'Will'; |
| 1144 | + store.push([{ type: 'update', key: guidPerson1, data: person1 }]); |
| 1145 | + |
| 1146 | + const updatedPerson = store.createQuery().toArray().find(item => item.id === guidPerson1); |
| 1147 | + assert.ok(updatedPerson, 'updated person is found'); |
| 1148 | + const updatedGuidArray = updatedPerson.guidArray; |
| 1149 | + |
| 1150 | + assert.strictEqual(updatedGuidArray.length, originalGuidArray.length, 'array length remains the same'); |
| 1151 | + updatedGuidArray.forEach((guidInstance, index) => { |
| 1152 | + assert.ok(guidInstance instanceof Guid, `item ${index} keeps Guid type after push`); |
| 1153 | + assert.strictEqual(guidInstance.toString(), originalGuidArray[index].toString(), 'Guid value is preserved'); |
| 1154 | + }); |
| 1155 | + assert.equal(updatedPerson.name, 'Will', 'person data is updated'); |
| 1156 | +}); |
| 1157 | + |
1118 | 1158 | QUnit.module('Error handling'); |
1119 | 1159 |
|
1120 | 1160 | QUnit.test('error in during query evaluation', function(assert) { |
|
0 commit comments