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

Taskfunctions test #361

Merged
merged 12 commits into from
Aug 27, 2024
98 changes: 97 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.1"
coverage:
dependency: transitive
description:
name: coverage
sha256: "3945034e86ea203af7a056d98e98e42a5518fff200d6e8e6647e1886b07e936e"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
cross_file:
dependency: transitive
description:
Expand Down Expand Up @@ -503,7 +511,7 @@ packages:
source: hosted
version: "2.0.9"
flutter_test:
dependency: "direct dev"
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
Expand All @@ -528,6 +536,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.6.6"
get_test:
dependency: "direct main"
description:
name: get_test
sha256: "558c39cb35fb37bd501f337dc143de60a4314d5ef3b75f4b0551d6741634995b"
url: "https://pub.dev"
source: hosted
version: "4.0.1"
glob:
dependency: transitive
description:
Expand Down Expand Up @@ -760,6 +776,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.4"
mockito:
dependency: "direct main"
description:
name: mockito
sha256: "6841eed20a7befac0ce07df8116c8b8233ed1f4486a7647c7fc5a02ae6163917"
url: "https://pub.dev"
source: hosted
version: "5.4.4"
nm:
dependency: transitive
description:
Expand All @@ -768,6 +792,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.5.0"
node_preamble:
dependency: transitive
description:
name: node_preamble
sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db"
url: "https://pub.dev"
source: hosted
version: "2.0.2"
package_config:
dependency: transitive
description:
Expand Down Expand Up @@ -1037,6 +1069,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.4.1"
shelf_packages_handler:
dependency: transitive
description:
name: shelf_packages_handler
sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
shelf_static:
dependency: transitive
description:
name: shelf_static
sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e
url: "https://pub.dev"
source: hosted
version: "1.1.2"
shelf_web_socket:
dependency: transitive
description:
Expand All @@ -1058,6 +1106,30 @@ packages:
description: flutter
source: sdk
version: "0.0.99"
source_gen:
dependency: transitive
description:
name: source_gen
sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832"
url: "https://pub.dev"
source: hosted
version: "1.5.0"
source_map_stack_trace:
dependency: transitive
description:
name: source_map_stack_trace
sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
source_maps:
dependency: transitive
description:
name: source_maps
sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703"
url: "https://pub.dev"
source: hosted
version: "0.10.12"
source_span:
dependency: transitive
description:
Expand Down Expand Up @@ -1154,6 +1226,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.1"
test:
dependency: "direct main"
description:
name: test
sha256: "7ee446762c2c50b3bd4ea96fe13ffac69919352bd3b4b17bac3f3465edc58073"
url: "https://pub.dev"
source: hosted
version: "1.25.2"
test_api:
dependency: transitive
description:
Expand All @@ -1162,6 +1242,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.0"
test_core:
dependency: transitive
description:
name: test_core
sha256: "2bc4b4ecddd75309300d8096f781c0e3280ca1ef85beda558d33fcbedc2eead4"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
time:
dependency: transitive
description:
Expand Down Expand Up @@ -1362,6 +1450,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.4.0"
webkit_inspection_protocol:
dependency: transitive
description:
name: webkit_inspection_protocol
sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
win32:
dependency: transitive
description:
Expand Down
7 changes: 5 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ dependencies:
flutter_platform_widgets: ^6.0.2
flutter_slidable: ^3.0.1
flutter_svg: ^2.0.7
flutter_test:
sdk: flutter
get: ^4.6.5
get_test: ^4.0.1
google_fonts: ^6.1.0
hive: ^2.2.1
hive_flutter: ^1.1.0
Expand All @@ -41,6 +44,7 @@ dependencies:
in_app_update: ^4.2.3
intl: ^0.18.0
loggy: ^2.0.1+1
mockito: ^5.4.4
package_info_plus: ^4.0.2
pem: ^2.0.1
permission_handler:
Expand All @@ -53,6 +57,7 @@ dependencies:
sizer: ^2.0.15
sqflite: ^2.3.3+1
syncfusion_flutter_charts: ^23.2.7
test: ^1.25.2
timezone: ^0.9.2
tuple: ^2.0.0
tutorial_coach_mark: ^1.2.11
Expand All @@ -63,8 +68,6 @@ dev_dependencies:
build_runner: null
flutter_gen_runner: null
flutter_lints: 4.0.0
flutter_test:
sdk: flutter

flutter_gen:
output: lib/app/utils/gen/
Expand Down
66 changes: 66 additions & 0 deletions test/taskfunctions/comparator_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:test/test.dart';
import 'package:taskwarrior/app/utils/taskfunctions/comparator.dart';
import 'package:taskwarrior/app/models/json/task.dart';

