Skip to content

Commit

Permalink
optimized test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecoomber committed Oct 16, 2024
1 parent 56053ac commit 1e7e0cd
Show file tree
Hide file tree
Showing 32 changed files with 455 additions and 340 deletions.
47 changes: 26 additions & 21 deletions lib/src/components/top_app_bar/top_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class ZetaTopAppBar extends ZetaStatefulWidget implements PreferredSizeWidget {
/// The semantic label for the microphone icon.
final String? microphoneSemanticLabel;

/// The semantic label for the search icon.
final String? searchSemanticLabel;

/// The semantic label for the back icon when search is open.
Expand All @@ -176,7 +177,11 @@ class ZetaTopAppBar extends ZetaStatefulWidget implements PreferredSizeWidget {
..add(DiagnosticsProperty<ZetaSearchController?>('searchController', searchController))
..add(StringProperty('searchHintText', searchHintText))
..add(EnumProperty<ZetaTopAppBarType>('type', type))
..add(DiagnosticsProperty<bool>('shrinks', shrinks));
..add(DiagnosticsProperty<bool>('shrinks', shrinks))
..add(StringProperty('clearSemanticLabel', clearSemanticLabel))
..add(StringProperty('microphoneSemanticLabel', microphoneSemanticLabel))
..add(StringProperty('searchSemanticLabel', searchSemanticLabel))
..add(StringProperty('searchBackSemanticLabel', searchBackSemanticLabel));
}
}

Expand All @@ -192,7 +197,7 @@ class _ZetaTopAppBarState extends State<ZetaTopAppBar> {
super.initState();
}

