cpd_2022_zi/test/integration_tests/sleep_view_test.dart

54 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:smoke_cess_app/models/sleep.dart';
import 'package:smoke_cess_app/providers/settings_provider.dart';
import 'package:smoke_cess_app/providers/tasks_provider.dart';
import 'package:smoke_cess_app/globals.dart' as globals;
import 'package:smoke_cess_app/widgets/view_form/sleep_view.dart';
import '../mock/db_mock.dart';
import '../mock/settings_mock.dart';
void main() {
globals.databaseService = DatabaseMock();
TestWidgetsFlutterBinding.ensureInitialized();
SharedPreferences.setMockInitialValues(mockSettings);
initializeDateFormatting('de');
testWidgets('Sleep View displays correctly', (WidgetTester tester) async {
const String testText = 'Its a test';
const int testValue = 30;
// Create an instance of the Providers and add it to the widget tree
final tasksProvider = TasksProvider(null);
final settingsProvider = SettingsProvider();
await tester.pumpWidget(
MultiProvider(
providers: [
ChangeNotifierProvider.value(value: tasksProvider),
ChangeNotifierProvider.value(value: settingsProvider),
],
child: const MaterialApp(
home: Scaffold(
body: SleepView(),
),
),
),
);
await settingsProvider.initSettings();
await globals.databaseService.addSleep(Sleep(
testValue,
testText,
DateTime.now(),
const TimeOfDay(hour: 22, minute: 0),
const TimeOfDay(hour: 8, minute: 0)));
await tasksProvider.initHistories();
await tester.pump();
expect(find.text('10:00'), findsOneWidget);
await tester.tap(find.byIcon(Icons.expand_more));
await tester.pump();
expect(find.text('Kommentar: $testText'), findsOneWidget);
});
}