cpd_2022_zi/test/integration_tests/mood_view_test.dart

50 lines
1.8 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/mood.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/mood_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('Mood 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: MoodView(),
),
),
),
);
await settingsProvider.initSettings();
await globals.databaseService
.addMood(Mood(testValue, testText, DateTime.now()));
await tasksProvider.initHistories();
await tester.pump();
expect(find.text('Stimmung: $testValue'), findsOneWidget);
await tester.tap(find.byIcon(Icons.expand_more));
await tester.pump();
expect(find.text('Kommentar: $testText'), findsOneWidget);
});
}