Skip to content

Commit

Permalink
test: Fix bug in golden tests that meant they failed on windows
Browse files Browse the repository at this point in the history
test: Add new GlodenFinder class to simplify generating golden file Uris
  • Loading branch information
github-actions committed Sep 10, 2024
1 parent 3ac64a7 commit 3d7ce8c
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 136 deletions.
29 changes: 11 additions & 18 deletions lib/src/components/list_item/notification_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ZetaNotificationListItem extends ZetaStatelessWidget {
final extend = actionWith / maxScreenWidth;
if (extend.clamp(0, maxButtonWidth).toDouble() > 1) {
return 1;
}
}
return extend.clamp(0, maxButtonWidth).toDouble();
}

Expand Down Expand Up @@ -148,8 +148,7 @@ class ZetaNotificationListItem extends ZetaStatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
MergeSemantics(
child: Row(
Expand All @@ -160,9 +159,7 @@ class ZetaNotificationListItem extends ZetaStatelessWidget {
size: ZetaWidgetSize.small,
),
SizedBox(
width: Zeta.of(context)
.spacing
.minimum,
width: Zeta.of(context).spacing.minimum,
),
Text(
title,
Expand All @@ -176,8 +173,7 @@ class ZetaNotificationListItem extends ZetaStatelessWidget {
if (notificationTime != null)
Text(
notificationTime!,
style:
ZetaTextStyles.bodySmall.apply(
style: ZetaTextStyles.bodySmall.apply(
color: colors.textDisabled,
),
),
Expand All @@ -186,15 +182,12 @@ class ZetaNotificationListItem extends ZetaStatelessWidget {
padding: const EdgeInsets.all(2),
decoration: BoxDecoration(
color: colors.surfaceNegative,
borderRadius:
Zeta.of(context).radius.full,
borderRadius: Zeta.of(context).radius.full,
),
child: ZetaIcon(
ZetaIcons.important_notification,
color: colors.white,
size: Zeta.of(context)
.spacing
.large,
size: Zeta.of(context).spacing.large,
),
),
].gap(Zeta.of(context).spacing.minimum),
Expand All @@ -205,8 +198,7 @@ class ZetaNotificationListItem extends ZetaStatelessWidget {
if (attachment != null)
Container(
padding: EdgeInsets.symmetric(
vertical:
Zeta.of(context).spacing.minimum,
vertical: Zeta.of(context).spacing.minimum,
),
child: Row(
children: [
Expand All @@ -216,8 +208,7 @@ class ZetaNotificationListItem extends ZetaStatelessWidget {
color: colors.primary,
),
DefaultTextStyle(
style: ZetaTextStyles.bodyXSmall
.apply(color: colors.primary),
style: ZetaTextStyles.bodyXSmall.apply(color: colors.primary),
child: attachment!,
),
],
Expand All @@ -230,7 +221,9 @@ class ZetaNotificationListItem extends ZetaStatelessWidget {
),
if (action != null)
Container(
alignment: Alignment.bottomRight, child: action),
alignment: Alignment.bottomRight,
child: action,
),
],
).paddingAll(Zeta.of(context).spacing.small),
),
Expand Down
16 changes: 8 additions & 8 deletions test/src/components/badge/indicator_test.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
const goldenFile = GoldenFinder(component: 'badge');

setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
goldenFileComparator = TolerantComparator(goldenFile.uri);
});
testWidgets('Default constructor initializes with correct parameters', (WidgetTester tester) async {
await tester.pumpWidget(const TestApp(home: ZetaIndicator()));
Expand All @@ -28,7 +28,7 @@ void main() {

await expectLater(
find.byType(ZetaIndicator),
matchesGoldenFile(join(getCurrentPath('badge'), 'indicator_default.png')),
matchesGoldenFile(goldenFile.getFileUri('indicator_default.png')),
);
});

Expand Down Expand Up @@ -73,7 +73,7 @@ void main() {

await expectLater(
find.byType(ZetaIndicator),
matchesGoldenFile(join(getCurrentPath('badge'), 'indicator_icon_default.png')),
matchesGoldenFile(goldenFile.getFileUri('indicator_icon_default')),
);
});
testWidgets('Icon constructor with values', (WidgetTester tester) async {
Expand Down Expand Up @@ -101,7 +101,7 @@ void main() {

await expectLater(
find.byType(ZetaIndicator),
matchesGoldenFile(join(getCurrentPath('badge'), 'indicator_icon_values.png')),
matchesGoldenFile(goldenFile.getFileUri('indicator_icon_values.png')),
);
});
testWidgets('Notification constructor initializes with correct parameters', (WidgetTester tester) async {
Expand All @@ -120,7 +120,7 @@ void main() {

await expectLater(
find.byType(ZetaIndicator),
matchesGoldenFile(join(getCurrentPath('badge'), 'indicator_notification_default.png')),
matchesGoldenFile(goldenFile.getFileUri('indicator_notification_default.png')),
);
});
testWidgets('Notification constructor with values', (WidgetTester tester) async {
Expand Down Expand Up @@ -149,7 +149,7 @@ void main() {

await expectLater(
find.byType(ZetaIndicator),
matchesGoldenFile(join(getCurrentPath('badge'), 'indicator_notification_values.png')),
matchesGoldenFile(goldenFile.getFileUri('indicator_notification_values.png')),
);
});
testWidgets('debugFillProperties works correctly', (WidgetTester tester) async {
Expand Down
20 changes: 10 additions & 10 deletions test/src/components/badge/label_test.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
const goldenFile = GoldenFinder(component: 'badge');

setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
goldenFileComparator = TolerantComparator(goldenFile.uri);
});
testWidgets('Initializes with correct parameters', (WidgetTester tester) async {
await tester.pumpWidget(const TestApp(home: ZetaLabel(label: 'Test Label')));
Expand All @@ -22,7 +22,7 @@ void main() {
expect(label.label, 'Test Label');
expect(label.status, ZetaWidgetStatus.info);

await expectLater(find.byType(ZetaLabel), matchesGoldenFile(join(getCurrentPath('badge'), 'label_default.png')));
await expectLater(find.byType(ZetaLabel), matchesGoldenFile(goldenFile.getFileUri('label_default.png')));
});

testWidgets('Positive status', (WidgetTester tester) async {
Expand All @@ -33,7 +33,7 @@ void main() {

expect(label.status, ZetaWidgetStatus.positive);

await expectLater(find.byType(ZetaLabel), matchesGoldenFile(join(getCurrentPath('badge'), 'label_positive.png')));
await expectLater(find.byType(ZetaLabel), matchesGoldenFile(goldenFile.getFileUri('label_positive.png')));
});

testWidgets('Warning status', (WidgetTester tester) async {
Expand All @@ -44,7 +44,7 @@ void main() {

expect(label.status, ZetaWidgetStatus.warning);

await expectLater(find.byType(ZetaLabel), matchesGoldenFile(join(getCurrentPath('badge'), 'label_warning.png')));
await expectLater(find.byType(ZetaLabel), matchesGoldenFile(goldenFile.getFileUri('label_warning.png')));
});
testWidgets('Negative status', (WidgetTester tester) async {
await tester.pumpWidget(const TestApp(home: ZetaLabel(label: 'Test Label', status: ZetaWidgetStatus.negative)));
Expand All @@ -54,7 +54,7 @@ void main() {

expect(label.status, ZetaWidgetStatus.negative);

await expectLater(find.byType(ZetaLabel), matchesGoldenFile(join(getCurrentPath('badge'), 'label_negative.png')));
await expectLater(find.byType(ZetaLabel), matchesGoldenFile(goldenFile.getFileUri('label_negative.png')));
});
testWidgets('Neutral status', (WidgetTester tester) async {
await tester.pumpWidget(const TestApp(home: ZetaLabel(label: 'Test Label', status: ZetaWidgetStatus.neutral)));
Expand All @@ -64,7 +64,7 @@ void main() {

expect(label.status, ZetaWidgetStatus.neutral);

await expectLater(find.byType(ZetaLabel), matchesGoldenFile(join(getCurrentPath('badge'), 'label_neutral.png')));
await expectLater(find.byType(ZetaLabel), matchesGoldenFile(goldenFile.getFileUri('label_neutral.png')));
});

testWidgets('Dark mode', (WidgetTester tester) async {
Expand All @@ -80,7 +80,7 @@ void main() {

expect(label.status, ZetaWidgetStatus.info);

await expectLater(find.byType(ZetaLabel), matchesGoldenFile(join(getCurrentPath('badge'), 'label_dark.png')));
await expectLater(find.byType(ZetaLabel), matchesGoldenFile(goldenFile.getFileUri('label_dark.png')));
});

testWidgets('Sharp', (WidgetTester tester) async {
Expand All @@ -93,7 +93,7 @@ void main() {

expect(label.rounded, false);

await expectLater(find.byType(ZetaLabel), matchesGoldenFile(join(getCurrentPath('badge'), 'label_sharp.png')));
await expectLater(find.byType(ZetaLabel), matchesGoldenFile(goldenFile.getFileUri('label_sharp.png')));
});

testWidgets('debugFillProperties works correctly', (WidgetTester tester) async {
Expand Down
15 changes: 7 additions & 8 deletions test/src/components/badge/priority_pill_test.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// ignore_for_file: avoid_dynamic_calls

import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
const goldenFile = GoldenFinder(component: 'badge');

setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
goldenFileComparator = TolerantComparator(goldenFile.uri);
});
testWidgets('Initializes with correct label and index', (WidgetTester tester) async {
await tester.pumpWidget(
Expand All @@ -36,7 +35,7 @@ void main() {

await expectLater(
find.byType(ZetaPriorityPill),
matchesGoldenFile(join(getCurrentPath('badge'), 'priority_pill_default.png')),
matchesGoldenFile(goldenFile.getFileUri('priority_pill_default.png')),
);
});
testWidgets('High priority pill', (WidgetTester tester) async {
Expand Down Expand Up @@ -64,7 +63,7 @@ void main() {

await expectLater(
find.byType(ZetaPriorityPill),
matchesGoldenFile(join(getCurrentPath('badge'), 'priority_pill_high.png')),
matchesGoldenFile(goldenFile.getFileUri('priority_pill_high.png')),
);
});
testWidgets('Medium priority pill', (WidgetTester tester) async {
Expand All @@ -84,7 +83,7 @@ void main() {

await expectLater(
find.byType(ZetaPriorityPill),
matchesGoldenFile(join(getCurrentPath('badge'), 'priority_pill_medium.png')),
matchesGoldenFile(goldenFile.getFileUri('priority_pill_medium.png')),
);
});
testWidgets('Low priority pill', (WidgetTester tester) async {
Expand All @@ -106,7 +105,7 @@ void main() {

await expectLater(
find.byType(ZetaPriorityPill),
matchesGoldenFile(join(getCurrentPath('badge'), 'priority_pill_low.png')),
matchesGoldenFile(goldenFile.getFileUri('priority_pill_low.png')),
);
});
testWidgets('debugFillProperties works correctly', (WidgetTester tester) async {
Expand Down
10 changes: 5 additions & 5 deletions test/src/components/badge/status_label_test.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
const goldenFile = GoldenFinder(component: 'badge');

setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
goldenFileComparator = TolerantComparator(goldenFile.uri);
});
group('ZetaStatusLabel Tests', () {
testWidgets('Initializes with correct properties', (WidgetTester tester) async {
Expand All @@ -24,7 +24,7 @@ void main() {

await expectLater(
find.byType(ZetaStatusLabel),
matchesGoldenFile(join(getCurrentPath('badge'), 'status_label_default.png')),
matchesGoldenFile(goldenFile.getFileUri('status_label_default.png')),
);
});
});
Expand All @@ -43,7 +43,7 @@ void main() {

await expectLater(
find.byType(ZetaStatusLabel),
matchesGoldenFile(join(getCurrentPath('badge'), 'status_label_custom.png')),
matchesGoldenFile(goldenFile.getFileUri('status_label_custom.png')),
);
});
testWidgets('debugFillProperties works correctly', (WidgetTester tester) async {
Expand Down
10 changes: 5 additions & 5 deletions test/src/components/badge/tag_test.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
const goldenFile = GoldenFinder(component: 'badge');

setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
goldenFileComparator = TolerantComparator(goldenFile.uri);
});
group('ZetaTag', () {
testWidgets('Initializes right with correct parameters', (WidgetTester tester) async {
Expand All @@ -24,7 +24,7 @@ void main() {

await expectLater(
find.byType(ZetaTag),
matchesGoldenFile(join(getCurrentPath('badge'), 'tag_right.png')),
matchesGoldenFile(goldenFile.getFileUri('tag_right.png')),
);
});

Expand All @@ -38,7 +38,7 @@ void main() {

await expectLater(
find.byType(ZetaTag),
matchesGoldenFile(join(getCurrentPath('badge'), 'tag_left.png')),
matchesGoldenFile(goldenFile.getFileUri('tag_left.png')),
);
});
});
Expand Down
Loading

0 comments on commit 3d7ce8c

Please sign in to comment.