From 70bd793c859299635c12964a22de469b42d717c5 Mon Sep 17 00:00:00 2001 From: Corey Sprague Date: Mon, 30 Mar 2020 09:44:26 -0700 Subject: [PATCH 1/5] plumb in notions of safe area and platform brightness into device specification --- packages/golden_toolkit/lib/src/device.dart | 13 +++++++++++++ packages/golden_toolkit/test/device_test.dart | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/packages/golden_toolkit/lib/src/device.dart b/packages/golden_toolkit/lib/src/device.dart index 44f65e7..826482f 100644 --- a/packages/golden_toolkit/lib/src/device.dart +++ b/packages/golden_toolkit/lib/src/device.dart @@ -7,6 +7,7 @@ /// *************************************************** import 'dart:ui'; +import 'package:flutter/widgets.dart'; import 'package:meta/meta.dart'; /// This [Device] is a configuration for golden test. Can be provided for [multiScreenGolden] @@ -17,6 +18,8 @@ class Device { this.devicePixelRatio = 1.0, @required this.name, this.textScale = 1.0, + this.brightness = Brightness.light, + this.safeArea = const EdgeInsets.all(0), }); /// [phone] one of the smallest phone screens @@ -43,18 +46,28 @@ class Device { /// [textScale] specify custom text scale final double textScale; + /// [brightness] specify platform brightness + final Brightness brightness; + + /// [safeArea] specify insets to define a safe area + final EdgeInsets safeArea; + /// [copyWith] convenience function for [Device] modification Device copyWith({ Size size, double devicePixelRatio, String name, double textScale, + Brightness brightness, + EdgeInsets safeArea, }) { return Device( size: size ?? this.size, devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, name: name ?? this.name, textScale: textScale ?? this.textScale, + brightness: brightness ?? this.brightness, + safeArea: safeArea ?? this.safeArea, ); } } diff --git a/packages/golden_toolkit/test/device_test.dart b/packages/golden_toolkit/test/device_test.dart index f1ed48c..a2836c8 100644 --- a/packages/golden_toolkit/test/device_test.dart +++ b/packages/golden_toolkit/test/device_test.dart @@ -8,6 +8,7 @@ /// import 'dart:ui'; +import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:golden_toolkit/golden_toolkit.dart'; @@ -20,6 +21,8 @@ void main() { expect(copied.name, equals(Device.phone.name)); expect(copied.size, equals(Device.phone.size)); expect(copied.textScale, equals(Device.phone.textScale)); + expect(copied.brightness, equals(Device.phone.brightness)); + expect(copied.safeArea, equals(Device.phone.safeArea)); }); test('copy with parameters', () { @@ -28,11 +31,15 @@ void main() { devicePixelRatio: 2.0, name: 'foo', size: const Size(100, 100), + brightness: Brightness.dark, + safeArea: const EdgeInsets.symmetric(vertical: 16), ); expect(copied.devicePixelRatio, equals(2.0)); expect(copied.name, equals('foo')); expect(copied.size, equals(const Size(100, 100))); expect(copied.textScale, equals(3.0)); + expect(copied.brightness, equals(Brightness.dark)); + expect(copied.safeArea, equals(const EdgeInsets.symmetric(vertical: 16))); }); }); } From cddc56e42aaf048944d649539c1b246558ead845 Mon Sep 17 00:00:00 2001 From: Corey Sprague Date: Mon, 30 Mar 2020 10:02:56 -0700 Subject: [PATCH 2/5] build in safe area support for goldens --- .../lib/src/multi_screen_golden.dart | 27 ++++++++++++++++++ .../test/goldens/safe_area.no_safe_area.png | Bin 0 -> 623 bytes .../test/goldens/safe_area.safe_area.png | Bin 0 -> 651 bytes .../test/multi_screen_golden_test.dart | 19 ++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 packages/golden_toolkit/test/goldens/safe_area.no_safe_area.png create mode 100644 packages/golden_toolkit/test/goldens/safe_area.safe_area.png diff --git a/packages/golden_toolkit/lib/src/multi_screen_golden.dart b/packages/golden_toolkit/lib/src/multi_screen_golden.dart index 6ee444b..e2f1b5d 100644 --- a/packages/golden_toolkit/lib/src/multi_screen_golden.dart +++ b/packages/golden_toolkit/lib/src/multi_screen_golden.dart @@ -61,6 +61,12 @@ Future multiScreenGolden( tester.binding.window.physicalSizeTestValue = device.size; tester.binding.window.devicePixelRatioTestValue = device.devicePixelRatio; tester.binding.window.textScaleFactorTestValue = device.textScale; + tester.binding.window.paddingTestValue = _FakeWindowPadding( + bottom: device.safeArea.bottom, + left: device.safeArea.left, + right: device.safeArea.right, + top: device.safeArea.top, + ); await deviceSetup(device, tester); await screenMatchesGolden( tester, @@ -71,3 +77,24 @@ Future multiScreenGolden( ); } } + +class _FakeWindowPadding implements WindowPadding { + const _FakeWindowPadding({ + this.bottom = 0, + this.left = 0, + this.right = 0, + this.top = 0, + }); + + @override + final double bottom; + + @override + final double left; + + @override + final double right; + + @override + final double top; +} diff --git a/packages/golden_toolkit/test/goldens/safe_area.no_safe_area.png b/packages/golden_toolkit/test/goldens/safe_area.no_safe_area.png new file mode 100644 index 0000000000000000000000000000000000000000..512de1b4066317e5e75faf9ef0924a38edbe9a15 GIT binary patch literal 623 zcmeAS@N?(olHy`uVBq!ia0vp^CqS5k4M?tyST_$yF%}28J29*~C-V}>VJUX<4B-HR z8jh3>1_mZcPZ!6KiaBpD8wxfUFdR4#q;A?9$P&Q3ca6ax?Gux-@1D1ASp2h;;m=G* j1qqg>QDTII!6CLvClohiH5<`)z4*}Q$iB}jNyp> literal 0 HcmV?d00001 diff --git a/packages/golden_toolkit/test/goldens/safe_area.safe_area.png b/packages/golden_toolkit/test/goldens/safe_area.safe_area.png new file mode 100644 index 0000000000000000000000000000000000000000..171ea716ce851031f368a49cd7ee333a268cb12a GIT binary patch literal 651 zcmeAS@N?(olHy`uVBq!ia0vp^CqS5k4M?tyST_$yF%}28J29*~C-V}>VJUX<4B-HR z8jh3>1_mZmPZ!6KiaBquZsa}WAmHlQ!?CjI-HH=;16w~YWqi%*af~nR&}6?~Cok(6 z8=EIw|NDlqAeE_6L4X5|=-+$%`mVp#>@v?j*Zuo*ofV4`G##T{j6kG!kZd?}W{xe> fx>F>^)(6(#t9UwZzI0#*CMX6^S3j3^P6 main() async { skip: !Platform.isMacOS, ); }); + + testGoldens('Safe Area test', (tester) async { + await tester.pumpWidgetBuilder( + Container( + color: Colors.white, + child: SafeArea(child: Container(color: Colors.blue))), + ); + await multiScreenGolden(tester, 'safe_area', devices: [ + const Device( + name: 'no_safe_area', + size: Size(200, 200), + ), + const Device( + name: 'safe_area', + size: Size(200, 200), + safeArea: EdgeInsets.fromLTRB(5, 10, 15, 20), + ) + ]); + }); }); }); } From 08f1ed651d0cb23af1f8d9342d58e25863333840 Mon Sep 17 00:00:00 2001 From: Corey Sprague Date: Mon, 30 Mar 2020 10:09:32 -0700 Subject: [PATCH 3/5] add golden test showing dark mode support --- .../lib/src/multi_screen_golden.dart | 1 + .../test/goldens/brightness.dark.png | Bin 0 -> 2759 bytes .../test/goldens/brightness.light.png | Bin 0 -> 2663 bytes .../test/multi_screen_golden_test.dart | 26 ++++++++++++++++++ 4 files changed, 27 insertions(+) create mode 100644 packages/golden_toolkit/test/goldens/brightness.dark.png create mode 100644 packages/golden_toolkit/test/goldens/brightness.light.png diff --git a/packages/golden_toolkit/lib/src/multi_screen_golden.dart b/packages/golden_toolkit/lib/src/multi_screen_golden.dart index e2f1b5d..79b251c 100644 --- a/packages/golden_toolkit/lib/src/multi_screen_golden.dart +++ b/packages/golden_toolkit/lib/src/multi_screen_golden.dart @@ -67,6 +67,7 @@ Future multiScreenGolden( right: device.safeArea.right, top: device.safeArea.top, ); + tester.binding.window.platformBrightnessTestValue = device.brightness; await deviceSetup(device, tester); await screenMatchesGolden( tester, diff --git a/packages/golden_toolkit/test/goldens/brightness.dark.png b/packages/golden_toolkit/test/goldens/brightness.dark.png new file mode 100644 index 0000000000000000000000000000000000000000..e44c1380d61fab66fdcb9159e3987bd00424df03 GIT binary patch literal 2759 zcmeH}i#t?XAIFtWIix(Na8lu%25%90&ydTwu>`I^|NxD9tblIX#*q#1V#Z zi@Aa(j@ALic9pmT#mz7qM zmXMH;Mc7)QK;OEzOC1EqQa466==KGp;1&{$&Qr7C}k&ytF$aD!oLSi*vAFYjvqK{pd~jI_aU{Q*}eQt1;I(tMKO@jQ-k-Pr*W*? zeV(P>oN`kbtSKvtaX53#4K92^JS_LU`$$`&B)KUn_)(MK!(H{i@UJh7;=5YdCvpV* z;QB7nc0`vUgx%k7FVk3iD&&FWBUZX)(uc9v7P*O_+1S_|PiRrh)K!R`onsfry2tPZ zXb+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dAJZ4{!u?0C(=aeQL^w1k1)y4uX~J*2>(*<0%l6^{&0fCGB6nWa?e9wvOK1+5*9nZ?5{H zzTPxGF76Af>kn{^@U?N@3xM4d7+lo)zwo2VxMsb zB(hWJ7)?a3S}Nh5M+WBM3Z0Ej+9w(Pm(0<6s56wkY2u_epPcU{rw z`I(-VplUU<152Z<>4oPI@yZH>XTadoV`6?jZ5Dww4q58|qYHLscIc42iHXTnrLULQ zOx+sKnLwxjOAs%y1b!RBNjuTU>uqX0A(>2O4-XeFEd}a9p{?^`b;hnD%EbkO*xcC? z5H^I~AiMA}?YYfqhOI0X>)6Gi)ba6g%)Dr8d#DPZ15-{wp-}f%W}Hr&K6HyRH%BvZ zu8?1x+}){$>K-hL5lNU&qtjC|GfR4VQ5EIo04hvfU7gXr3ELYdlb$~Z$>L5R5QLptbtbeh~iZps^OYDYuIEz>XiWRl2$`2s8|bdwUlcsw1+pvi2+koPlz7 zcEw-{9siST@V75d%BONMS`pWcG~3SCsb9BnpgUVzTLYc#9<~O3GsW(%^TGt|d1eCx zM8zJ2`T1VF@aC+Pau>6!r<9a>L4fP&>#GB(0N{>lYHC9j{@gr@uD(7E*hEc(zw#OX z%og%HxWT(Uwc|vr%}e*nfWg{!*5E*Ye}AU;`En0nTWyLzq8{2j>b(rl`xAt`O8Ck@ zm3Tg5Yl*e@Spg(vT*TKGOuoZ1uHmZ0eaGp2r1qPl=*n*5Xop$C`-Zn(zKINm_V(sH zQ~JRE&#kT9$B?kx_>&j4oAaWKeGr|hNy!unW!>WNdgS}v#}Wtk?>l^8|F2R9F33q; uSCwltSA7&^E+HB9@4&y3{9hQxB99s*j$F0wehYp^B@osQRt$^lfBg^Fmho5s literal 0 HcmV?d00001 diff --git a/packages/golden_toolkit/test/goldens/brightness.light.png b/packages/golden_toolkit/test/goldens/brightness.light.png new file mode 100644 index 0000000000000000000000000000000000000000..74cbc80460d2218370ecd718d12c309fcf68d1cb GIT binary patch literal 2663 zcmeHJi#yYO8()e%is~&X5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Opr7K&HEgI*6Ajl%uR3jQW8^7RqLD^ zQ6Oo3&$7yVbN7I&yE`}cAh`FYPR9DAkW*Jz2e7YHk2^BrJks8_T6X4gqFCq+8~8Tb zOb_c+($~{7IC;`RCw)1~so=;NVPKnm)$gw-UqtqmtIJzq_fK`ZKI zYmTpmU}h+Ex*wTL#wp~ItEw*Svsu3+-uho8Kt_DEP4Oc@bm|O!YFzLWX-n4bB%9#B zE_o>`D!O`j_(ws}+et zSzyIiVR=%QHK(%EVYl_7N1Gy;vc*Kpt|FQqKwOl;dFZs?t*bcMBZP0+{q0wmZXcWot$lf{nNJ##? z?xRPK@L2wf-D<}^p691y{7MgAep_%)Z(;0}XB3C1EtUY>UuX^i)Zy^YfsY$duh8qu zlSoDac>=cca#01p2}XtuM~y`tv(RCi2Qo_aln;uR4Q z!O{|IF+w*nPqMC!GyNbCNKap%pTVJl9Gwix=H{l2nTLzZk!9V3V2`0%Qbs+{!wY*f zOovKCGwNhZEEa#BTA3;3oOCYo4GAIoKMSlX1|%vItTC1HGf@yN-;h|QufI5K8bpzb z1TkOU_eCJ;JZ+?olh;4-FmO12 zm>T?4B;Y)K{Matb&TgO8vK?!r%W^wV*0lisOLg_e(b~aU&zNtY8s~&UuY`oAfq{Vs z1VY2~hth6b0YCv&9h)G4Kly1MKg!WErKYbhVIlYCbZS~A3U77iTMTo#C4p8q#A305t!=1Jjaxr}Z$A|3DIllql3`Rf zX?dIRQ2u3@8OGNI?%)DfC#^4sji>N&$fheWQupI+3sqHBBpqGyLxrJBZ9agwtL##E z^$m7Bu2Ac+@^a{#?cF=}?ov3SyzBISzPI8yB|-ToVqLA472 literal 0 HcmV?d00001 diff --git a/packages/golden_toolkit/test/multi_screen_golden_test.dart b/packages/golden_toolkit/test/multi_screen_golden_test.dart index 0b10589..ea3f71e 100644 --- a/packages/golden_toolkit/test/multi_screen_golden_test.dart +++ b/packages/golden_toolkit/test/multi_screen_golden_test.dart @@ -72,6 +72,32 @@ Future main() async { ) ]); }); + + testGoldens('Platform Brightness Test', (tester) async { + await tester.pumpWidgetBuilder( + Builder( + builder: (context) => Container( + color: + MediaQuery.of(context).platformBrightness == Brightness.dark + ? Colors.grey + : Colors.white, + child: Text(MediaQuery.of(context).platformBrightness.toString()), + ), + ), + ); + await multiScreenGolden(tester, 'brightness', devices: [ + const Device( + name: 'light', + size: Size(200, 200), + brightness: Brightness.light, + ), + const Device( + name: 'dark', + size: Size(200, 200), + brightness: Brightness.dark, + ) + ]); + }); }); }); } From 0c1242d4952c088111a30865612e90f47c656d06 Mon Sep 17 00:00:00 2001 From: Corey Sprague Date: Mon, 30 Mar 2020 10:10:58 -0700 Subject: [PATCH 4/5] rev version # --- packages/golden_toolkit/CHANGELOG.md | 4 ++++ packages/golden_toolkit/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/golden_toolkit/CHANGELOG.md b/packages/golden_toolkit/CHANGELOG.md index 8ce2a6e..a81c600 100644 --- a/packages/golden_toolkit/CHANGELOG.md +++ b/packages/golden_toolkit/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.3.0 + +Add support for configuring safe area (to simulate a device notch) and platform brightness (light/dark mode) on a multiScreenGolden device. + ## 0.2.3 Breaking: Removed Future return type from `testGoldens`. diff --git a/packages/golden_toolkit/pubspec.yaml b/packages/golden_toolkit/pubspec.yaml index 6f6557f..f67c603 100644 --- a/packages/golden_toolkit/pubspec.yaml +++ b/packages/golden_toolkit/pubspec.yaml @@ -1,6 +1,6 @@ name: golden_toolkit description: Common patterns for screenshot-based widget testing using Goldens. -version: 0.2.3 +version: 0.3.0 homepage: https://github.com/eBay/flutter_glove_box/ repository: https://github.com/eBay/flutter_glove_box/tree/master/packages/golden_toolkit issue_tracker: https://github.com/eBay/flutter_glove_box/issues From 7fa8d1434bc47e0fd1fdd66476b6fa208c093507 Mon Sep 17 00:00:00 2001 From: Corey Sprague Date: Mon, 30 Mar 2020 10:17:10 -0700 Subject: [PATCH 5/5] skip goldens in linux --- .../test/multi_screen_golden_test.dart | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/packages/golden_toolkit/test/multi_screen_golden_test.dart b/packages/golden_toolkit/test/multi_screen_golden_test.dart index ea3f71e..3547901 100644 --- a/packages/golden_toolkit/test/multi_screen_golden_test.dart +++ b/packages/golden_toolkit/test/multi_screen_golden_test.dart @@ -60,17 +60,22 @@ Future main() async { color: Colors.white, child: SafeArea(child: Container(color: Colors.blue))), ); - await multiScreenGolden(tester, 'safe_area', devices: [ - const Device( - name: 'no_safe_area', - size: Size(200, 200), - ), - const Device( - name: 'safe_area', - size: Size(200, 200), - safeArea: EdgeInsets.fromLTRB(5, 10, 15, 20), - ) - ]); + await multiScreenGolden( + tester, + 'safe_area', + devices: [ + const Device( + name: 'no_safe_area', + size: Size(200, 200), + ), + const Device( + name: 'safe_area', + size: Size(200, 200), + safeArea: EdgeInsets.fromLTRB(5, 10, 15, 20), + ) + ], + skip: !Platform.isMacOS, + ); }); testGoldens('Platform Brightness Test', (tester) async { @@ -85,18 +90,23 @@ Future main() async { ), ), ); - await multiScreenGolden(tester, 'brightness', devices: [ - const Device( - name: 'light', - size: Size(200, 200), - brightness: Brightness.light, - ), - const Device( - name: 'dark', - size: Size(200, 200), - brightness: Brightness.dark, - ) - ]); + await multiScreenGolden( + tester, + 'brightness', + devices: [ + const Device( + name: 'light', + size: Size(200, 200), + brightness: Brightness.light, + ), + const Device( + name: 'dark', + size: Size(200, 200), + brightness: Brightness.dark, + ) + ], + skip: !Platform.isMacOS, + ); }); }); });