forked from ubuntu/yaru.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyaru_checkbox_test.dart
168 lines (149 loc) · 5.17 KB
/
yaru_checkbox_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:yaru_widgets/yaru_widgets.dart';
import '../yaru_golden_tester.dart';
void main() {
testWidgets('the checkbox react to taps', (tester) async {
bool? changedValue;
Widget builder({required bool? initialValue, required bool tristate}) {
return MaterialApp(
home: Scaffold(
body: YaruCheckbox(
value: initialValue,
tristate: tristate,
onChanged: (v) => changedValue = v,
),
),
);
}
final checkboxFinder = find.byType(YaruCheckbox);
await tester.pumpWidget(builder(initialValue: false, tristate: false));
await tester.tap(checkboxFinder);
expect(changedValue, isTrue);
await tester.pumpWidget(builder(initialValue: true, tristate: false));
await tester.tap(checkboxFinder);
expect(changedValue, isFalse);
await tester.pumpWidget(builder(initialValue: false, tristate: true));
await tester.tap(checkboxFinder);
expect(changedValue, isTrue);
await tester.pumpWidget(builder(initialValue: true, tristate: true));
await tester.tap(checkboxFinder);
expect(changedValue, null);
await tester.pumpWidget(builder(initialValue: null, tristate: true));
await tester.tap(checkboxFinder);
expect(changedValue, isFalse);
});
testWidgets('mouse cursor changes depending on the state', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Column(
children: [
YaruCheckbox(
value: false,
onChanged: (_) {},
),
const YaruCheckbox(
value: false,
onChanged: null,
),
],
),
),
),
);
final gesture =
await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
await gesture.addPointer(location: Offset.zero);
addTearDown(gesture.removePointer);
await gesture.moveTo(
tester.getCenter(
find.byWidgetPredicate(
(widget) => widget is YaruCheckbox && widget.onChanged != null,
),
),
);
await tester.pump();
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
SystemMouseCursors.click,
);
await gesture.moveTo(
tester.getCenter(
find.byWidgetPredicate(
(widget) => widget is YaruCheckbox && widget.onChanged == null,
),
),
);
await tester.pump();
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
SystemMouseCursors.basic,
);
});
testWidgets(
'golden images',
(tester) async {
final variant = goldenVariant.currentValue!;
// ensure traditional focus highlight
FocusManager.instance.highlightStrategy =
FocusHighlightStrategy.alwaysTraditional;
final tristate = variant.label.startsWith('tristate');
await tester.pumpScaffold(
YaruCheckbox(
autofocus: variant.hasState(MaterialState.focused),
tristate: tristate,
value: tristate ? null : variant.hasState(MaterialState.selected),
onChanged: variant.hasState(MaterialState.disabled) ? null : (_) {},
),
themeMode: variant.themeMode,
size: const Size(40, 40),
);
await tester.pumpAndSettle();
if (variant.hasState(MaterialState.pressed)) {
await tester.down(find.byType(YaruCheckbox));
await tester.pumpAndSettle();
} else if (variant.hasState(MaterialState.hovered)) {
await tester.hover(find.byType(YaruCheckbox));
await tester.pumpAndSettle();
}
await expectLater(
find.byType(YaruCheckbox),
matchesGoldenFile('goldens/yaru_checkbox-${variant.label}.png'),
);
},
variant: goldenVariant,
tags: 'golden',
);
}
final goldenVariant = ValueVariant({
...goldenThemeVariants('unchecked', <MaterialState>{}),
...goldenThemeVariants('unckecked-disabled', {MaterialState.disabled}),
...goldenThemeVariants('unckecked-focused', {MaterialState.focused}),
...goldenThemeVariants('unckecked-hovered', {MaterialState.hovered}),
...goldenThemeVariants('unckecked-pressed', {MaterialState.pressed}),
...goldenThemeVariants('checked', {MaterialState.selected}),
...goldenThemeVariants('checked-disabled', {
MaterialState.selected,
MaterialState.disabled,
}),
...goldenThemeVariants('checked-focused', {
MaterialState.selected,
MaterialState.focused,
}),
...goldenThemeVariants('checked-hovered', {
MaterialState.selected,
MaterialState.hovered,
}),
...goldenThemeVariants('checked-pressed', {
MaterialState.selected,
MaterialState.pressed,
}),
...goldenThemeVariants('tristate', {MaterialState.selected}),
...goldenThemeVariants('tristate-disabled', {MaterialState.disabled}),
...goldenThemeVariants('tristate-focused', {MaterialState.focused}),
...goldenThemeVariants('tristate-hovered', {MaterialState.hovered}),
...goldenThemeVariants('tristate-pressed', {MaterialState.pressed}),
});