Fakultas Ilmu Komputer UI

pencarian_test.dart 2.09 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
40
  testWidgets('display list view in pencarian', (WidgetTester tester) async {
    // Provide the childWidget to the Container.
    await tester.pumpWidget(MaterialApp(home: Pencarian()));
41
42
43
44
    await tester.enterText(find.byKey(const Key("Text Field Mau Kemana")), "Coolidge");
    await tester.pump();

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

52
  testWidgets('finds a text field in pencarian', (WidgetTester tester) async {
53
    final textFieldKey = Key("Text Field Mau Kemana");
54
    await tester.pumpWidget(MaterialApp(home: Pencarian()));
55
    expect(find.byKey(textFieldKey), findsOneWidget);
56
  });
57

58
}