11import 'dart:convert' ;
2+ import 'dart:io' ;
23
34import 'package:flutter/services.dart' ;
45import 'package:flutter_test/flutter_test.dart' ;
@@ -24,10 +25,12 @@ void main() {
2425
2526 databaseFactory = databaseFactoryFfi;
2627 MockClient mockClient = MockClient ();
28+ late Directory docsDir;
2729
2830 setUpAll (() {
2931 sqfliteFfiInit ();
30-
32+ docsDir = Directory .systemTemp.createTempSync ('taskwarrior_test_docs_' );
33+
3134 // Mock SharedPreferences plugin
3235 const MethodChannel ('plugins.flutter.io/shared_preferences' )
3336 .setMockMethodCallHandler ((MethodCall methodCall) async {
@@ -36,6 +39,20 @@ void main() {
3639 }
3740 return null ;
3841 });
42+
43+ const MethodChannel ('plugins.flutter.io/path_provider' )
44+ .setMockMethodCallHandler ((MethodCall methodCall) async {
45+ if (methodCall.method == 'getApplicationDocumentsDirectory' ) {
46+ return docsDir.path;
47+ }
48+ return null ;
49+ });
50+ });
51+
52+ tearDownAll (() {
53+ if (docsDir.existsSync ()) {
54+ docsDir.deleteSync (recursive: true );
55+ }
3956 });
4057
4158 group ('Tasks model' , () {
@@ -191,5 +208,47 @@ void main() {
191208 // This will throw "Bad state: No element" when there are no tasks
192209 expect (() => taskDatabase.fetchTasksFromDatabase (), throwsStateError);
193210 });
211+
212+ test ('saveEditedTaskInDB updates description and tags together' , () async {
213+ final task = TaskForC (
214+ id: 7 ,
215+ description: 'Old description' ,
216+ project: 'Project 1' ,
217+ status: 'pending' ,
218+ uuid: 'edit-uuid' ,
219+ urgency: 5.0 ,
220+ priority: 'H' ,
221+ due: '2024-12-31' ,
222+ end: '' ,
223+ entry: '2024-01-01' ,
224+ modified: '2024-11-01' ,
225+ tags: ['old' ],
226+ start: '' ,
227+ wait: '' ,
228+ rtype: '' ,
229+ recur: '' ,
230+ depends: [],
231+ annotations: []);
232+
233+ await taskDatabase.insertTask (task);
234+
235+ await taskDatabase.saveEditedTaskInDB (
236+ 'edit-uuid' ,
237+ 'New description' ,
238+ 'Project 2' ,
239+ 'pending' ,
240+ 'M' ,
241+ '2025-01-01' ,
242+ ['new-a' , 'new-b' ],
243+ );
244+
245+ final edited = await taskDatabase.getTaskByUuid ('edit-uuid' );
246+ expect (edited, isNotNull);
247+ expect (edited! .description, 'New description' );
248+ expect (edited.project, 'Project 2' );
249+ expect (edited.priority, 'M' );
250+ expect (edited.due, '2025-01-01' );
251+ expect (edited.tags, unorderedEquals (['new-a' , 'new-b' ]));
252+ });
194253 });
195254}
0 commit comments