Fakultas Ilmu Komputer UI

pencarian_test.dart 2.65 KB
Newer Older
1
2
3
4
5
6
7
8
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. 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.


9
10
import 'dart:io';

11
12
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
13
import 'package:mockito/mockito.dart';
14
import 'package:ppl_disabilitas/page/pencarian/pencarian.dart';
15
import 'package:ppl_disabilitas/network/network_interface.dart';
16

17
class MockNetwork extends Mock implements NetworkInterface {}
18
19

void main() {
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  MockNetwork mockNetwork;
  setUp(() {
    mockNetwork = MockNetwork();
    when(mockNetwork.get(isLogin: false, url: anyNamed('url'))).thenAnswer((_) async {
      await Future.delayed(Duration(milliseconds: 50));
      return Future<dynamic>.value(
          [
            {
              "nama": "Coolidge",
              "latitude": -23.7169139,
              "longitude": -46.8498038,
              "alamat": "74809 Hooker Drive",
              "telepon": "+55 956 836 5799"
            }
          ]
      );
    });
  });
38
39
  testWidgets('display list view in pencarian', (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(home: Pencarian()));
Firriyal Bin Yahya's avatar
Firriyal Bin Yahya committed
40
41
42
    expect(find.byKey(const Key("Text Field Mau Kemana")), findsOneWidget);
    //var textField = find.byKey(const Key("Text Field Mau Kemana"));
    //await tester.tap(textField);
43
44
    await tester.enterText(find.byKey(const Key("Text Field Mau Kemana")), "Coolidge");
    await tester.pump();
Firriyal Bin Yahya's avatar
Firriyal Bin Yahya committed
45
    expect(find.text("Hasil Pencarian"), findsOneWidget);
46

Firriyal Bin Yahya's avatar
Firriyal Bin Yahya committed
47
48
49
    //expect(find.byType(CircleAvatar), findsWidgets);

    //expect(find.byKey(const Key("api-Coolidge")), findsOneWidget);
50
    // [TODO] tiap item itu punya key unik
51
    // Search for the childWidget in the tree and verify it exists.
52
53
54
    //expect(find.byType(ListView), findsNWidgets);
    //expect(find.byType(Container), findsWidgets);
    //expect(find.byType(Icon), findsWidgets);
55
  });
56

57
  testWidgets('finds a text field in pencarian', (WidgetTester tester) async {
58
    final textFieldKey = Key("Text Field Mau Kemana");
59
    await tester.pumpWidget(MaterialApp(home: Pencarian()));
60
    expect(find.byKey(textFieldKey), findsOneWidget);
61
  });
62

63
64
65
66
67
68
69
70
71

  testWidgets('test textfield result', (WidgetTester tester) async {
    final textFieldKey = Key("Text Field Mau Kemana");
    await tester.pumpWidget(MaterialApp(home: Pencarian()));
    await tester.enterText(find.byKey(textFieldKey), 'Mallory');
    await tester.pump();
    expect(find.text('Mallory'), findsOneWidget);
});

72
}