Skip to content

Commit e571ee9

Browse files
committed
test: added test for root files under lib/models directory
1 parent f474487 commit e571ee9

File tree

7 files changed

+399
-0
lines changed

7 files changed

+399
-0
lines changed

test/models/chart_test.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:taskwarrior/app/models/chart.dart';
3+
4+
void main() {
5+
group('ChartData', () {
6+
test('should create an instance with correct values', () {
7+
final chartData = ChartData('2024-12-12', 100, 200);
8+
9+
expect(chartData.x, '2024-12-12');
10+
expect(chartData.y1, 100);
11+
expect(chartData.y2, 200);
12+
});
13+
14+
test('should handle null or empty values correctly', () {
15+
final chartData = ChartData('', 0, 0);
16+
17+
expect(chartData.x, '');
18+
expect(chartData.y1, 0);
19+
expect(chartData.y2, 0);
20+
});
21+
22+
test('should handle negative values correctly', () {
23+
final chartData = ChartData('2024-12-12', -100, -200);
24+
25+
expect(chartData.x, '2024-12-12');
26+
expect(chartData.y1, -100);
27+
expect(chartData.y2, -200);
28+
});
29+
});
30+
}

test/models/data_test.dart

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:mockito/mockito.dart';
3+
import 'package:taskwarrior/app/models/data.dart';
4+
import 'package:taskwarrior/app/models/json/task.dart';
5+
import 'package:taskwarrior/app/services/notification_services.dart';
6+
import 'package:flutter/widgets.dart';
7+
import 'dart:io';
8+
9+
class MockNotificationService extends Mock implements NotificationService {}
10+
11+
void main() {
12+
TestWidgetsFlutterBinding.ensureInitialized();
13+
14+
group('Data', () {
15+
late Data data;
16+
late Directory home;
17+
late MockNotificationService mockNotificationService;
18+
19+
setUp(() {
20+
WidgetsFlutterBinding.ensureInitialized();
21+
home = Directory.systemTemp.createTempSync();
22+
data = Data(home);
23+
mockNotificationService = MockNotificationService();
24+
25+
when(mockNotificationService.initiliazeNotification())
26+
.thenAnswer((_) async {});
27+
});
28+
29+
test('should update tasks with status "waiting" or "until" correctly',
30+
() async {
31+
final task1 = Task((b) => b
32+
..uuid = '1'
33+
..status = 'pending'
34+
..wait = DateTime.now().toUtc().subtract(const Duration(days: 1))
35+
..description = 'Test Task'
36+
..entry = DateTime.now().toUtc());
37+
final task2 = Task((b) => b
38+
..uuid = '2'
39+
..status = 'deleted'
40+
..until = DateTime.now().toUtc().subtract(const Duration(days: 1))
41+
..description = 'Test Task'
42+
..entry = DateTime.now().toUtc());
43+
44+
final updatedTasks = data.pendingData();
45+
expect(
46+
updatedTasks.any(
47+
(task) => task.uuid == task1.uuid && task.status == task1.status),
48+
isFalse);
49+
expect(
50+
updatedTasks.any(
51+
(task) => task.uuid == task2.uuid && task.status == task2.status),
52+
isFalse);
53+
});
54+
55+
test('should correctly return pending data', () {
56+
final task = Task((b) => b
57+
..uuid = '1'
58+
..status = 'pending'
59+
..description = 'Test Task'
60+
..entry = DateTime.now().toUtc());
61+
62+
data.updateWaitOrUntil([task]);
63+
final tasks = data.pendingData();
64+
expect(tasks.any((t) => t.uuid == '1' && t.description == 'Test Task'),
65+
isFalse);
66+
});
67+
68+
test('should correctly return completed data', () {
69+
final task = Task((b) => b
70+
..uuid = '1'
71+
..status = 'completed'
72+
..description = 'Test Task'
73+
..entry = DateTime.now().toUtc());
74+
75+
data.updateWaitOrUntil([task]);
76+
final tasks = data.completedData();
77+
expect(tasks.any((t) => t.uuid == '1' && t.description == 'Test Task'),
78+
isFalse);
79+
});
80+
81+
test('should correctly return waiting data', () {
82+
final task = Task((b) => b
83+
..uuid = '1'
84+
..status = 'waiting'
85+
..description = 'Test Task'
86+
..entry = DateTime.now().toUtc());
87+
88+
data.updateWaitOrUntil([task]);
89+
final tasks = data.waitingData();
90+
expect(tasks.any((t) => t.uuid == '1' && t.description == 'Test Task'),
91+
isFalse);
92+
});
93+
94+
test('should correctly export data', () {
95+
final exportedData = data.export();
96+
expect(exportedData, isNotNull);
97+
});
98+
99+
tearDown(() {
100+
home.deleteSync(recursive: true);
101+
});
102+
});
103+
}

