-
Notifications
You must be signed in to change notification settings - Fork 157
/
widget_test.dart
75 lines (65 loc) · 2.3 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// 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:dynamic_color/dynamic_color.dart';
import 'package:dynamic_color/samples.dart';
import 'package:dynamic_color/test_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
const key = Key('container');
// Reset for every test
setUp(() => DynamicColorTestingUtils.setMockDynamicColors());
testWidgets('Verify dynamic core palette is used ',
(WidgetTester tester) async {
DynamicColorTestingUtils.setMockDynamicColors(
corePalette: SampleCorePalettes.green,
);
await tester.pumpWidget(
DynamicColorBuilder(
builder: (lightDynamic, darkDynamic) => Container(
key: key,
color: lightDynamic?.primary ?? Colors.red,
),
),
);
await tester.pumpAndSettle();
final container = tester.widget<Container>(find.byKey(key));
expect(container.color, const Color(0xff286c2a));
});
testWidgets('Verify dynamic accent color is used ',
(WidgetTester tester) async {
DynamicColorTestingUtils.setMockDynamicColors(
accentColor: Colors.green,
);
await tester.pumpWidget(
DynamicColorBuilder(
builder: (lightDynamic, darkDynamic) => Container(
key: key,
color: lightDynamic?.primary ?? Colors.red,
),
),
);
await tester.pumpAndSettle();
final container = tester.widget<Container>(find.byKey(key));
expect(container.color, const Color(0xff006e1c));
});
testWidgets('Verify fallback color is used', (WidgetTester tester) async {
await tester.pumpWidget(
DynamicColorBuilder(
builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
return Container(
key: key,
color: lightDynamic?.primary ?? Colors.red,
);
},
),
);
await tester.pumpAndSettle();
final container = tester.widget<Container>(find.byKey(key));
expect(container.color, Colors.red);
});
}