-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NOTE: To update golden images, run: ``` flutter test --update-goldens ```
- Loading branch information
Showing
36 changed files
with
203 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
tags: | ||
golden: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+589 Bytes
test/controls/goldens/yaru_icon_button-unselected-disabled-dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+571 Bytes
test/controls/goldens/yaru_icon_button-unselected-disabled-light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:yaru_icons/yaru_icons.dart'; | ||
import 'package:yaru_widgets/yaru_widgets.dart'; | ||
|
||
import '../yaru_golden_tester.dart'; | ||
|
||
void main() { | ||
testWidgets( | ||
'golden images', | ||
(tester) async { | ||
final variant = goldenVariant.currentValue!; | ||
|
||
// ensure traditional focus highlight | ||
FocusManager.instance.highlightStrategy = | ||
FocusHighlightStrategy.alwaysTraditional; | ||
|
||
await tester.pumpScaffold( | ||
YaruIconButton( | ||
autofocus: variant.hasState(MaterialState.focused), | ||
isSelected: variant.states[MaterialState.selected], | ||
onPressed: variant.hasState(MaterialState.disabled) ? null : () {}, | ||
icon: const Icon(YaruIcons.star_filled), | ||
), | ||
themeMode: variant.themeMode, | ||
size: const Size(40, 40), | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
if (variant.hasState(MaterialState.pressed)) { | ||
await tester.down(find.byType(YaruIconButton)); | ||
await tester.pumpAndSettle(); | ||
} else if (variant.hasState(MaterialState.hovered)) { | ||
await tester.hover(find.byType(YaruIconButton)); | ||
await tester.pumpAndSettle(); | ||
} | ||
|
||
await expectLater( | ||
find.byType(YaruIconButton), | ||
matchesGoldenFile('goldens/yaru_icon_button-${variant.label}.png'), | ||
); | ||
}, | ||
variant: goldenVariant, | ||
tags: 'golden', | ||
); | ||
} | ||
|
||
final goldenVariant = ValueVariant({ | ||
// normal (non-toggle) button | ||
...goldenThemeVariants('normal'), | ||
...goldenThemeVariants('disabled', {MaterialState.disabled: true}), | ||
...goldenThemeVariants('focused', {MaterialState.focused: true}), | ||
...goldenThemeVariants('hovered', {MaterialState.hovered: true}), | ||
...goldenThemeVariants('pressed', {MaterialState.pressed: true}), | ||
// selected toggle button | ||
...goldenThemeVariants('selected', {MaterialState.selected: true}), | ||
...goldenThemeVariants('selected-disabled', { | ||
MaterialState.selected: true, | ||
MaterialState.disabled: true, | ||
}), | ||
...goldenThemeVariants('selected-focused', { | ||
MaterialState.selected: true, | ||
MaterialState.focused: true, | ||
}), | ||
...goldenThemeVariants('selected-hovered', { | ||
MaterialState.selected: true, | ||
MaterialState.hovered: true, | ||
}), | ||
...goldenThemeVariants('selected-pressed', { | ||
MaterialState.selected: true, | ||
MaterialState.pressed: true, | ||
}), | ||
// unselected toggle button | ||
...goldenThemeVariants('unselected', {MaterialState.selected: false}), | ||
...goldenThemeVariants('unselected-disabled', { | ||
MaterialState.selected: false, | ||
MaterialState.disabled: true, | ||
}), | ||
...goldenThemeVariants('unselected-focused', { | ||
MaterialState.selected: false, | ||
MaterialState.focused: true, | ||
}), | ||
...goldenThemeVariants('unselected-hovered', { | ||
MaterialState.selected: false, | ||
MaterialState.hovered: true, | ||
}), | ||
...goldenThemeVariants('unselected-pressed', { | ||
MaterialState.selected: false, | ||
MaterialState.pressed: true, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:golden_toolkit/golden_toolkit.dart'; | ||
|
||
Future<void> testExecutable(FutureOr<void> Function() testMain) async { | ||
await loadAppFonts(); | ||
return testMain(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:flutter/gestures.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:yaru/yaru.dart'; | ||
|
||
extension YaruGoldenTester on WidgetTester { | ||
Future<void> pumpScaffold( | ||
Widget widget, { | ||
ThemeMode? themeMode, | ||
ThemeData? theme, | ||
ThemeData? darkTheme, | ||
Size? size, | ||
}) { | ||
binding.window.devicePixelRatioTestValue = 1; | ||
if (size != null) binding.window.physicalSizeTestValue = size; | ||
return pumpWidget( | ||
MaterialApp( | ||
themeMode: themeMode, | ||
theme: theme ?? yaruLight, | ||
darkTheme: darkTheme ?? yaruDark, | ||
home: Scaffold( | ||
body: Center(child: widget), | ||
), | ||
), | ||
); | ||
} | ||
|
||
Future<void> hover(Finder finder) async { | ||
final gesture = await createGesture(kind: PointerDeviceKind.mouse); | ||
await gesture.addPointer(); | ||
addTearDown(gesture.removePointer); | ||
await gesture.moveTo(getCenter(finder)); | ||
} | ||
|
||
Future<void> down(Finder finder) async { | ||
final gesture = await createGesture(kind: PointerDeviceKind.mouse); | ||
await gesture.addPointer(); | ||
addTearDown(gesture.removePointer); | ||
await gesture.down(getCenter(finder)); | ||
} | ||
} | ||
|
||
@immutable | ||
class YaruGoldenVariant { | ||
YaruGoldenVariant({ | ||
required String label, | ||
required this.themeMode, | ||
this.states = const {}, | ||
}) : label = '$label-${themeMode.name}'; | ||
|
||
final String label; | ||
final ThemeMode themeMode; | ||
final Map<MaterialState, bool> states; | ||
|
||
bool hasState(MaterialState state) => states[state] == true; | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
if (identical(this, other)) return true; | ||
final mapEquals = const MapEquality().equals; | ||
return other is YaruGoldenVariant && | ||
other.label == label && | ||
other.themeMode == themeMode && | ||
mapEquals(other.states, states); | ||
} | ||
|
||
@override | ||
int get hashCode { | ||
final mapHash = const MapEquality().hash; | ||
return Object.hash(label, themeMode, mapHash(states)); | ||
} | ||
|
||
@override | ||
String toString() => '$label: themeMode: $themeMode, states: $states'; | ||
} | ||
|
||
List<YaruGoldenVariant> goldenThemeVariants( | ||
String label, [ | ||
Map<MaterialState, bool> states = const {}, | ||
]) { | ||
return [ | ||
YaruGoldenVariant( | ||
label: label, | ||
themeMode: ThemeMode.light, | ||
states: states, | ||
), | ||
YaruGoldenVariant( | ||
label: label, | ||
themeMode: ThemeMode.dark, | ||
states: states, | ||
), | ||
]; | ||
} |