-
Notifications
You must be signed in to change notification settings - Fork 93
/
widget_test.dart
50 lines (43 loc) · 1.64 KB
/
widget_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fake_cloud_firestore/fake_cloud_firestore.dart';
import 'package:firestore_example/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
const MessagesCollection = 'messages';
void main() {
testWidgets('shows messages', (WidgetTester tester) async {
// Populate the mock database.
final firestore = FakeFirebaseFirestore();
await firestore.collection(MessagesCollection).add({
'message': 'Hello world!',
'created_at': FieldValue.serverTimestamp(),
});
// Render the widget.
await tester.pumpWidget(MaterialApp(
title: 'Firestore Example', home: MyHomePage(firestore: firestore)));
// Let the snapshots stream fire a snapshot.
await tester.idle();
// Re-render.
await tester.pump();
// Verify the output.
expect(find.text('Hello world!'), findsOneWidget);
expect(find.text('Message 1 of 1'), findsOneWidget);
});
testWidgets('adds messages', (WidgetTester tester) async {
// Instantiate the mock database.
final firestore = FakeFirebaseFirestore();
// Render the widget.
await tester.pumpWidget(MaterialApp(
title: 'Firestore Example', home: MyHomePage(firestore: firestore)));
// Verify that there is no data.
expect(find.text('Hello world!'), findsNothing);
// Tap the Add button.
await tester.tap(find.byType(FloatingActionButton));
// Let the snapshots stream fire a snapshot.
await tester.idle();
// Re-render.
await tester.pump();
// Verify the output.
expect(find.text('Hello world!'), findsOneWidget);
});
}