Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utils test #404

Merged
merged 11 commits into from
Dec 27, 2024
Merged
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ dependencies:
tutorial_coach_mark: ^1.2.11
url_launcher: ^6.1.14
uuid: ^4.2.2
built_collection: ^5.1.1

dev_dependencies:
build_runner: null
Expand Down
39 changes: 39 additions & 0 deletions test/utils/app_settings/app_settings_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:taskwarrior/app/utils/app_settings/app_settings.dart';
import 'package:taskwarrior/app/utils/language/supported_language.dart';

void main() {
group('AppSettings', () {
setUp(() async {
SharedPreferences.setMockInitialValues({});
await AppSettings.init();
});

test('should initialize settings correctly', () async {
expect(AppSettings.isDarkMode, true);
expect(AppSettings.selectedLanguage, SupportedLanguage.english);
});

test('should save settings correctly', () async {
await AppSettings.saveSettings(false, SupportedLanguage.english);
expect(AppSettings.isDarkMode, true);
expect(AppSettings.selectedLanguage, SupportedLanguage.english);
});
});

group('SelectedTheme', () {
setUp(() async {
SharedPreferences.setMockInitialValues({});
await SelectedTheme.init();
});

test('should save and retrieve theme mode correctly', () async {
await SelectedTheme.saveMode(false);
expect(SelectedTheme.getMode(), false);

await SelectedTheme.saveMode(true);
expect(SelectedTheme.getMode(), true);
});
});
}
61 changes: 61 additions & 0 deletions test/utils/app_settings/save_tour_status_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:taskwarrior/app/utils/app_settings/app_settings.dart';

void main() {
group('SaveTourStatus', () {
setUp(() async {
SharedPreferences.setMockInitialValues({});
await SaveTourStatus.init();
});

test('should save and retrieve reports tour status correctly', () async {
await SaveTourStatus.saveReportsTourStatus(true);
expect(await SaveTourStatus.getReportsTourStatus(), true);

await SaveTourStatus.saveReportsTourStatus(false);
expect(await SaveTourStatus.getReportsTourStatus(), false);
});

test('should save and retrieve in-app tour status correctly', () async {
await SaveTourStatus.saveInAppTourStatus(true);
expect(await SaveTourStatus.getInAppTourStatus(), true);

await SaveTourStatus.saveInAppTourStatus(false);
expect(await SaveTourStatus.getInAppTourStatus(), false);
});

test('should save and retrieve filter tour status correctly', () async {
await SaveTourStatus.saveFilterTourStatus(true);
expect(await SaveTourStatus.getFilterTourStatus(), true);

await SaveTourStatus.saveFilterTourStatus(false);
expect(await SaveTourStatus.getFilterTourStatus(), false);
});

test('should save and retrieve profile tour status correctly', () async {
await SaveTourStatus.saveProfileTourStatus(true);
expect(await SaveTourStatus.getProfileTourStatus(), true);

await SaveTourStatus.saveProfileTourStatus(false);
expect(await SaveTourStatus.getProfileTourStatus(), false);
});

test('should save and retrieve details tour status correctly', () async {
await SaveTourStatus.saveDetailsTourStatus(true);
expect(await SaveTourStatus.getDetailsTourStatus(), true);

await SaveTourStatus.saveDetailsTourStatus(false);
expect(await SaveTourStatus.getDetailsTourStatus(), false);
});

test('should save and retrieve manage task server tour status correctly',
() async {
await SaveTourStatus.saveManageTaskServerTourStatus(true);
expect(await SaveTourStatus.getManageTaskServerTourStatus(), true);

await SaveTourStatus.saveManageTaskServerTourStatus(false);
expect(await SaveTourStatus.getManageTaskServerTourStatus(), false);
});
});
}
21 changes: 21 additions & 0 deletions test/utils/app_settings/selected_language_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:taskwarrior/app/utils/app_settings/app_settings.dart';
import 'package:taskwarrior/app/utils/language/supported_language.dart';