test/models/filters_test.dart

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:taskwarrior/app/models/filters.dart';
3+
import 'package:taskwarrior/app/services/tag_filter.dart';
4+
5+
void main() {
6+
group('Filters', () {
7+
late Filters filters;
8+
late bool pendingFilter;
9+
late bool waitingFilter;
10+
late String projectFilter;
11+
late bool tagUnion;
12+
late Map<String, TagFilterMetadata> tags;
13+
14+
setUp(() {
15+
pendingFilter = false;
16+
waitingFilter = false;
17+
projectFilter = 'TestProject';
18+
tagUnion = false;
19+
tags = {
20+
'tag1': const TagFilterMetadata(display: 'Tag 1', selected: false),
21+
'tag2': const TagFilterMetadata(display: 'Tag 2', selected: true),
22+
};
23+
24+
filters = Filters(
25+
pendingFilter: pendingFilter,
26+
waitingFilter: waitingFilter,
27+
togglePendingFilter: () {
28+
pendingFilter = !pendingFilter;
29+
},
30+
toggleWaitingFilter: () {
31+
waitingFilter = !waitingFilter;
32+
},
33+
tagFilters: TagFilters(
34+
tagUnion: tagUnion,
35+
toggleTagUnion: () {
36+
tagUnion = !tagUnion;
37+
},
38+
tags: tags,
39+
toggleTagFilter: (String tag) {
40+
tags[tag] = TagFilterMetadata(
41+
display: tags[tag]!.display,
42+
selected: !tags[tag]!.selected,
43+
);
44+
},
45+
),
46+
projects: [],
47+
projectFilter: projectFilter,
48+
toggleProjectFilter: (String project) {
49+
projectFilter = project;
50+
},
51+
);
52+
});
53+
54+
test('should correctly initialize with given parameters', () {
55+
expect(filters.pendingFilter, pendingFilter);
56+
expect(filters.waitingFilter, waitingFilter);
57+
expect(filters.projectFilter, projectFilter);
58+
expect(filters.tagFilters.tagUnion, tagUnion);
59+
expect(filters.tagFilters.tags, tags);
60+
});
61+
62+
test('should correctly toggle pending filter', () {
63+
filters.togglePendingFilter();
64+
expect(pendingFilter, isTrue);
65+
66+
filters.togglePendingFilter();
67+
expect(pendingFilter, isFalse);
68+
});
69+
70+
test('should correctly toggle waiting filter', () {
71+
filters.toggleWaitingFilter();
72+
expect(waitingFilter, isTrue);
73+
74+
filters.toggleWaitingFilter();
75+
expect(waitingFilter, isFalse);
76+
});
77+
78+
test('should correctly toggle project filter', () {
79+
const newProject = 'NewProject';
80+
filters.toggleProjectFilter(newProject);
81+
expect(projectFilter, newProject);
82+
83+
const anotherProject = 'AnotherProject';
84+
filters.toggleProjectFilter(anotherProject);
85+
expect(projectFilter, anotherProject);
86+
});
87+
88+
test('should correctly toggle tag union', () {
89+
filters.tagFilters.toggleTagUnion();
90+
expect(tagUnion, isTrue);
91+
92+
filters.tagFilters.toggleTagUnion();
93+
expect(tagUnion, isFalse);
94+
});
95+
96+
test('should correctly toggle tag filter', () {
97+
filters.tagFilters.toggleTagFilter('tag1');
98+
expect(tags['tag1']!.selected, isTrue);
99+
100+
filters.tagFilters.toggleTagFilter('tag1');
101+
expect(tags['tag1']!.selected, isFalse);
102+
});
103+
});
104+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:taskwarrior/app/models/onboarding_model.dart';
4+
5+
void main() {
6+
group('OnboardingModel', () {
7+
late OnboardingModel model;
8+
9+
setUp(() {
10+
model = OnboardingModel(
11+
title: 'Welcome',
12+
image: 'assets/images/welcome.png',
13+
desc: 'Welcome to the app!',
14+
colors: Colors.blue,
15+
);
16+
});
17+
18+
test('should correctly initialize with given parameters', () {
19+
expect(model.title, 'Welcome');
20+
expect(model.image, 'assets/images/welcome.png');
21+
expect(model.desc, 'Welcome to the app!');
22+
expect(model.colors, Colors.blue);
23+
});
24+
});
25+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:taskwarrior/app/models/size_config_model.dart';
4+
5+
void main() {
6+
group('SizeConfig', () {
7+
late SizeConfig sizeConfig;
8+
9+
setUp(() {
10+
sizeConfig = SizeConfig();
11+
});
12+
13+
testWidgets('should initialize screen dimensions correctly',
14+
(WidgetTester tester) async {
15+
await tester.pumpWidget(
16+
MaterialApp(
17+
home: Builder(
18+
builder: (BuildContext context) {
19+
sizeConfig.init(context);
20+
return Container();
21+
},
22+
),
23+
),
24+
);
25+
26+
final mediaQueryData =
27+
MediaQuery.of(tester.element(find.byType(Container)));
28+
29+
expect(sizeConfig.screenW, mediaQueryData.size.width);
30+
expect(sizeConfig.screenH, mediaQueryData.size.height);
31+
expect(sizeConfig.blockH, mediaQueryData.size.width / 100);
32+
expect(sizeConfig.blockV, mediaQueryData.size.height / 100);
33+
});
34+
});
35+
}

test/models/storage_test.dart

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import 'dart:io';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:taskwarrior/app/models/data.dart';
4+
import 'package:taskwarrior/app/models/storage.dart';
5+
import 'package:taskwarrior/app/models/storage/tabs.dart';
6+
import 'package:taskwarrior/app/utils/home_path/impl/gui_pem_file_paths.dart';
7+
import 'package:taskwarrior/app/utils/home_path/impl/home.dart';
8+
import 'package:taskwarrior/app/utils/home_path/impl/taskrc.dart';
9+
import 'package:taskwarrior/app/utils/taskfunctions/query.dart';
10+
11+
void main() {
12+
group('Storage', () {
13+
late Directory profile;
14+
late Storage storage;
15+
16+
setUp(() {
17+
profile = Directory.systemTemp.createTempSync();
18+
storage = Storage(profile);
19+
});
20+
21+
tearDown(() {
22+
profile.deleteSync(recursive: true);
23+
});
24+
25+
test('should correctly initialize with given directory', () {
26+
expect(storage.profile, profile);
27+
});
28+
29+
test('should correctly initialize Data with profile directory', () {
30+
expect(storage.data, isA<Data>());
31+
expect(storage.profile, profile);
32+
});
33+
34+
test('should correctly initialize GUIPemFiles with profile directory', () {
35+
expect(storage.guiPemFiles, isA<GUIPemFiles>());
36+
expect(storage.profile, profile);
37+
});
38+
39+
test('should correctly initialize Home with profile directory', () {
40+
expect(storage.home, isA<Home>());
41+
expect(storage.home.home, profile);
42+
expect(
43+
storage.home.pemFilePaths?.key, storage.guiPemFiles.pemFilePaths.key);
44+
});
45+
46+
test('should correctly initialize Query with profile directory', () {
47+
expect(storage.query, isA<Query>());
48+
expect(storage.profile, profile);
49+
});
50+
51+
test('should correctly initialize Tabs with profile directory', () {
52+
expect(storage.tabs, isA<Tabs>());
53+
expect(storage.tabs.profile, profile);
54+
});
55+
56+
test('should correctly initialize Taskrc with profile directory', () {
57+
expect(storage.taskrc, isA<Taskrc>());
58+
expect(storage.profile, profile);
59+
});
60+
});
61+
}

0 commit comments

Comments
 (0)