|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:taskwarrior/app/models/models.dart'; |
| 3 | +import 'package:taskwarrior/app/utils/taskfunctions/patch.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + group('patch function', () { |
| 7 | + test('should patch description', () { |
| 8 | + Task initialTask = Task( |
| 9 | + (b) => b |
| 10 | + ..id = 1 |
| 11 | + ..description = 'Task 3' |
| 12 | + ..status = 'pending' |
| 13 | + ..start = DateTime.utc(2023, 1, 1) |
| 14 | + ..priority = 'H' |
| 15 | + ..project = 'Project A' |
| 16 | + ..tags.replace(['tag1', 'tag2']) |
| 17 | + ..uuid = 'uuid3' |
| 18 | + ..description = 'Task 3 Description' |
| 19 | + ..entry = DateTime(2024, 7, 20) |
| 20 | + ..modified = DateTime(2024, 7, 21) |
| 21 | + ..start = DateTime(2024, 7, 22) |
| 22 | + ..due = DateTime(2024, 7, 23), |
| 23 | + ); |
| 24 | + Map<String, dynamic> updates = {'description': 'Updated description'}; |
| 25 | + |
| 26 | + Task patchedTask = patch(initialTask, updates); |
| 27 | + |
| 28 | + expect(patchedTask.description, 'Updated description'); |
| 29 | + }); |
| 30 | + |
| 31 | + test('should handle unknown keys gracefully', () { |
| 32 | + Task initialTask = Task( |
| 33 | + (b) => b |
| 34 | + ..id = 1 |
| 35 | + ..description = 'Task 3' |
| 36 | + ..status = 'pending' |
| 37 | + ..start = DateTime.utc(2023, 1, 1) |
| 38 | + ..priority = 'H' |
| 39 | + ..project = 'Project A' |
| 40 | + ..tags.replace(['tag1', 'tag2']) |
| 41 | + ..uuid = 'uuid3' |
| 42 | + ..description = 'Task 3 Description' |
| 43 | + ..entry = DateTime(2024, 7, 20) |
| 44 | + ..modified = DateTime(2024, 7, 21) |
| 45 | + ..start = DateTime(2024, 7, 22) |
| 46 | + ..due = DateTime(2024, 7, 23), |
| 47 | + ); |
| 48 | + Map<String, dynamic> updates = {'unknownField': 'some value'}; |
| 49 | + |
| 50 | + Task patchedTask = patch(initialTask, updates); |
| 51 | + |
| 52 | + expect(patchedTask, initialTask); |
| 53 | + }); |
| 54 | + }); |
| 55 | +} |
0 commit comments