Fakultas Ilmu Komputer UI

filter_test.dart 1.7 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';
Fakhira Devina's avatar
Fakhira Devina committed
10
import 'package:ppl_disabilitas/page/filter_fasilitas/fasilitas.dart';
11
12

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

fazasabira's avatar
fazasabira committed
18
  testWidgets('find inside filter page', (WidgetTester tester) async {
19
    // Provide the childWidget to the Container.
Fakhira Devina's avatar
Fakhira Devina committed
20
21
22
23
24
25
26
27
    await tester.pumpWidget(buildTestableWidget(Fasilitas(
      alamat: 'Itu',
      nama: 'Ya',
      telpon: '9217424',
      url: 'afalklksafn',
    )));
    await tester.tap(find.byKey(Key('FilterButton')));
    await tester.pump(Duration(seconds: 1));
28
    // inside filter
Fakhira Devina's avatar
Fakhira Devina committed
29
30
31
32
    expect(find.byType(Container), findsNWidgets(28));
    expect(find.byType(Row), findsNWidgets(17));
    expect(find.byType(Column), findsNWidgets(4));
    expect(find.byType(Text), findsNWidgets(21));
33
    expect(find.byType(Flex), findsNothing);
34
35
    expect(find.text('jns fasilitas'), findsNothing);
    expect(find.text('urutn'), findsNothing);
fazasabira's avatar
fazasabira committed
36
    expect(find.text('hps smw'), findsNothing);
37
38
    // filter
    expect(find.byType(Scaffold), findsOneWidget);
Fakhira Devina's avatar
Fakhira Devina committed
39
40
41
    expect(find.byType(Icon), findsNWidgets(5));
    await tester.tap(find.byKey(Key('Tambah Informasi')));
    await tester.pump();
42
43
  });
}