|
1 | 1 | import 'package:checks/checks.dart';
|
| 2 | +import 'package:collection/collection.dart'; |
2 | 3 | import 'package:flutter/material.dart';
|
3 | 4 | import 'package:flutter_test/flutter_test.dart';
|
4 | 5 | import 'package:zulip/widgets/text.dart';
|
@@ -169,6 +170,82 @@ void main() {
|
169 | 170 | check(bolderWght(900, by: 200)).equals(1000);
|
170 | 171 | });
|
171 | 172 |
|
| 173 | + group('bolderWghtTextStyle', () { |
| 174 | + Future<void> testBolderWghtTextStyle( |
| 175 | + String description, { |
| 176 | + required TextStyle Function(BuildContext context) makeStyle, |
| 177 | + bool platformRequestsBold = false, |
| 178 | + required double expectedWght, |
| 179 | + required FontWeight expectedFontWeight, |
| 180 | + }) async { |
| 181 | + testWidgets(description, (WidgetTester tester) async { |
| 182 | + tester.platformDispatcher.accessibilityFeaturesTestValue = |
| 183 | + FakeAccessibilityFeatures(boldText: platformRequestsBold); |
| 184 | + |
| 185 | + await tester.pumpWidget( |
| 186 | + MaterialApp( |
| 187 | + home: Builder(builder: (context) => |
| 188 | + Text('', style: makeStyle(context))))); |
| 189 | + |
| 190 | + final TextStyle? style = tester.widget<Text>(find.byType(Text)).style; |
| 191 | + |
| 192 | + check(style).isNotNull().fontWeight.isNotNull().equals(expectedFontWeight); |
| 193 | + |
| 194 | + final fontVariations = style!.fontVariations; |
| 195 | + check(fontVariations).isNotNull(); |
| 196 | + final wghtVariation = fontVariations!.singleWhereOrNull((v) => v.axis == 'wght'); |
| 197 | + check(wghtVariation).isNotNull().value.equals(expectedWght); |
| 198 | + |
| 199 | + tester.platformDispatcher.clearAccessibilityFeaturesTestValue(); |
| 200 | + }); |
| 201 | + } |
| 202 | + |
| 203 | + testBolderWghtTextStyle('default + default', |
| 204 | + makeStyle: (context) => bolderWghtTextStyle(weightVariableTextStyle(context)), |
| 205 | + expectedWght: 700, |
| 206 | + expectedFontWeight: FontWeight.w700); |
| 207 | + |
| 208 | + testBolderWghtTextStyle('default + default (platform requests bold)', |
| 209 | + platformRequestsBold: true, |
| 210 | + makeStyle: (context) => bolderWghtTextStyle(weightVariableTextStyle(context)), |
| 211 | + expectedWght: 1000, |
| 212 | + expectedFontWeight: FontWeight.w900); |
| 213 | + |
| 214 | + testBolderWghtTextStyle('320 + 200', |
| 215 | + makeStyle: (context) => bolderWghtTextStyle( |
| 216 | + weightVariableTextStyle(context, wght: 320), |
| 217 | + by: 200, |
| 218 | + ), |
| 219 | + expectedWght: 520, |
| 220 | + expectedFontWeight: FontWeight.w500); |
| 221 | + |
| 222 | + testBolderWghtTextStyle('320 + 200 (platform requests bold)', |
| 223 | + platformRequestsBold: true, |
| 224 | + makeStyle: (context) => bolderWghtTextStyle( |
| 225 | + weightVariableTextStyle(context, wght: 320), |
| 226 | + by: 200, |
| 227 | + ), |
| 228 | + expectedWght: 820, |
| 229 | + expectedFontWeight: FontWeight.w800); |
| 230 | + |
| 231 | + testBolderWghtTextStyle('320 + 200 (platform requests bold; custom response to setting)', |
| 232 | + platformRequestsBold: true, |
| 233 | + makeStyle: (context) => bolderWghtTextStyle( |
| 234 | + weightVariableTextStyle(context, wght: 320, wghtIfPlatformRequestsBold: 410), |
| 235 | + by: 200, |
| 236 | + ), |
| 237 | + expectedWght: 610, |
| 238 | + expectedFontWeight: FontWeight.w600); |
| 239 | + |
| 240 | + testBolderWghtTextStyle('900 + 200', |
| 241 | + makeStyle: (context) => bolderWghtTextStyle( |
| 242 | + weightVariableTextStyle(context, wght: 900), |
| 243 | + by: 200, |
| 244 | + ), |
| 245 | + expectedWght: 1000, |
| 246 | + expectedFontWeight: FontWeight.w900); |
| 247 | + }); |
| 248 | + |
172 | 249 | test('clampVariableFontWeight: FontWeight has the assumed list of values', () {
|
173 | 250 | // Implementation assumes specific FontWeight values; we should
|
174 | 251 | // adapt if these change in a new Flutter version.
|
|
0 commit comments