Skip to content

Commit

Permalink
test: Fix bug in golden tests that meant they failed on windows (#177)
Browse files Browse the repository at this point in the history
test: Add new GoldenFiles class to simplify generating golden file Uris
  • Loading branch information
thelukewalton authored Sep 10, 2024
1 parent dc0edd6 commit a77211a
Show file tree
Hide file tree
Showing 22 changed files with 125 additions and 118 deletions.
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 = GoldenFiles(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')),
);
});

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')),
);
});
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')),
);
});
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')),
);
});
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 = GoldenFiles(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')));
});

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')));
});

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')));
});
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')));
});
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')));
});

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')));
});

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')));
});

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 = GoldenFiles(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')),
);
});
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')),
);
});
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')),
);
});
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')),
);
});
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 = GoldenFiles(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')),
);
});
});
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')),
);
});
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 = GoldenFiles(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')),
);
});

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')),
);
});
});
Expand Down
22 changes: 11 additions & 11 deletions test/src/components/button/button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import 'dart:ui';
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 = GoldenFiles(component: 'button');

setUpAll(() {
final testUri = Uri.parse(getCurrentPath('button'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
goldenFileComparator = TolerantComparator(goldenFile.uri);
});

group('ZetaButton Tests', () {
Expand Down Expand Up @@ -55,7 +55,7 @@ void main() {
expect(button.size, ZetaWidgetSize.medium);
expect(button.type, ZetaButtonType.primary);

await expectLater(find.byType(ZetaButton), matchesGoldenFile(join(getCurrentPath('button'), 'button_primary.png')));
await expectLater(find.byType(ZetaButton), matchesGoldenFile(goldenFile.getFileUri('button_primary')));
});
testWidgets('Initializes secondary with correct Label', (WidgetTester tester) async {
await tester.pumpWidget(
Expand All @@ -80,7 +80,7 @@ void main() {

await expectLater(
find.byType(ZetaButton),
matchesGoldenFile(join(getCurrentPath('button'), 'button_secondary.png')),
matchesGoldenFile(goldenFile.getFileUri('button_secondary')),
);
});
testWidgets('Initializes positive with correct Label', (WidgetTester tester) async {
Expand All @@ -101,7 +101,7 @@ void main() {

await expectLater(
find.byType(ZetaButton),
matchesGoldenFile(join(getCurrentPath('button'), 'button_positive.png')),
matchesGoldenFile(goldenFile.getFileUri('button_positive')),
);
});
testWidgets('Initializes negative with correct Label', (WidgetTester tester) async {
Expand All @@ -122,7 +122,7 @@ void main() {

await expectLater(
find.byType(ZetaButton),
matchesGoldenFile(join(getCurrentPath('button'), 'button_negative.png')),
matchesGoldenFile(goldenFile.getFileUri('button_negative')),
);
});
testWidgets('Initializes outline with correct Label', (WidgetTester tester) async {
Expand All @@ -141,7 +141,7 @@ void main() {
expect(button.size, ZetaWidgetSize.large);
expect(button.type, ZetaButtonType.outline);

await expectLater(find.byType(ZetaButton), matchesGoldenFile(join(getCurrentPath('button'), 'button_outline.png')));
await expectLater(find.byType(ZetaButton), matchesGoldenFile(goldenFile.getFileUri('button_outline')));
});
testWidgets('Initializes outlineSubtle with correct Label', (WidgetTester tester) async {
await tester.pumpWidget(
Expand All @@ -161,7 +161,7 @@ void main() {

await expectLater(
find.byType(ZetaButton),
matchesGoldenFile(join(getCurrentPath('button'), 'button_outline_subtle.png')),
matchesGoldenFile(goldenFile.getFileUri('button_outline_subtle')),
);
});
testWidgets('Initializes text with correct Label', (WidgetTester tester) async {
Expand All @@ -182,7 +182,7 @@ void main() {

await expectLater(
find.byType(ZetaButton),
matchesGoldenFile(join(getCurrentPath('button'), 'button_text.png')),
matchesGoldenFile(goldenFile.getFileUri('button_text')),
);
});

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

await expectLater(
find.byType(ZetaButton),
matchesGoldenFile(join(getCurrentPath('button'), 'button_disabled.png')),
matchesGoldenFile(goldenFile.getFileUri('button_disabled')),
);
});
testWidgets('Interaction with button', (WidgetTester tester) async {
Expand Down
Loading

0 comments on commit a77211a

Please sign in to comment.