cpd_2022_zi/test/integration_tests/relapse_view_test.dart

53 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/relapse.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/relapse_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('Relapse View displays correctly', (WidgetTester tester) async {
const String testText = 'Its a test';
// 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: RelapseView(),
),
),
),
);
await settingsProvider.initSettings();
await globals.databaseService.addRelapse(Relapse(
settingsProvider.settings!.relapseCategories![0],
testText,
DateTime.now(),
));
await tasksProvider.initHistories();
await tester.pump();
expect(find.text(settingsProvider.settings!.relapseCategories![0]),
findsOneWidget);
await tester.tap(find.byIcon(Icons.expand_more));
await tester.pump();
expect(find.text('Kommentar: $testText'), findsOneWidget);
});
}