ModernMemoires/test/ui_home_screen_test.dart

71 lines
2.4 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:moody/main.dart' as app;
import 'icon_finder.dart';
import 'package:moody/utils/widgets/question_slider_widget.dart'; // Replace with the actual import of your app
import 'package:moody/utils/widgets/why_widget.dart';
import 'package:shared_preferences/shared_preferences.dart';
// Testet "First Page" gleich mit
void main() {
SharedPreferences.setMockInitialValues({});
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
// testWidgets('HomePage - Find "+ Edit" and "- Save" Texts', (WidgetTester tester) async {
testWidgets('HomePage UI Test', (WidgetTester tester) async {
app.main();
await tester.pumpAndSettle();
await tester.tap(find.text('skip'));
await tester.pumpAndSettle();
// Navigate to the HomePage if it's not the initial page
await tester.tap(findIconByAsset('icon-logo.png'));// should be irrelevant because he *should* automatically be there but we are superstitius so I'm leaving this
await tester.pumpAndSettle();
// Check for the presence of QuestionSliderWidget
expect(find.byType(QuestionSliderWidget), findsOneWidget);
// Test the slider movement
final Finder sliderFinder = find.byType(Slider);
await tester.drag(sliderFinder, const Offset(50, 0)); // Adjust the Offset as necessary
await tester.pumpAndSettle();
await tester.tap(find.text("save."));
await tester.pumpAndSettle();
await tester.tap(find.text('warum?'));
await tester.pumpAndSettle();
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
//debugDumpApp();
await tester.tap(find.text("+ Edit"));
await tester.pumpAndSettle();
// Check if the text area is editable and perform text entry if it is
final Finder ancestor = find.byType(WhyWidget);
final Finder descendant = find.descendant(
of: ancestor,
matching: find.byType(TextField)
);
if (tester.any(descendant)) {
await tester.enterText(descendant, 'Sample diary entry');
await tester.pumpAndSettle();
}
// Test the save/edit button functionality
await tester.tap(find.text('- Save'));
await tester.pumpAndSettle();
// Verify the updated text
expect(find.text('Sample diary entry'), findsOneWidget);
});
}