Widget _getTitleText(ZetaColors colors) {
Widget _getTitle(ZetaColors colors) {
Widget? title = widget.title;
if (widget.title is Row) {
final oldRow = widget.title! as Row;
Expand Down Expand Up @@ -279,9 +284,10 @@ class _ZetaTopAppBarState extends State<ZetaTopAppBar> {
@override
Widget build(BuildContext context) {
final colors = Zeta.of(context).colors;
final spacing = Zeta.of(context).spacing;

final actions = _getActions(colors);
final titleText = _getTitleText(colors);
final titleText = _getTitle(colors);

final title = widget.searchController != null
? ZetaTopAppBarSearchField(
Expand Down Expand Up @@ -321,24 +327,23 @@ class _ZetaTopAppBarState extends State<ZetaTopAppBar> {

return ZetaRoundedScope(
rounded: context.rounded,
child: ColoredBox(
color: colors.surfacePrimary,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: Zeta.of(context).spacing.minimum),
child: AppBar(
elevation: 0,
scrolledUnderElevation: 0,
iconTheme: IconThemeData(color: colors.iconDefault),
leading: leading,
automaticallyImplyLeading: widget.automaticallyImplyLeading,
surfaceTintColor: Colors.transparent,
centerTitle: widget.type == ZetaTopAppBarType.centered,
titleTextStyle: widget.titleTextStyle == null
? ZetaTextStyles.bodyLarge.copyWith(color: colors.textDefault)
: widget.titleTextStyle!.copyWith(color: colors.textDefault),
title: title,
actions: actions,
),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: spacing.minimum),
child: AppBar(
elevation: 0,
scrolledUnderElevation: 0,
backgroundColor: colors.surfacePrimary,
iconTheme: IconThemeData(color: colors.iconDefault),
leading: leading,
toolbarHeight: spacing.xl_9,
automaticallyImplyLeading: widget.automaticallyImplyLeading,
surfaceTintColor: Colors.transparent,
centerTitle: widget.type == ZetaTopAppBarType.centered,
titleTextStyle: widget.titleTextStyle == null
? ZetaTextStyles.bodyLarge.copyWith(color: colors.textDefault)
: widget.titleTextStyle!.copyWith(color: colors.textDefault),
title: title,
actions: actions,
),
),
);
Expand Down
6 changes: 0 additions & 6 deletions test/src/components/avatar/avatar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ void main() {
ZetaAvatar(
size: size,
),
ZetaAvatar,
'avatar_default_${size.toString().split('.').last}',
);
goldenTest(
Expand All @@ -331,7 +330,6 @@ void main() {
initials: 'AB',
size: size,
),
ZetaAvatar,
'avatar_initials_${size.toString().split('.').last}',
);
goldenTest(
Expand All @@ -340,7 +338,6 @@ void main() {
image: Image.file(File('/assets/maxresdefault.jpg')),
size: size,
),
ZetaAvatar,
'avatar_image_${size.toString().split('.').last}',
);
goldenTest(
Expand All @@ -349,7 +346,6 @@ void main() {
name: 'John Doe',
size: size,
),
ZetaAvatar,
'avatar_from_name_${size.toString().split('.').last}',
);
goldenTest(
Expand All @@ -358,7 +354,6 @@ void main() {
upperBadge: const ZetaAvatarBadge.notification(value: 3),
size: size,
),
ZetaAvatar,
'avatar_upper_badge_${size.toString().split('.').last}',
);
goldenTest(
Expand All @@ -367,7 +362,6 @@ void main() {
lowerBadge: const ZetaAvatarBadge.icon(icon: Icons.star),
size: size,
),
ZetaAvatar,
'avatar_lower_badge_${size.toString().split('.').last}',
);
}
Expand Down
8 changes: 3 additions & 5 deletions test/src/components/badge/indicator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ void main() {
group('Styling Tests', () {});
group('Interaction Tests', () {});
group('Golden Tests', () {
goldenTest(goldenFile, const ZetaIndicator(), ZetaIndicator, 'indicator_default');
goldenTest(goldenFile, const ZetaIndicator.icon(), ZetaIndicator, 'indicator_icon_default');
goldenTest(goldenFile, const ZetaIndicator(), 'indicator_default');
goldenTest(goldenFile, const ZetaIndicator.icon(), 'indicator_icon_default');
goldenTest(
goldenFile,
const ZetaIndicator.icon(
Expand All @@ -167,10 +167,9 @@ void main() {
inverse: true,
size: ZetaWidgetSize.medium,
),
ZetaIndicator,
'indicator_icon_values',
);
goldenTest(goldenFile, const ZetaIndicator.notification(), ZetaIndicator, 'indicator_notification_default');
goldenTest(goldenFile, const ZetaIndicator.notification(), 'indicator_notification_default');
goldenTest(
goldenFile,
const ZetaIndicator.notification(
Expand All @@ -180,7 +179,6 @@ void main() {
size: ZetaWidgetSize.small,
value: 1,
),
ZetaIndicator,
'indicator_notification_values',
);
});
Expand Down
10 changes: 3 additions & 7 deletions test/src/components/badge/label_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,33 +104,29 @@ void main() {
group('Styling Tests', () {});
group('Interaction Tests', () {});
group('Golden Tests', () {
goldenTest(goldenFile, const ZetaLabel(label: 'Test Label'), ZetaLabel, 'label_default');
goldenTest(goldenFile, const ZetaLabel(label: 'Test Label'), 'label_default');
goldenTest(
goldenFile,
const ZetaLabel(label: 'Test Label', status: ZetaWidgetStatus.positive),
ZetaLabel,
'label_positive',
);
goldenTest(
goldenFile,
const ZetaLabel(label: 'Test Label', status: ZetaWidgetStatus.warning),
ZetaLabel,
'label_warning',
);
goldenTest(
goldenFile,
const ZetaLabel(label: 'Test Label', status: ZetaWidgetStatus.negative),
ZetaLabel,
'label_negative',
);
goldenTest(
goldenFile,
const ZetaLabel(label: 'Test Label', status: ZetaWidgetStatus.neutral),
ZetaLabel,
'label_neutral',
);
goldenTest(goldenFile, const ZetaLabel(label: 'Test Label'), ZetaLabel, 'label_dark', themeMode: ThemeMode.dark);
goldenTest(goldenFile, const ZetaLabel(label: 'Test Label', rounded: false), ZetaLabel, 'label_sharp');
goldenTest(goldenFile, const ZetaLabel(label: 'Test Label'), 'label_dark', themeMode: ThemeMode.dark);
goldenTest(goldenFile, const ZetaLabel(label: 'Test Label', rounded: false), 'label_sharp');
});
group('Performance Tests', () {});
}
5 changes: 1 addition & 4 deletions test/src/components/badge/priority_pill_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void main() {
group('Styling Tests', () {});
group('Interaction Tests', () {});
group('Golden Tests', () {
goldenTest(goldenFile, const ZetaPriorityPill(), ZetaPriorityPill, 'priority_pill_default');
goldenTest(goldenFile, const ZetaPriorityPill(), 'priority_pill_default');
goldenTest(
goldenFile,
const ZetaPriorityPill(
Expand All @@ -131,7 +131,6 @@ void main() {
rounded: false,
size: ZetaPriorityPillSize.small,
),
ZetaPriorityPill,
'priority_pill_high',
);
goldenTest(
Expand All @@ -140,7 +139,6 @@ void main() {
type: ZetaPriorityPillType.medium,
isBadge: true,
),
ZetaPriorityPill,
'priority_pill_medium',
);
goldenTest(
Expand All @@ -150,7 +148,6 @@ void main() {
size: ZetaPriorityPillSize.small,
isBadge: true,
),
ZetaPriorityPill,
'priority_pill_low',
);
});
Expand Down
3 changes: 1 addition & 2 deletions test/src/components/badge/status_label_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ void main() {
group('Styling Tests', () {});
group('Interaction Tests', () {});
group('Golden Tests', () {
goldenTest(goldenFile, const ZetaStatusLabel(label: 'Test Label'), ZetaStatusLabel, 'status_label_default');
goldenTest(goldenFile, const ZetaStatusLabel(label: 'Test Label'), 'status_label_default');
goldenTest(
goldenFile,
const ZetaStatusLabel(
label: 'Custom Icon',
customIcon: Icons.person,
),
ZetaStatusLabel,
'status_label_custom',
);
});
Expand Down
4 changes: 2 additions & 2 deletions test/src/components/badge/tag_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ void main() {
group('Styling Tests', () {});
group('Interaction Tests', () {});
group('Golden Tests', () {
goldenTest(goldenFile, const ZetaTag.right(label: 'Tag', rounded: false), ZetaTag, 'tag_right');
goldenTest(goldenFile, const ZetaTag.left(label: 'Tag', rounded: true), ZetaTag, 'tag_left');
goldenTest(goldenFile, const ZetaTag.right(label: 'Tag', rounded: false), 'tag_right');
goldenTest(goldenFile, const ZetaTag.left(label: 'Tag', rounded: true), 'tag_left');
});
group('Performance Tests', () {});
}
2 changes: 1 addition & 1 deletion test/src/components/banner/banner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ void main() {
);
},
),
ZetaBanner,
'banner_${type.toString().split('.').last}',
widgetType: ZetaBanner,
);
}
});
Expand Down
13 changes: 5 additions & 8 deletions test/src/components/button/button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,47 +258,44 @@ void main() {
});

group('Golden Tests', () {
goldenTest(goldenFile, ZetaButton.primary(onPressed: () {}, label: 'Test Button'), ZetaButton, 'button_primary');
goldenTest(
goldenFile,
ZetaButton.primary(onPressed: () {}, label: 'Test Button'),
'button_primary',
);
goldenTest(
goldenFile,
ZetaButton.secondary(onPressed: () {}, label: 'Test Button', leadingIcon: Icons.abc, size: ZetaWidgetSize.small),
ZetaButton,
'button_secondary',
);
goldenTest(
goldenFile,
ZetaButton.positive(onPressed: () {}, label: 'Test Button', trailingIcon: Icons.abc),
ZetaButton,
'button_positive',
);
goldenTest(
goldenFile,
ZetaButton.negative(onPressed: () {}, label: 'Test Button', size: ZetaWidgetSize.small),
ZetaButton,
'button_negative',
);
goldenTest(
goldenFile,
ZetaButton.outline(onPressed: () {}, label: 'Test Button', size: ZetaWidgetSize.large),
ZetaButton,
'button_outline',
);
goldenTest(
goldenFile,
const ZetaButton.outlineSubtle(label: 'Test Button', borderType: ZetaWidgetBorder.sharp),
ZetaButton,
'button_outline_subtle',
);
goldenTest(
goldenFile,
ZetaButton.text(onPressed: () {}, label: 'Test Button', borderType: ZetaWidgetBorder.full),
ZetaButton,
'button_text',
);
goldenTest(
goldenFile,
const ZetaButton.text(label: 'Test Button', borderType: ZetaWidgetBorder.full),
ZetaButton,
'button_disabled',
);
});
Expand Down
Loading

0 comments on commit 1e7e0cd

Please sign in to comment.