void main() {
final task1 = Task((builder) => builder
..entry = DateTime(2024, 7, 20)
..modified = DateTime(2024, 7, 21)
..start = DateTime(2024, 7, 22)
..due = DateTime(2024, 7, 23)
..priority = 'H'
..project = 'Project A'
..tags.replace(['tag1', 'tag2'])
..status = 'pending'
..uuid = 'uuid1'
..description = 'Task 1 Description'
);

final task2 = Task((builder) => builder
..entry = DateTime(2024, 7, 19)
..modified = DateTime(2024, 7, 18)
..start = DateTime(2024, 7, 21)
..due = DateTime(2024, 7, 22)
..priority = 'L'
..project = 'Project B'
..tags.replace(['tag1'])
..status = 'pending'
..uuid = 'uuid2'
..description = 'Task 2 Description'
);

test('Test compareTasks for Created column', () {
final compare = compareTasks('Created');
expect(compare(task1, task2), greaterThan(0));
});

test('Test compareTasks for Modified column', () {
final compare = compareTasks('Modified');
expect(compare(task1, task2), greaterThan(0));
});

test('Test compareTasks for Start Time column', () {
final compare = compareTasks('Start Time');
expect(compare(task1, task2), greaterThan(0));
});

test('Test compareTasks for Priority column', () {
final compare = compareTasks('Priority');
expect(compare(task1, task2), greaterThan(0));
});

test('Test compareTasks for Project column', () {
final compare = compareTasks('Project');
expect(compare(task1, task2), lessThan(0));
});

test('Test compareTasks for Tags column', () {
final compare = compareTasks('Tags');
expect(compare(task1, task2), greaterThan(0));
});

test('Test compareTasks for Urgency column', () {
final compare = compareTasks('Urgency');
expect(compare(task1, task2), lessThan(0));
});
}
96 changes: 96 additions & 0 deletions test/taskfunctions/datetime_differences_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:taskwarrior/app/utils/taskfunctions/datetime_differences.dart';

void main() {
group('DateTime Functions Tests', () {
test('Test age function', () {
DateTime dt = DateTime.now().subtract(const Duration(days: 365));
String result = age(dt);
expect(result, contains('12mo '));

dt = DateTime.now().subtract(const Duration(days: 60));
result = age(dt);
expect(result, contains('2mo '));

dt = DateTime.now().subtract(const Duration(days: 21));
result = age(dt);
expect(result, contains('3w '));

dt = DateTime.now().subtract(const Duration(days: 4));
result = age(dt);
expect(result, contains('4d '));

dt = DateTime.now().subtract(const Duration(hours: 5));
result = age(dt);
expect(result, contains('5h '));

dt = DateTime.now().subtract(const Duration(minutes: 10));
result = age(dt);
expect(result, contains('10min '));

dt = DateTime.now().subtract(const Duration(seconds: 30));
result = age(dt);
expect(result, contains('30s '));
});

test('Test when function', () {
DateTime dt = DateTime.now().add(const Duration(days: 365));
String result = when(dt);
expect(result, contains('12mo'));

dt = DateTime.now().add(const Duration(days: 60));
result = when(dt);
expect(result, contains('1mo'));

dt = DateTime.now().add(const Duration(days: 21));
result = when(dt);
expect(result, contains('2w'));

dt = DateTime.now().add(const Duration(days: 4));
result = when(dt);
expect(result, contains('3d'));

dt = DateTime.now().add(const Duration(hours: 5));
result = when(dt);
expect(result, contains('4h'));

dt = DateTime.now().add(const Duration(minutes: 10));
result = when(dt);
expect(result, contains('9min'));

dt = DateTime.now().add(const Duration(seconds: 30));
result = when(dt);
expect(result, contains('29s'));
});

test('Test difference function', () {
DateTime dt = DateTime.now().subtract(const Duration(days: 365));
String result = difference(DateTime.now().difference(dt));
expect(result, contains('12mo '));

dt = DateTime.now().subtract(const Duration(days: 60));
result = difference(DateTime.now().difference(dt));
expect(result, contains('2mo '));

dt = DateTime.now().subtract(const Duration(days: 21));
result = difference(DateTime.now().difference(dt));
expect(result, contains('3w '));

dt = DateTime.now().subtract(const Duration(days: 4));
result = difference(DateTime.now().difference(dt));
expect(result, contains('4d '));

dt = DateTime.now().subtract(const Duration(hours: 5));
result = difference(DateTime.now().difference(dt));
expect(result, contains('5h '));

dt = DateTime.now().subtract(const Duration(minutes: 10));
result = difference(DateTime.now().difference(dt));
expect(result, contains('10min '));

dt = DateTime.now().subtract(const Duration(seconds: 30));
result = difference(DateTime.now().difference(dt));
expect(result, contains('30s '));
});
});
}
Loading
Loading