forked from ubuntu/yaru.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyaru_radio_list_tile_test.dart
158 lines (142 loc) · 4.78 KB
/
yaru_radio_list_tile_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
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:yaru_widgets/yaru_widgets.dart';
import '../yaru_golden_tester.dart';
void main() {
testWidgets('contains radio, labels and secondary', (tester) async {
Widget builder({
required Widget title,
required Widget? subtitle,
required Widget? secondary,
}) {
return MaterialApp(
home: Scaffold(
body: YaruRadioListTile<int>(
title: title,
subtitle: subtitle,
secondary: secondary,
value: 0,
groupValue: 0,
onChanged: (_) {},
),
),
);
}
await tester.pumpWidget(
builder(
title: const Text('title'),
subtitle: null,
secondary: null,
),
);
expect(find.text('title'), findsOneWidget);
expect(find.text('subtitle'), findsNothing);
expect(find.byType(YaruRadio<int>), findsOneWidget);
await tester.pumpWidget(
builder(
title: const Text('title'),
subtitle: const Text('subtitle'),
secondary: const Icon(Icons.radio_button_checked),
),
);
expect(find.text('title'), findsOneWidget);
expect(find.text('subtitle'), findsOneWidget);
expect(find.byIcon(Icons.radio_button_checked), findsOneWidget);
expect(find.byType(YaruRadio<int>), findsOneWidget);
});
testWidgets('the tile react to taps', (tester) async {
int? changedValue;
Widget builder({
required int value,
required int groupValue,
required bool toggleable,
}) {
return MaterialApp(
home: Scaffold(
body: YaruRadioListTile<int>(
title: const Text('title'),
subtitle: const Text('subtitle'),
value: value,
groupValue: groupValue,
toggleable: toggleable,
onChanged: (v) => changedValue = v,
),
),
);
}
final tileFinder = find.byType(YaruRadioListTile<int>);
await tester
.pumpWidget(builder(value: 1, groupValue: 1, toggleable: false));
await tester.tap(tileFinder);
expect(changedValue, equals(1));
await tester
.pumpWidget(builder(value: 2, groupValue: 3, toggleable: false));
await tester.tap(tileFinder);
expect(changedValue, equals(2));
await tester.pumpWidget(builder(value: 1, groupValue: 1, toggleable: true));
await tester.tap(tileFinder);
expect(changedValue, equals(null));
await tester.pumpWidget(builder(value: 2, groupValue: 3, toggleable: true));
await tester.tap(tileFinder);
expect(changedValue, equals(2));
});
testWidgets(
'golden images',
(tester) async {
final variant = goldenVariant.currentValue!;
// ensure traditional focus highlight
FocusManager.instance.highlightStrategy =
FocusHighlightStrategy.alwaysTraditional;
await tester.pumpScaffold(
YaruRadioListTile<bool>(
autofocus: variant.hasState(MaterialState.focused),
value: variant.hasState(MaterialState.selected),
groupValue: true,
onChanged: variant.hasState(MaterialState.disabled) ? null : (_) {},
title: const Text('YaruRadioListTile'),
subtitle: const Text('Lorem ipsum dolor sit amet'),
),
themeMode: variant.themeMode,
size: const Size(325, 72),
);
await tester.pumpAndSettle();
if (variant.hasState(MaterialState.pressed)) {
await tester.down(find.byType(YaruRadio<bool>));
await tester.pumpAndSettle();
} else if (variant.hasState(MaterialState.hovered)) {
await tester.hover(find.byType(YaruRadio<bool>));
await tester.pumpAndSettle();
}
await expectLater(
find.byType(YaruRadioListTile<bool>),
matchesGoldenFile('goldens/yaru_radio_list_tile-${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,
}),
});