Skip to content

Commit 817695b

Browse files
committed
tags testcases added
1 parent 5eb6a6f commit 817695b

File tree

1 file changed

+318
-0
lines changed

1 file changed

+318
-0
lines changed

test/taskfunctions/tags_test.dart

Lines changed: 318 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,318 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:taskwarrior/app/models/models.dart';
3+
import 'package:taskwarrior/app/utils/taskfunctions/tags.dart';
4+
5+
void main() {
6+
group('tagSet', () {
7+
test('should return all unique tags from tasks', () {
8+
final tasks = [
9+
Task((b) => b
10+
..id = 1
11+
..description = 'Task 1'
12+
..status = 'pending'
13+
..tags.replace(['tag1', 'tag2'])
14+
..start = DateTime.now()
15+
..entry = DateTime.now()
16+
..modified = DateTime.now()
17+
..due = DateTime.now()
18+
..project = 'Project A'
19+
..uuid = 'uuid1'),
20+
Task((b) => b
21+
..id = 2
22+
..description = 'Task 2'
23+
..status = 'pending'
24+
..tags.replace(['tag2', 'tag3'])
25+
..start = DateTime.now()
26+
..entry = DateTime.now()
27+
..modified = DateTime.now()
28+
..due = DateTime.now()
29+
..project = 'Project B'
30+
..uuid = 'uuid2'),
31+
];
32+
33+
final result = tagSet(tasks);
34+
expect(result, {'tag1', 'tag2', 'tag3'});
35+
});
36+
37+
test('should return an empty set if no tasks', () {
38+
final tasks = <Task>[];
39+
40+
final result = tagSet(tasks);
41+
expect(result, <String>{});
42+
});
43+
44+
test('should return an empty set if tasks have no tags', () {
45+
final tasks = [
46+
Task((b) => b
47+
..id = 1
48+
..description = 'Task 1'
49+
..status = 'pending'
50+
..start = DateTime.now()
51+
..entry = DateTime.now()
52+
..modified = DateTime.now()
53+
..due = DateTime.now()
54+
..project = 'Project A'
55+
..uuid = 'uuid1'),
56+
Task((b) => b
57+
..id = 2
58+
..description = 'Task 2'
59+
..status = 'pending'
60+
..start = DateTime.now()
61+
..entry = DateTime.now()
62+
..modified = DateTime.now()
63+
..due = DateTime.now()
64+
..project = 'Project B'
65+
..uuid = 'uuid2'),
66+
];
67+
68+
final result = tagSet(tasks);
69+
expect(result, <String>{});
70+
});
71+
});
72+
73+
group('tagFrequencies', () {
74+
test('should count the frequency of each tag correctly', () {
75+
final tasks = [
76+
Task((b) => b
77+
..id = 1
78+
..description = 'Task 1'
79+
..status = 'pending'
80+
..tags.replace(['tag1', 'tag2'])
81+
..start = DateTime.now()
82+
..entry = DateTime.now()
83+
..modified = DateTime.now()
84+
..due = DateTime.now()
85+
..project = 'Project A'
86+
..uuid = 'uuid1'),
87+
Task((b) => b
88+
..id = 2
89+
..description = 'Task 2'
90+
..status = 'pending'
91+
..tags.replace(['tag2', 'tag3'])
92+
..start = DateTime.now()
93+
..entry = DateTime.now()
94+
..modified = DateTime.now()
95+
..due = DateTime.now()
96+
..project = 'Project B'
97+
..uuid = 'uuid2'),
98+
Task((b) => b
99+
..id = 3
100+
..description = 'Task 3'
101+
..status = 'pending'
102+
..tags.replace(['tag2'])
103+
..start = DateTime.now()
104+
..entry = DateTime.now()
105+
..modified = DateTime.now()
106+
..due = DateTime.now()
107+
..project = 'Project C'
108+
..uuid = 'uuid3'),
109+
];
110+
111+
final result = tagFrequencies(tasks);
112+
expect(result, {'tag1': 1, 'tag2': 3, 'tag3': 1});
113+
});
114+
115+
test('should return an empty map if no tasks', () {
116+
final tasks = <Task>[];
117+
118+
final result = tagFrequencies(tasks);
119+
expect(result, <String, int>{});
120+
});
121+
122+
test('should return an empty map if tasks have no tags', () {
123+
final tasks = [
124+
Task((b) => b
125+
..id = 1
126+
..description = 'Task 1'
127+
..status = 'pending'
128+
..start = DateTime.now()
129+
..entry = DateTime.now()
130+
..modified = DateTime.now()
131+
..due = DateTime.now()
132+
..project = 'Project A'
133+
..uuid = 'uuid1'),
134+
Task((b) => b
135+
..id = 2
136+
..description = 'Task 2'
137+
..status = 'pending'
138+
..start = DateTime.now()
139+
..entry = DateTime.now()
140+
..modified = DateTime.now()
141+
..due = DateTime.now()
142+
..project = 'Project B'
143+
..uuid = 'uuid2'),
144+
];
145+
146+
final result = tagFrequencies(tasks);
147+
expect(result, <String, int>{});
148+
});
149+
150+
test('should count tags correctly with overlapping tasks', () {
151+
final tasks = [
152+
Task((b) => b
153+
..id = 1
154+
..description = 'Task 1'
155+
..status = 'pending'
156+
..tags.replace(['tag1', 'tag2'])
157+
..start = DateTime.now()
158+
..entry = DateTime.now()
159+
..modified = DateTime.now()
160+
..due = DateTime.now()
161+
..project = 'Project A'
162+
..uuid = 'uuid1'),
163+
Task((b) => b
164+
..id = 2
165+
..description = 'Task 2'
166+
..status = 'pending'
167+
..tags.replace(['tag1', 'tag2', 'tag3'])
168+
..start = DateTime.now()
169+
..entry = DateTime.now()
170+
..modified = DateTime.now()
171+
..due = DateTime.now()
172+
..project = 'Project B'
173+
..uuid = 'uuid2'),
174+
Task((b) => b
175+
..id = 3
176+
..description = 'Task 3'
177+
..status = 'pending'
178+
..tags.replace(['tag2', 'tag3'])
179+
..start = DateTime.now()
180+
..entry = DateTime.now()
181+
..modified = DateTime.now()
182+
..due = DateTime.now()
183+
..project = 'Project C'
184+
..uuid = 'uuid3'),
185+
];
186+
187+
final result = tagFrequencies(tasks);
188+
expect(result, {'tag1': 2, 'tag2': 3, 'tag3': 2});
189+
});
190+
});
191+
192+
group('tagsLastModified', () {
193+
test('should return the latest modification date for each tag', () {
194+
final tasks = [
195+
Task((b) => b
196+
..id = 1
197+
..description = 'Task 1'
198+
..status = 'pending'
199+
..tags.replace(['tag1'])
200+
..modified = DateTime.utc(2024, 1, 1)
201+
..start = DateTime.now()
202+
..entry = DateTime.now()
203+
..due = DateTime.now()
204+
..project = 'Project A'
205+
..uuid = 'uuid1'),
206+
Task((b) => b
207+
..id = 2
208+
..description = 'Task 2'
209+
..status = 'pending'
210+
..tags.replace(['tag2'])
211+
..modified = DateTime.utc(2024, 2, 1)
212+
..start = DateTime.now()
213+
..entry = DateTime.now()
214+
..due = DateTime.now()
215+
..project = 'Project B'
216+
..uuid = 'uuid2'),
217+
Task((b) => b
218+
..id = 3
219+
..description = 'Task 3'
220+
..status = 'pending'
221+
..tags.replace(['tag1', 'tag3'])
222+
..modified = DateTime.utc(2024, 3, 1)
223+
..start = DateTime.now()
224+
..entry = DateTime.now()
225+
..due = DateTime.now()
226+
..project = 'Project C'
227+
..uuid = 'uuid3'),
228+
];
229+
230+
final result = tagsLastModified(tasks);
231+
expect(result, {
232+
'tag1': DateTime.utc(2024, 3, 1),
233+
'tag2': DateTime.utc(2024, 2, 1),
234+
'tag3': DateTime.utc(2024, 3, 1),
235+
});
236+
});
237+
238+
test('should return an empty map if no tasks', () {
239+
final tasks = <Task>[];
240+
241+
final result = tagsLastModified(tasks);
242+
expect(result, <String, DateTime>{});
243+
});
244+
245+
test('should return an empty map if tasks have no tags', () {
246+
final tasks = [
247+
Task((b) => b
248+
..id = 1
249+
..description = 'Task 1'
250+
..status = 'pending'
251+
..start = DateTime.now()
252+
..entry = DateTime.now()
253+
..modified = DateTime.now()
254+
..due = DateTime.now()
255+
..project = 'Project A'
256+
..uuid = 'uuid1'),
257+
Task((b) => b
258+
..id = 2
259+
..description = 'Task 2'
260+
..status = 'pending'
261+
..start = DateTime.now()
262+
..entry = DateTime.now()
263+
..modified = DateTime.now()
264+
..due = DateTime.now()
265+
..project = 'Project B'
266+
..uuid = 'uuid2'),
267+
];
268+
269+
final result = tagsLastModified(tasks);
270+
expect(result, <String, DateTime>{});
271+
});
272+
273+
test('should return correct modification dates with overlapping tags', () {
274+
final tasks = [
275+
Task((b) => b
276+
..id = 1
277+
..description = 'Task 1'
278+
..status = 'pending'
279+
..tags.replace(['tag1', 'tag2'])
280+
..modified = DateTime.utc(2024, 1, 1)
281+
..start = DateTime.now()
282+
..entry = DateTime.now()
283+
..due = DateTime.now()
284+
..project = 'Project A'
285+
..uuid = 'uuid1'),
286+
Task((b) => b
287+
..id = 2
288+
..description = 'Task 2'
289+
..status = 'pending'
290+
..tags.replace(['tag2', 'tag3'])
291+
..modified = DateTime.utc(2024, 2, 1)
292+
..start = DateTime.now()
293+
..entry = DateTime.now()
294+
..due = DateTime.now()
295+
..project = 'Project B'
296+
..uuid = 'uuid2'),
297+
Task((b) => b
298+
..id = 3
299+
..description = 'Task 3'
300+
..status = 'pending'
301+
..tags.replace(['tag3'])
302+
..modified = DateTime.utc(2024, 3, 1)
303+
..start = DateTime.now()
304+
..entry = DateTime.now()
305+
..due = DateTime.now()
306+
..project = 'Project C'
307+
..uuid = 'uuid3'),
308+
];
309+
310+
final result = tagsLastModified(tasks);
311+
expect(result, {
312+
'tag1': DateTime.utc(2024, 1, 1),
313+
'tag2': DateTime.utc(2024, 2, 1),
314+
'tag3': DateTime.utc(2024, 3, 1),
315+
});
316+
});
317+
});
318+
}

0 commit comments

Comments
 (0)