cpd_2022_zi/test/unit_tests/date_service_test.dart

38 lines
1.3 KiB
Dart
Raw Normal View History

2023-03-06 21:04:35 +01:00
import 'package:flutter_test/flutter_test.dart';
import 'package:timezone/data/latest.dart' as tz;
import 'package:smoke_cess_app/services/date_service.dart';
import 'package:timezone/timezone.dart';
void main() {
tz.initializeTimeZones();
test('IsSameDay: false', () {
bool result =
isSameDay(DateTime.now(), DateTime.now().add(const Duration(days: 1)));
expect(result, false);
});
test('IsSameDay: true', () {
bool result = isSameDay(DateTime.now(), DateTime.now());
expect(result, true);
});
test('CreateTZDateTimes: all the same days as today in next 6 weeks at 23:59',
() {
List<String> selectedDays = [
weekDays.keys.elementAt(DateTime.now().weekday - 1)
];
List<TZDateTime> expected = [];
DateTime now = DateTime.now();
final Duration offset = now.timeZoneOffset;
final DateTime date =
DateTime(now.year, now.month, now.day, 23, 59, 0, 0, 0);
for (int i = 0; i <= trainingTime; i = i + 7) {
expected.add(
TZDateTime.local(date.year, date.month, date.day, 23, 59, 0, 0, 0)
.add(Duration(days: i))
// subtract offset since TZDateTime uses the UTC Timezone
.subtract(offset));
}
List<TZDateTime> result = createTZDateTimes(selectedDays, 23, 59);
expect(result, expected);
});
}