Skip to content

Commit ab77c2a

Browse files
committed
test: added test for all files under utils/constants
1 parent 13086e4 commit ab77c2a

File tree

6 files changed

+208
-0
lines changed

6 files changed

+208
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:taskwarrior/app/utils/constants/onboarding_screen_content.dart';
4+
5+
void main() {
6+
group('Onboarding Screen Content', () {
7+
test('should contain three onboarding items', () {
8+
expect(contents.length, 3);
9+
});
10+
11+
test('should have valid content for each onboarding item', () {
12+
for (var content in contents) {
13+
expect(content.title.isNotEmpty, true);
14+
expect(content.image.isNotEmpty, true);
15+
expect(content.colors, isA<Color>());
16+
expect(content.desc.isNotEmpty, true);
17+
}
18+
});
19+
20+
test('should match the expected titles', () {
21+
expect(contents[0].title, "Welcome to Taskwarrior");
22+
expect(contents[1].title, "Powerful Reporting");
23+
expect(contents[2].title, "Sync Across Devices");
24+
});
25+
});
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:taskwarrior/app/utils/constants/palette.dart';
3+
import 'package:flutter/material.dart';
4+
5+
void main() {
6+
group('Palette', () {
7+
test('kToDark should be a MaterialColor', () {
8+
expect(Palette.kToDark, isA<MaterialColor>());
9+
});
10+
11+
test('kToDark should contain the correct color values', () {
12+
expect(Palette.kToDark[50], const Color(0xff1e1e1e));
13+
expect(Palette.kToDark[100], const Color(0xff1a1a1a));
14+
expect(Palette.kToDark[200], const Color(0xff171717));
15+
expect(Palette.kToDark[300], const Color(0xff141414));
16+
expect(Palette.kToDark[400], const Color(0xff111111));
17+
expect(Palette.kToDark[500], const Color(0xff0d0d0d));
18+
expect(Palette.kToDark[600], const Color(0xff0a0a0a));
19+
expect(Palette.kToDark[700], const Color(0xff070707));
20+
expect(Palette.kToDark[800], const Color(0xff030303));
21+
expect(Palette.kToDark[900], const Color(0xff000000));
22+
});
23+
});
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:permission_handler/permission_handler.dart';
3+
import 'package:taskwarrior/app/utils/constants/permissions.dart';
4+
5+
void main() {
6+
group('Permissions', () {
7+
test('should contain the correct permissions', () {
8+
expect(permissions, [
9+
Permission.notification,
10+
Permission.storage,
11+
Permission.manageExternalStorage,
12+
]);
13+
});
14+
});
15+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:taskwarrior/app/utils/constants/palette.dart';
4+
import 'package:taskwarrior/app/utils/constants/taskwarrior_colors.dart';
5+
6+
void main() {
7+
group('TaskWarriorColors', () {
8+
test('should contain the correct normal colors', () {
9+
expect(TaskWarriorColors.red, Colors.red);
10+
expect(TaskWarriorColors.green, Colors.green);
11+
expect(TaskWarriorColors.yellow, Colors.yellow);
12+
expect(TaskWarriorColors.white, Colors.white);
13+
expect(TaskWarriorColors.black, Colors.black);
14+
expect(TaskWarriorColors.grey, Colors.grey);
15+
expect(TaskWarriorColors.lightGrey, Colors.grey[600]);
16+
expect(TaskWarriorColors.purple, Colors.purple);
17+
expect(TaskWarriorColors.borderColor, Colors.grey.shade300);
18+
expect(TaskWarriorColors.deepPurpleAccent, Colors.deepPurpleAccent);
19+
expect(TaskWarriorColors.deepPurple, Colors.deepPurple);
20+
});
21+
22+
test('should contain the correct dark theme colors', () {
23+
expect(
24+
TaskWarriorColors.kprimaryBackgroundColor, Palette.kToDark.shade200);
25+
expect(TaskWarriorColors.ksecondaryBackgroundColor,
26+
const Color.fromARGB(255, 48, 46, 46));
27+
expect(TaskWarriorColors.kprimaryTextColor, Colors.white);
28+
expect(TaskWarriorColors.ksecondaryTextColor, Colors.white);
29+
expect(
30+
TaskWarriorColors.kprimaryDisabledTextColor, const Color(0xff595f6b));
31+
expect(TaskWarriorColors.kdialogBackGroundColor,
32+
const Color.fromARGB(255, 25, 25, 25));
33+
});
34+
35+
test('should contain the correct light theme colors', () {
36+
expect(TaskWarriorColors.kLightPrimaryBackgroundColor, Colors.white);
37+
expect(TaskWarriorColors.kLightSecondaryBackgroundColor,
38+
const Color.fromARGB(255, 220, 216, 216));
39+
expect(TaskWarriorColors.kLightPrimaryTextColor, Colors.black);
40+
expect(TaskWarriorColors.kLightSecondaryTextColor,
41+
const Color.fromARGB(255, 48, 46, 46));
42+
expect(TaskWarriorColors.kLightPrimaryDisabledTextColor,
43+
const Color(0xffACACAB));
44+
expect(TaskWarriorColors.kLightDialogBackGroundColor, Colors.white);
45+
});
46+
});
47+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:taskwarrior/app/utils/constants/taskwarrior_fonts.dart';
4+
5+
void main() {
6+
group('TaskWarriorFonts', () {
7+
test('should contain the correct font weights', () {
8+
expect(TaskWarriorFonts.thin, FontWeight.w100);
9+
expect(TaskWarriorFonts.extraLight, FontWeight.w200);
10+
expect(TaskWarriorFonts.light, FontWeight.w300);
11+
expect(TaskWarriorFonts.regular, FontWeight.w400);
12+
expect(TaskWarriorFonts.medium, FontWeight.w500);
13+
expect(TaskWarriorFonts.semiBold, FontWeight.w600);
14+
expect(TaskWarriorFonts.bold, FontWeight.w700);
15+
expect(TaskWarriorFonts.extraBold, FontWeight.w800);
16+
expect(TaskWarriorFonts.black, FontWeight.w900);
17+
});
18+
19+
test('should contain the correct font sizes', () {
20+
expect(TaskWarriorFonts.fontSizeSmall, 12.0);
21+
expect(TaskWarriorFonts.fontSizeMedium, 16.0);
22+
expect(TaskWarriorFonts.fontSizeLarge, 20.0);
23+
expect(TaskWarriorFonts.fontSizeExtraLarge, 24.0);
24+
});
25+
});
26+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:taskwarrior/app/utils/constants/utilites.dart';
4+
5+
void main() {
6+
group('Utils', () {
7+
test('should return the correct week number as string', () {
8+
DateTime date = DateTime(2024, 12, 15);
9+
expect(Utils.getWeekNumber(date), '50');
10+
});
11+
12+
test('should return the correct week number as integer', () {
13+
DateTime date = DateTime(2024, 12, 15);
14+
expect(Utils.getWeekNumbertoInt(date), 50);
15+
});
16+
17+
test('should format date correctly', () {
18+
DateTime date = DateTime(2024, 12, 15);
19+
String pattern = 'yyyy-MM-dd';
20+
expect(Utils.formatDate(date, pattern), '2024-12-15');
21+
});
22+
23+
test('should return the correct month name', () {
24+
expect(Utils.getMonthName(1), 'January');
25+
expect(Utils.getMonthName(2), 'February');
26+
expect(Utils.getMonthName(3), 'March');
27+
expect(Utils.getMonthName(4), 'April');
28+
expect(Utils.getMonthName(5), 'May');
29+
expect(Utils.getMonthName(6), 'June');
30+
expect(Utils.getMonthName(7), 'July');
31+
expect(Utils.getMonthName(8), 'August');
32+
expect(Utils.getMonthName(9), 'September');
33+
expect(Utils.getMonthName(10), 'October');
34+
expect(Utils.getMonthName(11), 'November');
35+
expect(Utils.getMonthName(12), 'December');
36+
expect(Utils.getMonthName(0), '');
37+
});
38+
39+
testWidgets('should create an AlertDialog', (WidgetTester tester) async {
40+
await tester.pumpWidget(MaterialApp(
41+
home: Scaffold(
42+
body: Builder(
43+
builder: (context) {
44+
return ElevatedButton(
45+
onPressed: () {
46+
showDialog(
47+
context: context,
48+
builder: (BuildContext context) {
49+
return Utils.showAlertDialog(
50+
title: const Text('Test Dialog'),
51+
content: const Text('This is a test dialog'),
52+
);
53+
},
54+
);
55+
},
56+
child: const Text('Show Dialog'),
57+
);
58+
},
59+
),
60+
),
61+
));
62+
63+
await tester.tap(find.text('Show Dialog'));
64+
await tester.pump();
65+
66+
expect(find.text('Test Dialog'), findsOneWidget);
67+
expect(find.text('This is a test dialog'), findsOneWidget);
68+
});
69+
});
70+
}

0 commit comments

Comments
 (0)