void main() {
group('SelectedLanguage', () {
setUp(() async {
SharedPreferences.setMockInitialValues({});
await SelectedLanguage.init();
});

test('should save and retrieve selected language correctly', () async {
await SelectedLanguage.saveSelectedLanguage(SupportedLanguage.spanish);
expect(SelectedLanguage.getSelectedLanguage(), SupportedLanguage.spanish);

await SelectedLanguage.saveSelectedLanguage(SupportedLanguage.english);
expect(SelectedLanguage.getSelectedLanguage(), SupportedLanguage.english);
});
});
}
20 changes: 20 additions & 0 deletions test/utils/app_settings/selected_theme_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:taskwarrior/app/utils/app_settings/app_settings.dart';

void main() {
group('SelectedTheme', () {
setUp(() async {
SharedPreferences.setMockInitialValues({});
await SelectedTheme.init();
});

test('should save and retrieve theme mode correctly', () async {
await SelectedTheme.saveMode(false);
expect(SelectedTheme.getMode(), false);

await SelectedTheme.saveMode(true);
expect(SelectedTheme.getMode(), true);
});
});
}
26 changes: 26 additions & 0 deletions test/utils/constants/onboarding_screen_content_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:taskwarrior/app/utils/constants/onboarding_screen_content.dart';

void main() {
group('Onboarding Screen Content', () {
test('should contain three onboarding items', () {
expect(contents.length, 3);
});

test('should have valid content for each onboarding item', () {
for (var content in contents) {
expect(content.title.isNotEmpty, true);
expect(content.image.isNotEmpty, true);
expect(content.colors, isA<Color>());
expect(content.desc.isNotEmpty, true);
}
});

test('should match the expected titles', () {
expect(contents[0].title, "Welcome to Taskwarrior");
expect(contents[1].title, "Powerful Reporting");
expect(contents[2].title, "Sync Across Devices");
});
});
}
24 changes: 24 additions & 0 deletions test/utils/constants/pallette_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:taskwarrior/app/utils/constants/palette.dart';
import 'package:flutter/material.dart';

void main() {
group('Palette', () {
test('kToDark should be a MaterialColor', () {
expect(Palette.kToDark, isA<MaterialColor>());
});

test('kToDark should contain the correct color values', () {
expect(Palette.kToDark[50], const Color(0xff1e1e1e));
expect(Palette.kToDark[100], const Color(0xff1a1a1a));
expect(Palette.kToDark[200], const Color(0xff171717));
expect(Palette.kToDark[300], const Color(0xff141414));
expect(Palette.kToDark[400], const Color(0xff111111));
expect(Palette.kToDark[500], const Color(0xff0d0d0d));
expect(Palette.kToDark[600], const Color(0xff0a0a0a));
expect(Palette.kToDark[700], const Color(0xff070707));
expect(Palette.kToDark[800], const Color(0xff030303));
expect(Palette.kToDark[900], const Color(0xff000000));
});
});
}
15 changes: 15 additions & 0 deletions test/utils/constants/permissions_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:taskwarrior/app/utils/constants/permissions.dart';

void main() {
group('Permissions', () {
test('should contain the correct permissions', () {
expect(permissions, [
Permission.notification,
Permission.storage,
Permission.manageExternalStorage,
]);
});
});
}
47 changes: 47 additions & 0 deletions test/utils/constants/taskwarrior_colors_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:taskwarrior/app/utils/constants/palette.dart';
import 'package:taskwarrior/app/utils/constants/taskwarrior_colors.dart';

