Fakultas Ilmu Komputer UI

Commit c8d9218f authored by Fakhira Devina's avatar Fakhira Devina
Browse files

[CHORE] pass tests

parent cfdab534
import 'package:flutter/material.dart';
import 'package:mockito/mockito.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:ppl_disabilitas/page/dashboard/dashboard.dart';
class MockNavigatorObserver extends Mock implements NavigatorObserver {}
void main() {
group('Dashboard navigation tests', () {
NavigatorObserver mockObserver;
setUp(() {
mockObserver = MockNavigatorObserver();
});
Future<Null> _buildDashboardPage(WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Dashboard(),
/// This mocked observer will now receive all navigation events
/// that happen in our app.
navigatorObservers: [mockObserver],
));
/// The tester.pumpWidget() call above just built our app widget
/// and triggered the pushObserver method on the mockObserver once.
verify(mockObserver.didPush(any, any));
}
Future<Null> _navigateToPencarianPage(WidgetTester tester) async {
final textFieldKey = Key("Text Field Mau Kemana");
await tester.tap(find.byKey(textFieldKey));
await tester.pumpAndSettle();
}
testWidgets(
'when tapping text form field, should navigate to pencarina page',
(WidgetTester tester) async {
final textFieldKeyPencarian = Key("Text Field Mau Kemana");
await _buildDashboardPage(tester);
await _navigateToPencarianPage(tester);
verify(mockObserver.didPush(any, any));
expect(find.byKey(textFieldKeyPencarian), findsOneWidget);
});
testWidgets('tapping the back button should navigate back to the dashboard',
(WidgetTester tester) async {
final backIconKey = Key("Back Icon Key");
await _buildDashboardPage(tester);
await _navigateToPencarianPage(tester);
final Route pushedRoute =verify(mockObserver.didPush(captureAny, any)).captured.single;
String popResult;
pushedRoute.popped.then((result) => popResult = result);
await tester.tap(find.byKey(backIconKey));
await tester.pumpAndSettle();
expect(popResult, 'Take me back');
});
});
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment