Skip to content

Commit f453e8f

Browse files
committed
Draft test added
1 parent 9de2bd3 commit f453e8f

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

test/taskfunctions/draft_test.dart

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:taskwarrior/app/models/models.dart';
3+
import 'package:taskwarrior/app/utils/taskfunctions/draft.dart';
4+
5+
void main() {
6+
group('Draft Tests', () {
7+
test('Setting status to completed updates end date', () {
8+
Task original = Task(
9+
(b) => b
10+
..id = 1
11+
..description = 'Task 1'
12+
..status = 'pending'
13+
..start = DateTime.utc(2023, 1, 1)
14+
..priority = 'H'
15+
..project = 'Project A'
16+
..tags.replace(['tag1', 'tag2'])
17+
..uuid = 'uuid1'
18+
..description = 'Task 1 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+
25+
Draft draft = Draft(original);
26+
27+
draft.set('status', 'completed');
28+
29+
expect(draft.draft.status, 'completed');
30+
31+
expect(draft.draft.end, isNotNull);
32+
});
33+
34+
test('Setting status to pending does not update end date', () {
35+
Task original = Task(
36+
(b) => b
37+
..id = 2
38+
..description = 'Task 2'
39+
..status = 'completed'
40+
..start = DateTime.utc(2023, 1, 1)
41+
..priority = 'H'
42+
..project = 'Project A'
43+
..tags.replace(['tag1', 'tag2'])
44+
..uuid = 'uuid2'
45+
..description = 'Task 2 Description'
46+
..entry = DateTime(2024, 7, 20)
47+
..modified = DateTime(2024, 7, 21)
48+
..start = DateTime(2024, 7, 22)
49+
..due = DateTime(2024, 7, 23),
50+
);
51+
52+
Draft draft = Draft(original);
53+
54+
draft.set('status', 'pending');
55+
56+
expect(draft.draft.status, 'pending');
57+
58+
expect(draft.draft.end, isNull);
59+
});
60+
61+
test('Setting other properties updates correctly', () {
62+
Task original = Task(
63+
(b) => b
64+
..id = 1
65+
..description = 'Task 3'
66+
..status = 'pending'
67+
..start = DateTime.utc(2023, 1, 1)
68+
..priority = 'H'
69+
..project = 'Project A'
70+
..tags.replace(['tag1', 'tag2'])
71+
..uuid = 'uuid3'
72+
..description = 'Task 3 Description'
73+
..entry = DateTime(2024, 7, 20)
74+
..modified = DateTime(2024, 7, 21)
75+
..start = DateTime(2024, 7, 22)
76+
..due = DateTime(2024, 7, 23),
77+
);
78+
79+
Draft draft = Draft(original);
80+
81+
draft.set('priority', 'L');
82+
83+
expect(draft.draft.priority, 'L');
84+
85+
expect(draft.draft.id, original.id);
86+
87+
expect(draft.draft.description, original.description);
88+
89+
expect(draft.draft.status, original.status);
90+
});
91+
});
92+
}

0 commit comments

Comments
 (0)