-
Notifications
You must be signed in to change notification settings - Fork 352
/
Copy pathpin_code_fields_test.dart
73 lines (63 loc) · 2.1 KB
/
pin_code_fields_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pin_code_fields/pin_code_fields.dart';
void main() {
final binding = TestWidgetsFlutterBinding.ensureInitialized();
testWidgets('disposes error stream', (WidgetTester tester) async {
final StreamController<ErrorAnimationType> controller =
StreamController<ErrorAnimationType>();
final Widget app = Builder(
builder: (context) => MaterialApp(
home: Scaffold(
body: PinCodeTextField(
appContext: context,
length: 6,
errorAnimationController: controller,
),
),
),
);
await tester.pumpWidget(app);
expect(controller.hasListener, isTrue);
await tester.pumpWidget(SizedBox());
expect(controller.hasListener, isFalse);
controller.close();
});
/// This test demonstrates that a application can set a InputDecorationTheme
/// which specifies a background color for input fields. When this happens,
/// the PinCodeFields should override the theme setting with the users chosen
/// background color.
testWidgets('transparent background', (WidgetTester tester) async {
await binding.setSurfaceSize(const Size(800, 400));
final Widget app = Builder(
builder: (context) {
return MaterialApp(
theme: ThemeData(
inputDecorationTheme: InputDecorationTheme(
fillColor: Colors.red,
filled: true,
)),
home: Scaffold(
backgroundColor: Colors.black,
body: Builder(builder: (context) {
return PinCodeTextField(
appContext: context,
autoFocus: true,
backgroundColor: Colors.transparent,
length: 6,
animationDuration: Duration.zero,
);
}),
),
);
},
);
await tester.pumpWidget(app);
await tester.pumpAndSettle();
await expectLater(
find.byType(Scaffold),
matchesGoldenFile('golden_test_1.png'),
);
});
}