mobileapplicationPassvault/test/widget_test.dart

59 lines
2.3 KiB
Dart
Raw Normal View History

2024-04-12 05:23:32 +00:00
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_passvault/view_pages/login.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Username and Password TextField Test',
(WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MaterialApp(home: LoginScreen()));
// Verify that our counter starts at 0.
// expect(find.text('0'), findsOneWidget);
// expect(find.text('1'), findsNothing);
// // Tap the '+' icon and trigger a frame.
// await tester.tap(find.byIcon(Icons.add));
// await tester.pump();
// // Verify that our counter has incremented.
// expect(find.text('0'), findsNothing);
// expect(find.text('1'), findsOneWidget);
// Find the username and password TextFields using their keys or other identifiers
final Finder usernameTextField = find.byKey(const Key('usernameTextField'));
final Finder passwordTextField = find.byKey(const Key('passwordTextField'));
// Enter text into the username and password fields
await tester.enterText(usernameTextField, 'testUsername');
await tester.enterText(passwordTextField, 'testPassword');
// Verify that the entered text is correct
expect(find.text('testUsername'), findsOneWidget);
expect(find.text('testPassword'), findsOneWidget);
// Perform any interactions or further tests based on your widget's behavior
// For example, you could simulate tapping a login button
// and then verify the expected behavior after tapping the button
// Pump the widget after interactions
await tester.pump();
// Assert or verify the expected behavior after interactions
// Example: Verify that a loading indicator appears after tapping the login button
// expect(find.byType(CircularProgressIndicator), findsOneWidget);
expect(find.text('testUsername'), findsOneWidget);
expect(find.text('testPassword'), findsOneWidget);
});
}