Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YaruRadioButton: add golden test #330

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
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,
}),
});