void main() {
group('TaskWarriorColors', () {
test('should contain the correct normal colors', () {
expect(TaskWarriorColors.red, Colors.red);
expect(TaskWarriorColors.green, Colors.green);
expect(TaskWarriorColors.yellow, Colors.yellow);
expect(TaskWarriorColors.white, Colors.white);
expect(TaskWarriorColors.black, Colors.black);
expect(TaskWarriorColors.grey, Colors.grey);
expect(TaskWarriorColors.lightGrey, Colors.grey[600]);
expect(TaskWarriorColors.purple, Colors.purple);
expect(TaskWarriorColors.borderColor, Colors.grey.shade300);
expect(TaskWarriorColors.deepPurpleAccent, Colors.deepPurpleAccent);
expect(TaskWarriorColors.deepPurple, Colors.deepPurple);
});

test('should contain the correct dark theme colors', () {
expect(
TaskWarriorColors.kprimaryBackgroundColor, Palette.kToDark.shade200);
expect(TaskWarriorColors.ksecondaryBackgroundColor,
const Color.fromARGB(255, 48, 46, 46));
expect(TaskWarriorColors.kprimaryTextColor, Colors.white);
expect(TaskWarriorColors.ksecondaryTextColor, Colors.white);
expect(
TaskWarriorColors.kprimaryDisabledTextColor, const Color(0xff595f6b));
expect(TaskWarriorColors.kdialogBackGroundColor,
const Color.fromARGB(255, 25, 25, 25));
});

test('should contain the correct light theme colors', () {
expect(TaskWarriorColors.kLightPrimaryBackgroundColor, Colors.white);
expect(TaskWarriorColors.kLightSecondaryBackgroundColor,
const Color.fromARGB(255, 220, 216, 216));
expect(TaskWarriorColors.kLightPrimaryTextColor, Colors.black);
expect(TaskWarriorColors.kLightSecondaryTextColor,
const Color.fromARGB(255, 48, 46, 46));
expect(TaskWarriorColors.kLightPrimaryDisabledTextColor,
const Color(0xffACACAB));
expect(TaskWarriorColors.kLightDialogBackGroundColor, Colors.white);
});
});
}
26 changes: 26 additions & 0 deletions test/utils/constants/taskwarrior_fonts_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:taskwarrior/app/utils/constants/taskwarrior_fonts.dart';

void main() {
group('TaskWarriorFonts', () {
test('should contain the correct font weights', () {
expect(TaskWarriorFonts.thin, FontWeight.w100);
expect(TaskWarriorFonts.extraLight, FontWeight.w200);
expect(TaskWarriorFonts.light, FontWeight.w300);
expect(TaskWarriorFonts.regular, FontWeight.w400);
expect(TaskWarriorFonts.medium, FontWeight.w500);
expect(TaskWarriorFonts.semiBold, FontWeight.w600);
expect(TaskWarriorFonts.bold, FontWeight.w700);
expect(TaskWarriorFonts.extraBold, FontWeight.w800);
expect(TaskWarriorFonts.black, FontWeight.w900);
});

test('should contain the correct font sizes', () {
expect(TaskWarriorFonts.fontSizeSmall, 12.0);
expect(TaskWarriorFonts.fontSizeMedium, 16.0);
expect(TaskWarriorFonts.fontSizeLarge, 20.0);
expect(TaskWarriorFonts.fontSizeExtraLarge, 24.0);
});
});
}
70 changes: 70 additions & 0 deletions test/utils/constants/utilities_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:taskwarrior/app/utils/constants/utilites.dart';

void main() {
group('Utils', () {
test('should return the correct week number as string', () {
DateTime date = DateTime(2024, 12, 15);
expect(Utils.getWeekNumber(date), '50');
});

test('should return the correct week number as integer', () {
DateTime date = DateTime(2024, 12, 15);
expect(Utils.getWeekNumbertoInt(date), 50);
});

test('should format date correctly', () {
DateTime date = DateTime(2024, 12, 15);
String pattern = 'yyyy-MM-dd';
expect(Utils.formatDate(date, pattern), '2024-12-15');
});

test('should return the correct month name', () {
expect(Utils.getMonthName(1), 'January');
expect(Utils.getMonthName(2), 'February');
expect(Utils.getMonthName(3), 'March');
expect(Utils.getMonthName(4), 'April');
expect(Utils.getMonthName(5), 'May');
expect(Utils.getMonthName(6), 'June');
expect(Utils.getMonthName(7), 'July');
expect(Utils.getMonthName(8), 'August');
expect(Utils.getMonthName(9), 'September');
expect(Utils.getMonthName(10), 'October');
expect(Utils.getMonthName(11), 'November');
expect(Utils.getMonthName(12), 'December');
expect(Utils.getMonthName(0), '');
});

testWidgets('should create an AlertDialog', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: Builder(
builder: (context) {
return ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return Utils.showAlertDialog(
title: const Text('Test Dialog'),
content: const Text('This is a test dialog'),
);
},
);
},
child: const Text('Show Dialog'),
);
},
),
),
));

await tester.tap(find.text('Show Dialog'));
await tester.pump();

expect(find.text('Test Dialog'), findsOneWidget);
expect(find.text('This is a test dialog'), findsOneWidget);
});
});
}
Loading
Loading