Skip to content

Commit

Permalink
YaruRadioButton: add golden test (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnurmi committed Oct 24, 2022
1 parent 463c13e commit d41e2f0
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions test/controls/yaru_radio_button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

import '../yaru_golden_tester.dart';

void main() {
testWidgets('contains radio and labels', (tester) async {
Widget builder({required Widget title, required Widget? subtitle}) {
Expand Down Expand Up @@ -141,4 +143,69 @@ void main() {
equals(Theme.of(disabled).disabledColor),
);
});

testWidgets(
'golden images',
(tester) async {
final variant = goldenVariant.currentValue!;

// ensure traditional focus highlight
FocusManager.instance.highlightStrategy =
FocusHighlightStrategy.alwaysTraditional;

await tester.pumpScaffold(
YaruRadioButton<bool>(
autofocus: variant.hasState(MaterialState.focused),
value: variant.hasState(MaterialState.selected),
groupValue: true,
onChanged: variant.hasState(MaterialState.disabled) ? null : (_) {},
title: const Text('YaruRadioButton'),
subtitle: const Text('Lorem ipsum dolor sit amet'),
),
themeMode: variant.themeMode,
size: const Size(224, 56),
);
await tester.pumpAndSettle();

if (variant.hasState(MaterialState.pressed)) {
await tester.down(find.byType(Radio<bool>));
await tester.pumpAndSettle();
} else if (variant.hasState(MaterialState.hovered)) {
await tester.hover(find.byType(Radio<bool>));
await tester.pumpAndSettle();
}

await expectLater(
find.byType(YaruRadioButton<bool>),
matchesGoldenFile('goldens/yaru_radio_button-${variant.label}.png'),
);
},
variant: goldenVariant,
tags: 'golden',
);
}

final goldenVariant = ValueVariant({
...goldenThemeVariants('unchecked', <MaterialState>{}),
...goldenThemeVariants('unckecked-disabled', {MaterialState.disabled}),
...goldenThemeVariants('unckecked-focused', {MaterialState.focused}),
...goldenThemeVariants('unckecked-hovered', {MaterialState.hovered}),
...goldenThemeVariants('unckecked-pressed', {MaterialState.pressed}),
...goldenThemeVariants('checked', {MaterialState.selected}),
...goldenThemeVariants('checked-disabled', {
MaterialState.selected,
MaterialState.disabled,
}),
...goldenThemeVariants('checked-focused', {
MaterialState.selected,
MaterialState.focused,
}),
...goldenThemeVariants('checked-hovered', {
MaterialState.selected,
MaterialState.hovered,
}),
...goldenThemeVariants('checked-pressed', {
MaterialState.selected,
MaterialState.pressed,
}),
});

0 comments on commit d41e2f0

Please sign in to comment.