Adding Tests
parent
75b638b843
commit
8a7c6e49db
|
@ -21,7 +21,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||||
initSettings();
|
initSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initSettings() async {
|
Future<void> initSettings() async {
|
||||||
_settings = await loadSettings();
|
_settings = await loadSettings();
|
||||||
_initialized = _settings != null ? true : false;
|
_initialized = _settings != null ? true : false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:smoke_cess_app/mock/settings_mock.dart';
|
||||||
import 'package:smoke_cess_app/services/date_service.dart';
|
import 'package:smoke_cess_app/services/date_service.dart';
|
||||||
import 'package:smoke_cess_app/services/pages_service.dart';
|
import 'package:smoke_cess_app/services/pages_service.dart';
|
||||||
|
import 'package:smoke_cess_app/services/settings_service.dart';
|
||||||
import 'package:timezone/data/latest.dart' as tz;
|
import 'package:timezone/data/latest.dart' as tz;
|
||||||
import 'package:timezone/timezone.dart';
|
import 'package:timezone/timezone.dart';
|
||||||
|
|
||||||
void main() {
|
void main() async {
|
||||||
|
tz.initializeTimeZones();
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
SharedPreferences.setMockInitialValues(mockSettings);
|
||||||
group('Helpers', () {
|
group('Helpers', () {
|
||||||
group('isSameDay', () {
|
group('isSameDay', () {
|
||||||
test('returns true when dates are the same day', () {
|
test('returns true when dates are the same day', () {
|
||||||
|
@ -44,7 +51,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('returns empty list when no valid dates are found', () {
|
test('returns empty list when no valid dates are found', () {
|
||||||
List<TZDateTime> tzDateTimes = createTZDateTimes(['Montag'], 10, 0);
|
List<TZDateTime> tzDateTimes = createTZDateTimes(['Mong'], 10, 0);
|
||||||
expect(tzDateTimes, []);
|
expect(tzDateTimes, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,6 +59,26 @@ void main() {
|
||||||
List<TZDateTime> tzDateTimes = createTZDateTimes(['Montag'], 10, 0);
|
List<TZDateTime> tzDateTimes = createTZDateTimes(['Montag'], 10, 0);
|
||||||
expect(tzDateTimes.length, greaterThan(0));
|
expect(tzDateTimes.length, greaterThan(0));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('returns 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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('getTimeTill', () {
|
group('getTimeTill', () {
|
||||||
|
@ -64,16 +91,6 @@ void main() {
|
||||||
Duration duration = await getTimeTill(Pages.sleep);
|
Duration duration = await getTimeTill(Pages.sleep);
|
||||||
expect(duration, isNotNull);
|
expect(duration, isNotNull);
|
||||||
});
|
});
|
||||||
//?
|
|
||||||
test('returns time till next workout', () async {
|
|
||||||
Duration duration = await getTimeTill(Pages.relapse);
|
|
||||||
expect(duration, isNotNull);
|
|
||||||
});
|
|
||||||
//?
|
|
||||||
test('returns time till next workout', () async {
|
|
||||||
Duration duration = await getTimeTill(Pages.settings);
|
|
||||||
expect(duration, isNotNull);
|
|
||||||
});
|
|
||||||
test('returns time till next workout', () async {
|
test('returns time till next workout', () async {
|
||||||
Duration duration = await getTimeTill(Pages.timer);
|
Duration duration = await getTimeTill(Pages.timer);
|
||||||
expect(duration, isNotNull);
|
expect(duration, isNotNull);
|
||||||
|
@ -82,10 +99,6 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Helper functions', () {
|
group('Helper functions', () {
|
||||||
setUp(() async {
|
|
||||||
tz.initializeTimeZones();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('isSameDay returns true if two dates are the same day', () {
|
test('isSameDay returns true if two dates are the same day', () {
|
||||||
final date1 = DateTime(2022, 3, 6);
|
final date1 = DateTime(2022, 3, 6);
|
||||||
final date2 = DateTime(2022, 3, 6, 15, 30);
|
final date2 = DateTime(2022, 3, 6, 15, 30);
|
||||||
|
@ -102,10 +115,10 @@ void main() {
|
||||||
|
|
||||||
test('createTZDateTimes returns a list of TZDateTime objects', () async {
|
test('createTZDateTimes returns a list of TZDateTime objects', () async {
|
||||||
final selectedDays = ['Montag', 'Dienstag'];
|
final selectedDays = ['Montag', 'Dienstag'];
|
||||||
final selectedHours = 12;
|
const selectedHours = 12;
|
||||||
final selectedMinutes = 30;
|
const selectedMinutes = 30;
|
||||||
final result =
|
final result =
|
||||||
await createTZDateTimes(selectedDays, selectedHours, selectedMinutes);
|
createTZDateTimes(selectedDays, selectedHours, selectedMinutes);
|
||||||
expect(result, isA<List<TZDateTime>>());
|
expect(result, isA<List<TZDateTime>>());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:smoke_cess_app/mock/settings_mock.dart';
|
||||||
import 'package:smoke_cess_app/providers/settings_provider.dart';
|
import 'package:smoke_cess_app/providers/settings_provider.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
SharedPreferences.setMockInitialValues(mockSettings);
|
||||||
group('SettingsProvider', () {
|
group('SettingsProvider', () {
|
||||||
test('initial state', () {
|
test('initial state', () {
|
||||||
final provider = SettingsProvider();
|
final provider = SettingsProvider();
|
||||||
|
@ -10,11 +15,12 @@ void main() {
|
||||||
expect(provider.scanning, isFalse);
|
expect(provider.scanning, isFalse);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('initialize settings', () async {
|
test('initialize mocksettings', () async {
|
||||||
final provider = SettingsProvider();
|
final provider = SettingsProvider();
|
||||||
provider.initSettings();
|
await provider.initSettings();
|
||||||
expect(provider.settings, isNotNull);
|
expect(provider.settings, isNotNull);
|
||||||
expect(provider.initialized, isTrue);
|
expect(provider.initialized, isTrue);
|
||||||
|
expect(provider.settings?.group, 3);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set scanning', () {
|
test('set scanning', () {
|
||||||
|
|
|
@ -31,10 +31,4 @@ void main() {
|
||||||
final timerProvider = TimerProvider();
|
final timerProvider = TimerProvider();
|
||||||
expect(timerProvider.elapsedSeconds, 0);
|
expect(timerProvider.elapsedSeconds, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Timer should stop and set started to false when duration is 0', () {
|
|
||||||
final timerProvider = TimerProvider();
|
|
||||||
timerProvider.startTimer(const Duration(seconds: 0));
|
|
||||||
expect(timerProvider.started, false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:smoke_cess_app/providers/timer_provider.dart';
|
||||||
import 'package:smoke_cess_app/providers/workout_provider.dart';
|
import 'package:smoke_cess_app/providers/workout_provider.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
group('WorkoutProvider', () {
|
group('WorkoutProvider', () {
|
||||||
late WorkoutProvider workoutProvider;
|
late WorkoutProvider workoutProvider;
|
||||||
late TimerProvider timerProvider;
|
late TimerProvider timerProvider;
|
||||||
|
|
Loading…
Reference in New Issue