@@ -16,72 +16,84 @@ void main() {
16
16
TestZulipBinding .ensureInitialized ();
17
17
18
18
group ('ZulipWebUiKitButton' , () {
19
- final textScaleFactorVariants = ValueVariant (Set .of (kTextScaleFactors));
20
-
21
- testWidgets ('vertical outer padding is preserved as text scales' , (tester) async {
22
- addTearDown (testBinding.reset);
23
- tester.platformDispatcher.textScaleFactorTestValue = textScaleFactorVariants.currentValue! ;
24
- addTearDown (tester.platformDispatcher.clearTextScaleFactorTestValue);
25
-
26
- final buttonFinder = find.byType (ZulipWebUiKitButton );
27
-
28
- await tester.pumpWidget (TestZulipApp (
29
- child: UnconstrainedBox (
30
- child: ZulipWebUiKitButton (label: 'Cancel' , onPressed: () {}))));
31
- await tester.pump ();
32
-
33
- final element = tester.element (buttonFinder);
34
- final renderObject = element.renderObject as RenderBox ;
35
- final size = renderObject.size;
36
- check (size).height.equals (44 ); // includes outer padding
37
-
38
- final textScaler = TextScaler .linear (textScaleFactorVariants.currentValue! )
39
- .clamp (maxScaleFactor: 1.5 );
40
- final expectedButtonHeight = max (28.0 , // configured min height
41
- (textScaler.scale (17 ) * 1.20 ).roundToDouble () // text height
42
- + 4 + 4 ); // vertical padding
43
-
44
- // Rounded rectangle paints with the intended height…
45
- final expectedRRect = RRect .fromLTRBR (
46
- 0 , 0 , // zero relative to the position at this paint step
47
- size.width, expectedButtonHeight, Radius .circular (4 ));
48
- check (renderObject).legacyMatcher (
49
- // `paints` isn't a [Matcher] so we wrap it with `equals`;
50
- // awkward but it works
51
- equals (paints..drrect (outer: expectedRRect)));
52
-
53
- // …and that height leaves at least 4px for vertical outer padding.
54
- check (expectedButtonHeight).isLessOrEqual (44 - 2 - 2 );
55
- }, variant: textScaleFactorVariants);
56
-
57
- testWidgets ('vertical outer padding responds to taps, not just painted area' , (tester) async {
58
- addTearDown (testBinding.reset);
59
- tester.platformDispatcher.textScaleFactorTestValue = textScaleFactorVariants.currentValue! ;
60
- addTearDown (tester.platformDispatcher.clearTextScaleFactorTestValue);
61
-
62
- final buttonFinder = find.byType (ZulipWebUiKitButton );
63
-
64
- int numTapsHandled = 0 ;
65
- await tester.pumpWidget (TestZulipApp (
66
- child: UnconstrainedBox (
67
- child: ZulipWebUiKitButton (
68
- label: 'Cancel' ,
69
- onPressed: () => numTapsHandled++ ))));
70
- await tester.pump ();
71
-
72
- final element = tester.element (buttonFinder);
73
- final renderObject = element.renderObject as RenderBox ;
74
- final size = renderObject.size;
75
- check (size).height.equals (44 ); // includes outer padding
76
-
77
- // Outer padding responds to taps, not just the painted part.
78
- final buttonCenter = tester.getCenter (buttonFinder);
79
- int numTaps = 0 ;
80
- for (double y = - 22 ; y < 22 ; y++ ) {
81
- await tester.tapAt (buttonCenter + Offset (0 , y));
82
- numTaps++ ;
83
- }
84
- check (numTapsHandled).equals (numTaps);
85
- }, variant: textScaleFactorVariants);
19
+ void testVerticalOuterPadding ({required ZulipWebUiKitButtonSize sizeVariant}) {
20
+ final textScaleFactorVariants = ValueVariant (Set .of (kTextScaleFactors));
21
+ T forSizeVariant <T >(T small, T normal) =>
22
+ switch (sizeVariant) {
23
+ ZulipWebUiKitButtonSize .small => small,
24
+ ZulipWebUiKitButtonSize .normal => normal,
25
+ };
26
+
27
+ testWidgets ('vertical outer padding is preserved as text scales; $sizeVariant ' , (tester) async {
28
+ addTearDown (testBinding.reset);
29
+ tester.platformDispatcher.textScaleFactorTestValue = textScaleFactorVariants.currentValue! ;
30
+ addTearDown (tester.platformDispatcher.clearTextScaleFactorTestValue);
31
+
32
+ final buttonFinder = find.byType (ZulipWebUiKitButton );
33
+
34
+ await tester.pumpWidget (TestZulipApp (
35
+ child: UnconstrainedBox (
36
+ child: ZulipWebUiKitButton (
37
+ label: 'Cancel' ,
38
+ onPressed: () {},
39
+ size: sizeVariant))));
40
+ await tester.pump ();
41
+
42
+ final element = tester.element (buttonFinder);
43
+ final renderObject = element.renderObject as RenderBox ;
44
+ final size = renderObject.size;
45
+ check (size).height.equals (44 ); // includes outer padding
46
+
47
+ final textScaler = TextScaler .linear (textScaleFactorVariants.currentValue! )
48
+ .clamp (maxScaleFactor: 1.5 );
49
+ final expectedButtonHeight = max (forSizeVariant (24.0 , 28.0 ), // configured min height
50
+ (textScaler.scale (forSizeVariant (16 , 17 ) * forSizeVariant (1 , 1.20 )).roundToDouble () // text height
51
+ + 4 + 4 )); // vertical padding
52
+
53
+ // Rounded rectangle paints with the intended height…
54
+ final expectedRRect = RRect .fromLTRBR (
55
+ 0 , 0 , // zero relative to the position at this paint step
56
+ size.width, expectedButtonHeight, Radius .circular (forSizeVariant (6 , 4 )));
57
+ check (renderObject).legacyMatcher (
58
+ // `paints` isn't a [Matcher] so we wrap it with `equals`;
59
+ // awkward but it works
60
+ equals (paints..drrect (outer: expectedRRect)));
61
+
62
+ // …and that height leaves at least 4px for vertical outer padding.
63
+ check (expectedButtonHeight).isLessOrEqual (44 - 2 - 2 );
64
+ }, variant: textScaleFactorVariants);
65
+
66
+ testWidgets ('vertical outer padding responds to taps, not just painted area' , (tester) async {
67
+ addTearDown (testBinding.reset);
68
+ tester.platformDispatcher.textScaleFactorTestValue = textScaleFactorVariants.currentValue! ;
69
+ addTearDown (tester.platformDispatcher.clearTextScaleFactorTestValue);
70
+
71
+ final buttonFinder = find.byType (ZulipWebUiKitButton );
72
+
73
+ int numTapsHandled = 0 ;
74
+ await tester.pumpWidget (TestZulipApp (
75
+ child: UnconstrainedBox (
76
+ child: ZulipWebUiKitButton (
77
+ label: 'Cancel' ,
78
+ onPressed: () => numTapsHandled++ ))));
79
+ await tester.pump ();
80
+
81
+ final element = tester.element (buttonFinder);
82
+ final renderObject = element.renderObject as RenderBox ;
83
+ final size = renderObject.size;
84
+ check (size).height.equals (44 ); // includes outer padding
85
+
86
+ // Outer padding responds to taps, not just the painted part.
87
+ final buttonCenter = tester.getCenter (buttonFinder);
88
+ int numTaps = 0 ;
89
+ for (double y = - 22 ; y < 22 ; y++ ) {
90
+ await tester.tapAt (buttonCenter + Offset (0 , y));
91
+ numTaps++ ;
92
+ }
93
+ check (numTapsHandled).equals (numTaps);
94
+ }, variant: textScaleFactorVariants);
95
+ }
96
+ testVerticalOuterPadding (sizeVariant: ZulipWebUiKitButtonSize .small);
97
+ testVerticalOuterPadding (sizeVariant: ZulipWebUiKitButtonSize .normal);
86
98
});
87
99
}
0 commit comments