Fakultas Ilmu Komputer UI

list_sekolah_test.dart 1.88 KB
Newer Older
1
2
3
4
5
6
7
8
9
// 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.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
10
import 'package:ppl_disabilitas/page/informasi/list_sekolah.dart';
11
12

void main() {
13
14
15
16
17
  Widget buildTestableWidget(Widget widget) {
    // https://docs.flutter.io/flutter/widgets/MediaQuery-class.html
    return MediaQuery(data: MediaQueryData(), child: MaterialApp(home: widget));
  }

Firriyal Bin Yahya's avatar
Firriyal Bin Yahya committed
18
  testWidgets("find a title app bar", (WidgetTester tester) async {
19
    final textAppBar = Key("appbar-text-informasi-sekolah");
Firriyal Bin Yahya's avatar
Firriyal Bin Yahya committed
20
21
22
    await tester.pumpWidget(MaterialApp(home: ListSekolah()));

    expect(find.byKey(textAppBar), findsOneWidget);
23
    expect(find.text("Sekolah dengan Dukungan Disabilitas"), findsOneWidget);
Firriyal Bin Yahya's avatar
Firriyal Bin Yahya committed
24
  });
25

26
27
28
29
30
  testWidgets('find inside filter page', (WidgetTester tester) async {
    // Provide the childWidget to the Container.
    await tester.pumpWidget(buildTestableWidget(ListSekolah()));
    await tester.tap(find.byKey(Key('FilterButton')));
    await tester.pump(Duration(seconds: 1));
31
    expect(find.byType(Container), findsNWidgets(34));
32
33
34
    expect(find.byType(Row), findsNWidgets(21));
    expect(find.byType(Column), findsNWidgets(5));
    expect(find.byType(Text), findsNWidgets(27));
35
36
37
38
39
    expect(find.byType(Flex), findsNothing);
    expect(find.text('jns fasilitas'), findsNothing);
    expect(find.text('urutn'), findsNothing);
    expect(find.text('hps smw'), findsNothing);
    expect(find.byType(Scaffold), findsOneWidget);
40
41
    expect(find.byType(Icon), findsNWidgets(5));
    await tester.tap(find.byKey(Key('FilterButton')));
42
43
    await tester.pump();
  });
44
}