|
1 |
| - |
2 | 1 | import 'package:checks/checks.dart';
|
3 | 2 | import 'package:flutter/material.dart';
|
4 | 3 | import 'package:flutter_test/flutter_test.dart';
|
@@ -215,4 +214,57 @@ void main() {
|
215 | 214 | check(clampVariableFontWeight(999)) .equals(FontWeight.w900);
|
216 | 215 | check(clampVariableFontWeight(1000)) .equals(FontWeight.w900);
|
217 | 216 | });
|
| 217 | + |
| 218 | + group('proportionalLetterSpacing', () { |
| 219 | + Future<void> testLetterSpacing( |
| 220 | + String description, { |
| 221 | + required double Function(BuildContext context) getValue, |
| 222 | + double? ambientTextScaleFactor, |
| 223 | + required double expected, |
| 224 | + }) async { |
| 225 | + testWidgets(description, (WidgetTester tester) async { |
| 226 | + if (ambientTextScaleFactor != null) { |
| 227 | + tester.platformDispatcher.textScaleFactorTestValue = ambientTextScaleFactor; |
| 228 | + addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue); |
| 229 | + } |
| 230 | + await tester.pumpWidget( |
| 231 | + MaterialApp( |
| 232 | + home: Builder(builder: (context) => Text('', |
| 233 | + style: TextStyle(letterSpacing: getValue(context)))))); |
| 234 | + |
| 235 | + final TextStyle? style = tester.widget<Text>(find.byType(Text)).style; |
| 236 | + final actualLetterSpacing = style!.letterSpacing!; |
| 237 | + check((actualLetterSpacing - expected).abs()).isLessThan(0.0001); |
| 238 | + }); |
| 239 | + } |
| 240 | + |
| 241 | + testLetterSpacing('smoke 1', |
| 242 | + getValue: (context) => proportionalLetterSpacing(context, 0.01, baseFontSize: 14), |
| 243 | + expected: 0.14); |
| 244 | + |
| 245 | + testLetterSpacing('smoke 2', |
| 246 | + getValue: (context) => proportionalLetterSpacing(context, 0.02, baseFontSize: 16), |
| 247 | + expected: 0.32); |
| 248 | + |
| 249 | + for (final textScaleFactor in kTextScaleFactors) { |
| 250 | + testLetterSpacing('ambient text scale factor $textScaleFactor, no override', |
| 251 | + ambientTextScaleFactor: textScaleFactor, |
| 252 | + getValue: (context) => proportionalLetterSpacing(context, 0.01, baseFontSize: 14), |
| 253 | + expected: 0.14 * textScaleFactor); |
| 254 | + |
| 255 | + testLetterSpacing('ambient text scale factor $textScaleFactor, override with no scaling', |
| 256 | + ambientTextScaleFactor: textScaleFactor, |
| 257 | + getValue: (context) => proportionalLetterSpacing(context, |
| 258 | + 0.01, baseFontSize: 14, textScaler: TextScaler.noScaling), |
| 259 | + expected: 0.14); |
| 260 | + |
| 261 | + final clampingTextScaler = TextScaler.linear(textScaleFactor) |
| 262 | + .clamp(minScaleFactor: 0.9, maxScaleFactor: 1.1); |
| 263 | + testLetterSpacing('ambient text scale factor $textScaleFactor, override with clamping', |
| 264 | + ambientTextScaleFactor: textScaleFactor, |
| 265 | + getValue: (context) => proportionalLetterSpacing(context, |
| 266 | + 0.01, baseFontSize: 14, textScaler: clampingTextScaler), |
| 267 | + expected: clampingTextScaler.scale(14) * 0.01); |
| 268 | + } |
| 269 | + }); |
218 | 270 | }
|
0 commit comments