Skip to content

Commit baa71ab

Browse files
committed
test
1 parent 5e28522 commit baa71ab

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/dart/test/src/objects/parse_object/parse_object_array_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,27 @@ void main() {
662662
expect(listValue, orderedEquals([1, 2]));
663663
});
664664

665+
test('Arrays should not be cleared when calling clearUnsavedChanges() '
666+
'after fetching/querying without save', () {
667+
// arrange - Simulate a fetch/query response (no prior save operation)
668+
dietPlansObject.fromJson({
669+
keyArray: [1, 2, 3],
670+
"objectId": "someId",
671+
}); // assume this coming from the server via fetch/query
672+
673+
// Simulate what happens in _handleSingleResult for fetch/query
674+
// (calls _notifyChildrenAboutSave without prior _notifyChildrenAboutSaving)
675+
// This reproduces the bug where arrays were incorrectly cleared
676+
dietPlansObject._notifyChildrenAboutSave();
677+
678+
// act - this should NOT clear the arrays
679+
dietPlansObject.clearUnsavedChanges();
680+
681+
// assert - arrays should still have their values
682+
final listValue = dietPlansObject.get(keyArray);
683+
expect(listValue, orderedEquals([1, 2, 3]));
684+
});
685+
665686
test('The list value and the value for api request should be identical '
666687
'before and after the save() failed to save the object', () async {
667688
// arrange

0 commit comments

Comments
 (0)