From f894edebff62638cbd49eb93fabed2c2a5543b67 Mon Sep 17 00:00:00 2001 From: xster Date: Fri, 3 Mar 2017 14:30:33 -0800 Subject: [PATCH] Use exact Ahem and exact dimensions for Cupertino button test (#8561) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use exact Ahem and exact dimensions for test * use ‘px’ everywhere --- .../flutter/lib/src/cupertino/button.dart | 2 +- .../flutter/test/cupertino/button_test.dart | 34 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/packages/flutter/lib/src/cupertino/button.dart b/packages/flutter/lib/src/cupertino/button.dart index f3094a894d..7a52af5a80 100644 --- a/packages/flutter/lib/src/cupertino/button.dart +++ b/packages/flutter/lib/src/cupertino/button.dart @@ -24,7 +24,7 @@ final TextStyle _kBackgroundButtonTextStyle = _kButtonTextStyle.copyWith( const EdgeInsets _kButtonPadding = const EdgeInsets.all(16.0); const EdgeInsets _kBackgroundButtonPadding = -const EdgeInsets.symmetric(vertical: 16.0, horizontal: 64.0); + const EdgeInsets.symmetric(vertical: 16.0, horizontal: 64.0); /// An iOS style button. /// diff --git a/packages/flutter/test/cupertino/button_test.dart b/packages/flutter/test/cupertino/button_test.dart index 3a4d329adb..f8a76d2b00 100644 --- a/packages/flutter/test/cupertino/button_test.dart +++ b/packages/flutter/test/cupertino/button_test.dart @@ -7,56 +7,66 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; +const TextStyle testStyle = const TextStyle( + fontFamily: 'Ahem', + fontSize: 10.0, +); + void main() { testWidgets('Layout minimum size', (WidgetTester tester) async { await tester.pumpWidget( - new Center(child: new CupertinoButton(child: new Text(' '), onPressed: null)) + new Center(child: new CupertinoButton( + child: new Text('X', style: testStyle), + onPressed: null, + )) ); RenderBox buttonBox = tester.renderObject(find.byType(CupertinoButton)); expect( buttonBox.size, - greaterThanOrEqualTo(const Size.square(48.0)), - ); - expect( - buttonBox.size, - lessThan(const Size.square(100.0)), + // 1 10px character + 16px * 2 is smaller than the 48px minimum. + const Size.square(48.0), ); }); testWidgets('Size grows with text', (WidgetTester tester) async { await tester.pumpWidget( - new Center(child: new CupertinoButton(child: new Text('blah blah blah'), onPressed: null)) + new Center(child: new CupertinoButton( + child: new Text('XXXX', style: testStyle), + onPressed: null, + )) ); RenderBox buttonBox = tester.renderObject(find.byType(CupertinoButton)); expect( buttonBox.size.width, - greaterThan(48.0), + // 4 10px character + 16px * 2 = 72. + 72.0, ); }); testWidgets('Button with background is wider', (WidgetTester tester) async { await tester.pumpWidget(new Center(child: new CupertinoButton( - child: new Text(' '), + child: new Text('X', style: testStyle), onPressed: null, color: new Color(0xFFFFFFFF), ))); RenderBox buttonBox = tester.renderObject(find.byType(CupertinoButton)); expect( buttonBox.size.width, - greaterThan(120.0), + // 1 10px character + 64 * 2 = 138 for buttons with background. + 138.0, ); }); testWidgets('Custom padding', (WidgetTester tester) async { await tester.pumpWidget(new Center(child: new CupertinoButton( - child: new Text(' '), + child: new Text(' ', style: testStyle), onPressed: null, padding: new EdgeInsets.all(100.0), ))); RenderBox buttonBox = tester.renderObject(find.byType(CupertinoButton)); expect( buttonBox.size, - greaterThan(const Size.square(100.0)), + const Size.square(210.0), ); });