From a77211a9fd33dfee170605a33098e9df6d634be2 Mon Sep 17 00:00:00 2001 From: Luke Walton Date: Tue, 10 Sep 2024 14:57:09 +0100 Subject: [PATCH] test: Fix bug in golden tests that meant they failed on windows (#177) test: Add new GoldenFiles class to simplify generating golden file Uris --- test/src/components/badge/indicator_test.dart | 16 ++++++------- test/src/components/badge/label_test.dart | 20 ++++++++-------- .../components/badge/priority_pill_test.dart | 15 ++++++------ .../components/badge/status_label_test.dart | 10 ++++---- test/src/components/badge/tag_test.dart | 10 ++++---- test/src/components/button/button_test.dart | 22 +++++++++--------- .../components/chat_item/chat_item_test.dart | 22 +++++++++--------- .../components/checkbox/checkbox_test.dart | 12 +++++----- test/src/components/dialpad/dialpad_test.dart | 12 +++++----- .../src/components/fab/golden/FAB_default.png | Bin 0 -> 4598 bytes .../components/fab/golden/FAB_disabled.png | Bin 0 -> 4321 bytes .../src/components/fab/golden/FAB_inverse.png | Bin 0 -> 4269 bytes .../src/components/fab/golden/FAB_pressed.png | Bin 0 -> 4706 bytes .../components/fab/golden/FAB_secondary.png | Bin 0 -> 3407 bytes test/src/components/fabs/fab_test.dart | 16 ++++++------- .../in_page_banner/in_page_banner_test.dart | 15 ++++++------ .../password/password_input_test.dart | 10 ++++---- .../search_bar/search_bar_test.dart | 15 ++++++------ test/src/components/tooltip/tooltip_test.dart | 16 ++++++------- .../extended_top_app_bar_test.dart | 10 ++++---- test/test_utils/tolerant_comparator.dart | 4 ++-- test/test_utils/utils.dart | 18 ++++++++++---- 22 files changed, 125 insertions(+), 118 deletions(-) create mode 100644 test/src/components/fab/golden/FAB_default.png create mode 100644 test/src/components/fab/golden/FAB_disabled.png create mode 100644 test/src/components/fab/golden/FAB_inverse.png create mode 100644 test/src/components/fab/golden/FAB_pressed.png create mode 100644 test/src/components/fab/golden/FAB_secondary.png diff --git a/test/src/components/badge/indicator_test.dart b/test/src/components/badge/indicator_test.dart index a52a34d7..cf732149 100644 --- a/test/src/components/badge/indicator_test.dart +++ b/test/src/components/badge/indicator_test.dart @@ -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())); @@ -28,7 +28,7 @@ void main() { await expectLater( find.byType(ZetaIndicator), - matchesGoldenFile(join(getCurrentPath('badge'), 'indicator_default.png')), + matchesGoldenFile(goldenFile.getFileUri('indicator_default')), ); }); @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/test/src/components/badge/label_test.dart b/test/src/components/badge/label_test.dart index f7f777fe..d5bfb5d2 100644 --- a/test/src/components/badge/label_test.dart +++ b/test/src/components/badge/label_test.dart @@ -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'))); @@ -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 { @@ -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 { @@ -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))); @@ -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))); @@ -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 { @@ -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 { @@ -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 { diff --git a/test/src/components/badge/priority_pill_test.dart b/test/src/components/badge/priority_pill_test.dart index 28c53e1b..8724eba2 100644 --- a/test/src/components/badge/priority_pill_test.dart +++ b/test/src/components/badge/priority_pill_test.dart @@ -1,8 +1,6 @@ // 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'; @@ -10,9 +8,10 @@ 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( @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/test/src/components/badge/status_label_test.dart b/test/src/components/badge/status_label_test.dart index 27c9d278..201a8ebc 100644 --- a/test/src/components/badge/status_label_test.dart +++ b/test/src/components/badge/status_label_test.dart @@ -1,7 +1,6 @@ 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'; @@ -9,9 +8,10 @@ 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 { @@ -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')), ); }); }); @@ -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 { diff --git a/test/src/components/badge/tag_test.dart b/test/src/components/badge/tag_test.dart index 6f6f4fcf..3dd84531 100644 --- a/test/src/components/badge/tag_test.dart +++ b/test/src/components/badge/tag_test.dart @@ -1,6 +1,5 @@ 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'; @@ -8,9 +7,10 @@ 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 { @@ -24,7 +24,7 @@ void main() { await expectLater( find.byType(ZetaTag), - matchesGoldenFile(join(getCurrentPath('badge'), 'tag_right.png')), + matchesGoldenFile(goldenFile.getFileUri('tag_right')), ); }); @@ -38,7 +38,7 @@ void main() { await expectLater( find.byType(ZetaTag), - matchesGoldenFile(join(getCurrentPath('badge'), 'tag_left.png')), + matchesGoldenFile(goldenFile.getFileUri('tag_left')), ); }); }); diff --git a/test/src/components/button/button_test.dart b/test/src/components/button/button_test.dart index fed28ad8..c14a9271 100644 --- a/test/src/components/button/button_test.dart +++ b/test/src/components/button/button_test.dart @@ -3,7 +3,6 @@ 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'; @@ -11,9 +10,10 @@ 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', () { @@ -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( @@ -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 { @@ -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 { @@ -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 { @@ -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( @@ -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 { @@ -182,7 +182,7 @@ void main() { await expectLater( find.byType(ZetaButton), - matchesGoldenFile(join(getCurrentPath('button'), 'button_text.png')), + matchesGoldenFile(goldenFile.getFileUri('button_text')), ); }); @@ -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 { diff --git a/test/src/components/chat_item/chat_item_test.dart b/test/src/components/chat_item/chat_item_test.dart index 7e3456f7..8bafbc00 100644 --- a/test/src/components/chat_item/chat_item_test.dart +++ b/test/src/components/chat_item/chat_item_test.dart @@ -2,7 +2,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:intl/intl.dart'; -import 'package:path/path.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; import '../../../test_utils/test_app.dart'; @@ -10,9 +9,10 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { + const goldenFile = GoldenFiles(component: 'chat_item'); + setUpAll(() { - final testUri = Uri.parse(getCurrentPath('chat_item')); - goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01); + goldenFileComparator = TolerantComparator(goldenFile.uri); }); group('ZetaChatItem Tests', () { @@ -67,7 +67,7 @@ void main() { await expectLater( chatItemFinder, - matchesGoldenFile(join(getCurrentPath('chat_item'), 'chat_item_default.png')), + matchesGoldenFile(goldenFile.getFileUri('chat_item_default')), ); }); @@ -122,7 +122,7 @@ void main() { await expectLater( chatItemFinder, - matchesGoldenFile(join(getCurrentPath('chat_item'), 'chat_item_highlighted.png')), + matchesGoldenFile(goldenFile.getFileUri('chat_item_highlighted')), ); }); @@ -184,7 +184,7 @@ void main() { await expectLater( chatItemFinder, - matchesGoldenFile(join(getCurrentPath('chat_item'), 'chat_item_slidable_actions.png')), + matchesGoldenFile(goldenFile.getFileUri('chat_item_slidable_actions')), ); }); @@ -238,7 +238,7 @@ void main() { await expectLater( chatItemFinder, - matchesGoldenFile(join(getCurrentPath('chat_item'), 'chat_item_pale_slidable_buttons.png')), + matchesGoldenFile(goldenFile.getFileUri('chat_item_pale_slidable_buttons')), ); }); @@ -326,7 +326,7 @@ void main() { await expectLater( chatItemFinder, - matchesGoldenFile(join(getCurrentPath('chat_item'), 'chat_item_pale_and_regular_buttons.png')), + matchesGoldenFile(goldenFile.getFileUri('chat_item_pale_and_regular_buttons')), ); }); @@ -370,7 +370,7 @@ void main() { await expectLater( chatItemFinder, - matchesGoldenFile(join(getCurrentPath('chat_item'), 'chat_item_custom_leading.png')), + matchesGoldenFile(goldenFile.getFileUri('chat_item_custom_leading')), ); }); @@ -428,7 +428,7 @@ void main() { await expectLater( chatItemFinder, - matchesGoldenFile(join(getCurrentPath('chat_item'), 'chat_item_custom_slidable_buttons.png')), + matchesGoldenFile(goldenFile.getFileUri('chat_item_custom_slidable_buttons')), ); }); @@ -544,7 +544,7 @@ void main() { await expectLater( chatItemFinder, - matchesGoldenFile(join(getCurrentPath('chat_item'), 'chat_item_small_screen_slidable_button.png')), + matchesGoldenFile(goldenFile.getFileUri('chat_item_small_screen_slidable_button')), ); }); }); diff --git a/test/src/components/checkbox/checkbox_test.dart b/test/src/components/checkbox/checkbox_test.dart index f7c85810..c2c00c56 100644 --- a/test/src/components/checkbox/checkbox_test.dart +++ b/test/src/components/checkbox/checkbox_test.dart @@ -3,7 +3,6 @@ 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/src/components/checkbox/checkbox.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; @@ -12,9 +11,10 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { + const goldenFile = GoldenFiles(component: 'checkbox'); + setUpAll(() { - final testUri = Uri.parse(getCurrentPath('checkbox')); - goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01); + goldenFileComparator = TolerantComparator(goldenFile.uri); }); group('ZetaCheckbox Tests', () { @@ -54,7 +54,7 @@ void main() { final checkboxFinder = find.byType(ZetaCheckbox); await expectLater( checkboxFinder, - matchesGoldenFile(join(getCurrentPath('checkbox'), 'checkbox_enabled.png')), + matchesGoldenFile(goldenFile.getFileUri('checkbox_enabled')), ); await tester.tap(find.byType(ZetaCheckbox)); await tester.pump(); @@ -73,7 +73,7 @@ void main() { final checkboxFinder = find.byType(ZetaCheckbox); await expectLater( checkboxFinder, - matchesGoldenFile(join(getCurrentPath('checkbox'), 'checkbox_disabled.png')), + matchesGoldenFile(goldenFile.getFileUri('checkbox_disabled')), ); await tester.tap(find.byType(ZetaCheckbox)); await tester.pump(); @@ -136,7 +136,7 @@ void main() { await tester.pumpAndSettle(); await expectLater( checkboxFinder, - matchesGoldenFile(join(getCurrentPath('checkbox'), 'checkbox_hover.png')), + matchesGoldenFile(goldenFile.getFileUri('checkbox_hover')), ); }); diff --git a/test/src/components/dialpad/dialpad_test.dart b/test/src/components/dialpad/dialpad_test.dart index 1b19da10..f85a2d54 100644 --- a/test/src/components/dialpad/dialpad_test.dart +++ b/test/src/components/dialpad/dialpad_test.dart @@ -3,7 +3,6 @@ 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'; @@ -11,9 +10,10 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { + const goldenFile = GoldenFiles(component: 'dialpad'); + setUpAll(() { - final testUri = Uri.parse(getCurrentPath('dialpad')); - goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01); + goldenFileComparator = TolerantComparator(goldenFile.uri); }); group('ZetaDialPad Tests', () { @@ -126,7 +126,7 @@ void main() { await expectLater( dialPadFinder, - matchesGoldenFile(join(getCurrentPath('dialpad'), 'dialpad_enabled.png')), + matchesGoldenFile(goldenFile.getFileUri('dialpad_enabled')), ); }); }); @@ -235,7 +235,7 @@ void main() { await expectLater( dialPadFinder, - matchesGoldenFile(join(getCurrentPath('dialpad'), 'dialpad_disabled.png')), + matchesGoldenFile(goldenFile.getFileUri('dialpad_disabled')), ); }); testWidgets('ZetaDialPadButton interaction', (WidgetTester tester) async { @@ -259,7 +259,7 @@ void main() { await expectLater( buttonFinder, - matchesGoldenFile(join(getCurrentPath('dialpad'), 'dialpadbutton.png')), + matchesGoldenFile(goldenFile.getFileUri('dialpadbutton')), ); }); diff --git a/test/src/components/fab/golden/FAB_default.png b/test/src/components/fab/golden/FAB_default.png new file mode 100644 index 0000000000000000000000000000000000000000..70d8d11e36a69b7cd4ff78e355251b4d5aa29d20 GIT binary patch literal 4598 zcmeH}e^}Dj9>)*pCe?$j+n(wnf6&@p>n=$vf1nb~(&lxeoQR~=b!v%2L8r*Bq+;7{ znfYVwnPzHau2d9IQfH*7Gp8;vy{H%lq@*HT#ZqLV=)P_LZU5dsIscsJ^Lak!oX>fk z_viDR+*8C8$jzwD003n0N5?+}zzz)noPu~0^4v_nlnhO<)K5w>c*5he8op=a+>dd3j|3J&2GkwwmX51TpnLk;R^@X&Bw|5Lnvlv?PN=C7?uMq%jVGv=W zBy-x?Od~aEJgHwx9h8SL4L_e}%6p5`GTw$Vb7$;E7h0L3qnR3NK9OSbQJz`t3N%^k ziWM9q&ki&Y)Q1T3YTtAJ%1X}uK48z(Ao{3}@j%YfN_5 zJC1(w0zJQ4(jX!qn4evGAAqz6-fNWA*@=G3FTzI-!Z8V3ELfeD+-%&k6>z-TF@*GM z(qT{Yd|j}{d&bj6Ia(j(l2t2@1z>Q>adXj7?o-QfVGzw6B3bG(sMa4*R2$W~#6lP# z?DTt|AX$7tv8E_UGxsJM%spJAuwA>PtqfDN=8(p2b{7NrJ9nEa*X5XX9JQledjq&^Rmt5C=oHEa$Drz;>RGwG4 z())4*q=gSqRom~I$~u?~&LFlhk)?r{-2C}ib^=*m`IWT08~*wb&z3o|tMrMHMI8BI z+yQbNxuwx=y1r6cE>L3i>o5>KkLqTZ&vdTgjF5Hvjr^TvHYaX;gkNMml) zFF8LrlL-J&17o}QXI9+G!7!(J>c|JJ)xW=Bpv6nzT$7{bO~ak2s#LAun;W^9lpYJD zbpQw@3H6j`VKeRHU%ktJc+q<259e$hPkhlzz=_(Q&Yqs`;f2JPH?)PiiZUU+?C|9A zFzhD;)7UR3w_u`-x1b9#^Lf0HWBC?+Z%KN_4)LSGJGU&Bp2xm8sI#2abuwzy$@ABJ z)s9I+zxSWdhv2)>%rPW zNnJ;(JefjUBB@eM(QfniEillz=JYn&+8&Nyk-qXhf0s{bQ!6lM$UFI_?_>Z-HHLp` zTf2gA$*NN(bNU6e<4HvuBUF``2k9v(qx){b*7C6kjX2RAkGy=>%pHp`pP9>o4$WkU z75dcOI}|LTQ$6g1Jtvxx)ypFX@qVNbOQz8daF$I+%4AP}%;+kf=ojmIt4!Py&8zcH zIRZR8MV0am;tdcz(U!y^g(Hon0^0m|MD`f=`_iig`XrKyITd|2yM;Rr#e62)PvG%x z%EMVW99i?L>2Y(s^z*)N^=tA~ntY#wp}jY189-afu!M8X@rf;T_S%$1UHq3uls3}| zK(emM2`yB5916p;FWhm-Oc#0Ky-#by$bn*6LhthEz5$&uM1l0tK>1(!w?iK-|Dx^w*iz=ILGI^#Jrm76BLlH}br3 z4)#!rm7CrI03F1EROzJ6=>U?W20RYY}7#x5{2wSL)fQ^8SfQ^8S ofQ^8SfQ^8SfQ`WakH8{+e7~swjxS;g`i_I(K;m&hK=h^G08Sy18UO$Q literal 0 HcmV?d00001 diff --git a/test/src/components/fab/golden/FAB_disabled.png b/test/src/components/fab/golden/FAB_disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..8a0e4a444f873ee2ced9e15add092c7159b6b43f GIT binary patch literal 4321 zcmeH|=~Giz7{*T$G^q{*rb-ZyV8^M}VHs*lV1S4$(kPot0YL>J4PXNjP>2u$wbQ{3 z;uJ^97O*aiWfP-B3W%Z!QVih41Oo)n$Rc4&0$B{X>4i_7e(67u`{m4i=bSU|Ip=wP z&*jMQ5X(*Wn*aco+qRUjMfz3n z!-C|~ahGg*ZU%o&J81L;Ie$t*YHgW{s@c79jZp^rA%l_CAgOGLO%r6dJB-NEX*q@# z*@A#opkPnG3KP*@*QJJv2vcf2D?GwhPHFR6P61#woQt)*KA%l&N{^CHQTIkEiU*yE zVO)CdL&v&ZeRNHNH6nSEx*Pk}haYYf#Rv@ZY89 z6gh1G6EnuRLK?4qt+XUS*Zh{FeVkJcfYod=LM1BwAnV7cGIJ%B^Nh3~v0$Q>W$TP9 z8`Au(Cb$1}s#sCEa;pabuh_+>_9?uP;yxac_xV8qQ$Km~H35S7xEz)D(xI^vCyLQ^ zeSvHQ$ha}qSlH3l;pAhGdm|M>$sYK$KZnYD#B5%4ec%AHoQR7qazcQK-L3*V`7AYm zdfaL`k9Sxm*0?h83SoAG!~wkp30~SJU8Cn4mFXdEX-_&B%0#AdWeCqS#&h=JO@?_M zx*ckEk1sLlXX~*~A@#sM{5VrBM8}&{lYL6DD`c7;s9~Qyt2A`MYge`7kY@kT*l5EB z4DhE7FKUw>LkyG!>8rbw}V6w+T>cme;PhUYs#w{rLkSQ2j^agp6NTqFhzR#^GLCdlx;m)f-7 z>y*0Jhy{@q_foTGwoN3A!kabn@hcWOd^}5E#B>|I%V)CITez~-x}?H@2esc-yWomA z2rFva10)he##V9MdT5>k$f^XTH{jw&`JvZiT&9wC_ycf6M5rt-om35G`7b=bZ*T&& zo@*BAtFKhbv}dt?o9{rYbIJ!BY~WojBQAOehzOUlpb+)DfL+w$M=HpeIqs}p?tKx+ zh8w;ywjG(tf)YZ*f1Scqx!|IVuuMLlq=$0Lf3Pm;F6~KPf4CGQtylj3g@~S+81Gxt zq~;!7WC7qfIDn*h3K$ycZI7CfEBv}?N}F9ohXIyEq$$c?L~s}&KafG_( z$z52W%DRF69vXFID|nW#I)(UFU}rGel|>K9Kd6S!V6>7%4}64EwReg&nBe3t0)1~f z4-cC`u9_Wg-!bX{pMgCvAke=Mt+&vulOa^4{|1WiUA;{rJZlXnFjbPVH(TQnfN4SU z@`uE%E}7N5I^rSYQCSZsQDq z|ADpgHU!dKG+&5W3}z#k$zZ0UIT6fhXih_O8k*Daf6{Qugn$loMtkCRieY8~a&UN1 JQ$WJSe*m9C7P$Zb literal 0 HcmV?d00001 diff --git a/test/src/components/fab/golden/FAB_inverse.png b/test/src/components/fab/golden/FAB_inverse.png new file mode 100644 index 0000000000000000000000000000000000000000..1f994e94fd96fb9db3f4b287f882eb9eca890983 GIT binary patch literal 4269 zcmeHKTTl~c6#kPSNkIk_OR6AXomQ=ia=*j?MHCncX+^mVR{^0_AfQ5k07*fu76m)b zAOc1oXehOYtAtAk)^@UDB%r3;36K;68E!EKawF+t9qn}b;HcB5?90D<&e{FX`Of#9 z-M#Q-u%C(1CL;iVNr1oaAplUe03gFLhOng~t1um25T_3L`2YsbY6iYAIOP*?7y}=9 zn8fn{n1u!SettN+YHlpxV)ZcuG)ekw$$PqN{#wAI?SuG(=4+VLR^fX2%|?T7eNDgL zm2m-Gw8c&u{{^euOjKwoEVMuGvtcdTdDA+qgWdKRzJWofzeC@|LyWUIr+7QY=%6M) zVL(>(v&YyG9g7*uR<*nIh-E9Hbt>(hflEY+m@J}KrdgAIsVkMsaS(oaROYYC+wY;6 zD1wHECE<~goBeDu`PoxDV_bss9vRbVYXCr32bp4RNn>(xMz@&l#?G1=fM|HiOxcP} zWJJWqn(Mib-PA$EkG`{34c3YQxQh_Q8r~OllA$oWuK1|DZY(F7w9*#ag0RY+PJnX6 zRnEM9qUMI?W+%B70Oh0m4e!s7bwElii!?hZZTcoOb?=@WX)y;a(6Jj>tbOtga1_4? z`R6io)PqM6cR&low#@b;mVH0?S=-xb`q0qo$&0XuC}d*(3NNF7h-l5!PL@7l4Bsrt z7MgQD!BXN=h8kU7MEyR?Myr?REEn8#(Lxbrx-3$+SCI27nZwRk(`iTmt|-XVDAkW# zPF%p8nHo-hPUz@q>-*%aN8b?Fv^og~?8ES3;s9JA(zo#kr*@bAge zJjW(12s%R+!rf#_L4&BKt2`IxR&|n>N=l#$>g%iU02C)JRgP=ZBqqk(Arz?pItfP- zc*@V6oti~}aHpp0I8t!u(WCBU04#b^JV_|k;g@$|3eW&de6__J0O~~mSK@#)0N_5x z3;^4$Z)}v6*P=(oLPCB@Rr)SaJBat^M?pmsV<@CCHsUs~xue&$Wayx_=9?r7{)B}#> z2UnPcSH4+gFL|DCY0)1Tds4_Zhg;~3)3zqJZOlam1_p{0A{zd0QiXc6ryCo=Vr!6AX6zKSC<$MGT$%_3A9=%t%!Xm9s;DMc;8nlyM+wADu27akKsOM7H^2X@-2rq2pd zfO^(NEw)J+*H%k=h*6$2>GOn|h-Sp~#VQeJpic434Spa24^OF2<`ZQYgt3nRM=PIf0Dx~PHMQItrwOqCwY(ZUaRI-SP7o2 zeY{)k)zaAL5KNidA*yN`cPle>Pn5U=kbXCN5VUojpe+6-y-lQ$Mo-In65v78z%CHC zs^>d&Ok>k@^ybrjt1~pRzn}BS&&D}M`s`{6_J-nKZ88ELi!)wEu+XTwbCz(k-a&tF zu2g;GTMs!sbb9FC;@zmHjh;4o+Q8o;dLihApclgbBm~We+!`14tZX6({@noq2ZDVW IK5>PA0fbKy1^@s6 literal 0 HcmV?d00001 diff --git a/test/src/components/fab/golden/FAB_pressed.png b/test/src/components/fab/golden/FAB_pressed.png new file mode 100644 index 0000000000000000000000000000000000000000..e0b19382773adc4c3e051e49b56704eb4169492f GIT binary patch literal 4706 zcmeH}TU1k59>#Y-1&a}@RqoX(V{Jzu$W;Roqyl9WP%)wu2*X_{H)FUYLNa!=2nf1p zGfa>G1(O0H3g_wj(frQ8{nIk^V>pbSXoOSm3&f4Gp{r}(I z=fR}_U-(Dn9{~X1eqW!z0)YN80Q9aK?tw-q>33718w`8J*9$NQEoIQdF07Z|RYT~y zV;G$az`=cf=g(cue6k?EQ4o%^>RFy@zj(ofGyKpYV)u`qU2$_6JD&QLjrXB85al%d z#h-HXeA>EAqee|l-rVbHgng3Si+P1nwQ(;dk=prL6~~!Ac3(oJNdZW;G{usXR;CQZ)rYb}2wFcCWclfg8)))0?}a0obQQ6a3D1+zf^mvt0MnRP z!w%;r+!O=>P;$TUFP<%n^Wk=B3!f59RV&&c++8;yV)_L-r*A7ag^(p2>vQ z%XqCS1I-I6ni;eZbyS=suGb~TX3%#ehqR8K$&;u)zg?BinJn~86ewzKC%#!EH)$veax zc+g0>+LBSn!EQxF zwAyJ`8srZ&zYN$$zTD{PsaI8DJjQke^N>KycNL8-Y?glW%Ma@1rETV#%GepD4@hKr z&PIOO<{tS38-=XQPtwj!oQMiig|3PH+V&SOz3xgCrz*%BLr)PY@A29y8xB1}Z2#Vk zbUHmbZyqx3#`Xv)@>q@*I6^C_4A@>(&dj-qC-}o>PTPlKG_tS!`2bYhTt zWej<-J%%KyyFrCn8AihGxbN$J`%xozrn}5P5V946B#viQ$ly(*S6ektwZCPb&9>e5>yKJM9DjL!Xs( z7#NgFJo6Vmfnr>6jxK`%(6wB}%9Jo@u0xS@n{g(<2-0C|GO#$Dt3NUb8C;Hj)m0i-&dy+mVh= z^(ZCHi+UVbkiQUhBzp-4>|M%gYh4+rdJcy|^(qbhW94v8EC8mg0JJc#SUO6; zXh&%5p@Z1Kd1g_^?BNe}MFtX=7e(b^)V#srOp$k8f@a?A!yC=vV@7lRjFT=;g!AUK z_ToTfqhzLOA0Va4x1>jzt*PiNJ3~HQAViBgv0($yVs^q%6Su3k;1CigMoY6e&U~4^ zNqLY3o0B#gKzgxE)UU3U^SQ>tA2A)Q zPbHlQR-O+I8K!!`X4Yqf{_$of{R5V0(p5Cv%BI)icaEhM>|}j&Cf`c-nfC|b&9*flOJR*b0F(g zOQ(i2yT}`*eV;Bw6|D(}9zTA8`R$aD6`fqhPROcXLJ3z<0OXoxkhbXE(~n;@Wd(~@ zzs4j@OklWb_~_!celtNEfy#Q<`@2odB-y3}-8aW)#u&v3^X_5g|FdDoUeSa4_jUZc zJ7@ro`H-L^>D2p?+>fD#_bdQVzenye1mJ+RCjcZvMn4WS0sNp%Et1at&+1at&+ n1at&+1at&+1pc1{N_hH$TipR%OF}60Qx5#R1I{zOBJTbd5XR6u literal 0 HcmV?d00001 diff --git a/test/src/components/fab/golden/FAB_secondary.png b/test/src/components/fab/golden/FAB_secondary.png new file mode 100644 index 0000000000000000000000000000000000000000..ae97e30a75d1823b7c33b36398a96c2e27faeb95 GIT binary patch literal 3407 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i1B%QlYbpRzjKx9jP7LeL$-D$|Sc;uI zLpXq-h9jkefr00zr;B4q#hkad9rc_OMH()KXC7(Uz*u&WDPp3*8?F}Ch-Tf0PC;n} z(}{jrS*zmqYdt^nf42GGqW81!#PObH3@fR!lRkGYefB>d28L}%&MmVC+VR7lg@b`% zf}jEegM(WGP(YHAiGd-7fMA-{vkj+bKh-FHw@!WW8Ab+%I&o|p>}f=AHjy6KNkX*<_lWMDWjZ4)D0aZgoK zX}PUru?z#lhvPRu{+qe=Z%f?9QbvY`w~5R|c$I`e*%YBOZT3H4a6YKtfN%owo)}dL zN^XHM2;jhVr7-x)Ii Nfv2mV%Q~loCIHCF1&jay literal 0 HcmV?d00001 diff --git a/test/src/components/fabs/fab_test.dart b/test/src/components/fabs/fab_test.dart index e9e79000..cb90a4b3 100644 --- a/test/src/components/fabs/fab_test.dart +++ b/test/src/components/fabs/fab_test.dart @@ -3,16 +3,16 @@ 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: 'fab'); + setUpAll(() { - final testUri = Uri.parse(getCurrentPath('fabs')); - goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01); + goldenFileComparator = TolerantComparator(goldenFile.uri); }); group('ZetaFAB Tests', () { @@ -28,7 +28,7 @@ void main() { await expectLater( find.byType(ZetaFAB), - matchesGoldenFile(join(getCurrentPath('fabs'), 'FAB_default.png')), + matchesGoldenFile(goldenFile.getFileUri('FAB_default')), ); }); @@ -47,7 +47,7 @@ void main() { await expectLater( find.byType(ZetaFAB), - matchesGoldenFile(join(getCurrentPath('fabs'), 'FAB_pressed.png')), + matchesGoldenFile(goldenFile.getFileUri('FAB_pressed')), ); await e.up(); @@ -78,7 +78,7 @@ void main() { await expectLater( find.byType(ZetaFAB), - matchesGoldenFile(join(getCurrentPath('fabs'), 'FAB_inverse.png')), + matchesGoldenFile(goldenFile.getFileUri('FAB_inverse')), ); }); @@ -104,7 +104,7 @@ void main() { await expectLater( find.byType(ZetaFAB), - matchesGoldenFile(join(getCurrentPath('fabs'), 'FAB_secondary.png')), + matchesGoldenFile(goldenFile.getFileUri('FAB_secondary')), ); }); testWidgets('ZetaFAB interactive', (WidgetTester tester) async { @@ -168,7 +168,7 @@ void main() { await expectLater( find.byType(ZetaFAB), - matchesGoldenFile(join(getCurrentPath('fabs'), 'FAB_disabled.png')), + matchesGoldenFile(goldenFile.getFileUri('FAB_disabled')), ); }); diff --git a/test/src/components/in_page_banner/in_page_banner_test.dart b/test/src/components/in_page_banner/in_page_banner_test.dart index a15b4205..4c825515 100644 --- a/test/src/components/in_page_banner/in_page_banner_test.dart +++ b/test/src/components/in_page_banner/in_page_banner_test.dart @@ -1,16 +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: 'in_page_banner'); + setUpAll(() { - final testUri = Uri.parse(getCurrentPath('in_page_banner')); - goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01); + goldenFileComparator = TolerantComparator(goldenFile.uri); }); group('ZetaInPageBanner Tests', () { @@ -32,7 +33,7 @@ void main() { await expectLater( find.byType(ZetaInPageBanner), - matchesGoldenFile(join(getCurrentPath('in_page_banner'), 'in_page_banner_default.png')), + matchesGoldenFile(goldenFile.getFileUri('in_page_banner_default')), ); }); }); @@ -50,7 +51,7 @@ void main() { expect(decoration.color, ZetaColorBase.red.shade10); await expectLater( find.byType(ZetaInPageBanner), - matchesGoldenFile(join(getCurrentPath('in_page_banner'), 'in_page_banner_negative.png')), + matchesGoldenFile(goldenFile.getFileUri('in_page_banner_negative')), ); }); @@ -66,7 +67,7 @@ void main() { expect(decoration.color, ZetaColorBase.green.shade10); await expectLater( find.byType(ZetaInPageBanner), - matchesGoldenFile(join(getCurrentPath('in_page_banner'), 'in_page_banner_positive.png')), + matchesGoldenFile(goldenFile.getFileUri('in_page_banner_positive')), ); }); @@ -101,7 +102,7 @@ void main() { await expectLater( find.byType(ZetaInPageBanner), - matchesGoldenFile(join(getCurrentPath('in_page_banner'), 'in_page_banner_buttons.png')), + matchesGoldenFile(goldenFile.getFileUri('in_page_banner_buttons')), ); }); testWidgets("ZetaInPageBanner 'close' icon tap test", (WidgetTester tester) async { diff --git a/test/src/components/password/password_input_test.dart b/test/src/components/password/password_input_test.dart index 2a6af86a..57dbbd28 100644 --- a/test/src/components/password/password_input_test.dart +++ b/test/src/components/password/password_input_test.dart @@ -1,7 +1,6 @@ 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'; @@ -9,9 +8,10 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { + const goldenFile = GoldenFiles(component: 'password'); + setUpAll(() { - final testUri = Uri.parse(getCurrentPath('password')); - goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01); + goldenFileComparator = TolerantComparator(goldenFile.uri); }); testWidgets('ZetaPasswordInput initializes correctly', (WidgetTester tester) async { @@ -24,7 +24,7 @@ void main() { await expectLater( find.byType(ZetaPasswordInput), - matchesGoldenFile(join(getCurrentPath('password'), 'password_default.png')), + matchesGoldenFile(goldenFile.getFileUri('password_default')), ); }); @@ -75,7 +75,7 @@ void main() { await expectLater( find.byType(ZetaPasswordInput), - matchesGoldenFile(join(getCurrentPath('password'), 'password_error.png')), + matchesGoldenFile(goldenFile.getFileUri('password_error')), ); }); testWidgets('Test debugFillProperties', (WidgetTester tester) async { diff --git a/test/src/components/search_bar/search_bar_test.dart b/test/src/components/search_bar/search_bar_test.dart index 8c28fbe4..9cfaef8b 100644 --- a/test/src/components/search_bar/search_bar_test.dart +++ b/test/src/components/search_bar/search_bar_test.dart @@ -3,7 +3,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:path/path.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; import '../../../test_utils/test_app.dart'; @@ -27,10 +26,10 @@ abstract class ISearchBarEvents { ]) void main() { late MockISearchBarEvents callbacks; + const goldenFile = GoldenFiles(component: 'search_bar'); setUpAll(() { - final testUri = Uri.parse(getCurrentPath('search_bar')); - goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01); + goldenFileComparator = TolerantComparator(goldenFile.uri); }); setUp(() { @@ -61,7 +60,7 @@ void main() { await expectLater( find.byType(ZetaSearchBar), - matchesGoldenFile(join(getCurrentPath('search_bar'), 'search_bar_default.png')), + matchesGoldenFile(goldenFile.getFileUri('search_bar_default')), ); }); @@ -75,7 +74,7 @@ void main() { await expectLater( find.byType(ZetaSearchBar), - matchesGoldenFile(join(getCurrentPath('search_bar'), 'search_bar_medium.png')), + matchesGoldenFile(goldenFile.getFileUri('search_bar_medium')), ); }); @@ -91,7 +90,7 @@ void main() { await expectLater( find.byType(ZetaSearchBar), - matchesGoldenFile(join(getCurrentPath('search_bar'), 'search_bar_small.png')), + matchesGoldenFile(goldenFile.getFileUri('search_bar_small')), ); }); @@ -107,7 +106,7 @@ void main() { await expectLater( find.byType(ZetaSearchBar), - matchesGoldenFile(join(getCurrentPath('search_bar'), 'search_bar_full.png')), + matchesGoldenFile(goldenFile.getFileUri('search_bar_full')), ); }); @@ -123,7 +122,7 @@ void main() { await expectLater( find.byType(ZetaSearchBar), - matchesGoldenFile(join(getCurrentPath('search_bar'), 'search_bar_sharp.png')), + matchesGoldenFile(goldenFile.getFileUri('search_bar_sharp')), ); }); diff --git a/test/src/components/tooltip/tooltip_test.dart b/test/src/components/tooltip/tooltip_test.dart index 71961158..b1c5284f 100644 --- a/test/src/components/tooltip/tooltip_test.dart +++ b/test/src/components/tooltip/tooltip_test.dart @@ -1,11 +1,9 @@ // ignore_for_file: avoid_dynamic_calls - import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:path/path.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; import '../../../test_utils/test_app.dart'; @@ -19,10 +17,10 @@ import 'tooltip_test.mocks.dart'; void main() { final mockZeta = MockZeta(); when(mockZeta.radius).thenReturn(const ZetaRadiiAA(primitives: ZetaPrimitivesLight())); - setUpAll(() { - final testUri = Uri.parse(getCurrentPath('tooltip')); + const goldenFile = GoldenFiles(component: 'tooltip'); - goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01); + setUpAll(() { + goldenFileComparator = TolerantComparator(goldenFile.uri); }); group('ZetaTooltip Widget Tests', () { @@ -118,7 +116,7 @@ void main() { // Verifying the CustomPaint with different arrow directions. await expectLater( find.byType(ZetaTooltip), - matchesGoldenFile(join(getCurrentPath('tooltip'), 'arrow_up.png')), + matchesGoldenFile(goldenFile.getFileUri('arrow_up')), ); }); @@ -138,7 +136,7 @@ void main() { // Verifying the CustomPaint with different arrow directions. await expectLater( find.byType(ZetaTooltip), - matchesGoldenFile(join(getCurrentPath('tooltip'), 'arrow_down.png')), + matchesGoldenFile(goldenFile.getFileUri('arrow_down')), ); }); @@ -159,7 +157,7 @@ void main() { // Verifying the CustomPaint with different arrow directions. await expectLater( find.byType(ZetaTooltip), - matchesGoldenFile(join(getCurrentPath('tooltip'), 'arrow_left.png')), + matchesGoldenFile(goldenFile.getFileUri('arrow_left')), ); }); @@ -180,7 +178,7 @@ void main() { // Verifying the CustomPaint with different arrow directions. await expectLater( find.byType(ZetaTooltip), - matchesGoldenFile(join(getCurrentPath('tooltip'), 'arrow_right.png')), + matchesGoldenFile(goldenFile.getFileUri('arrow_right')), ); }); diff --git a/test/src/components/top_app_bar/extended_top_app_bar_test.dart b/test/src/components/top_app_bar/extended_top_app_bar_test.dart index 379b2a14..ecc49885 100644 --- a/test/src/components/top_app_bar/extended_top_app_bar_test.dart +++ b/test/src/components/top_app_bar/extended_top_app_bar_test.dart @@ -1,6 +1,5 @@ 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'; @@ -8,9 +7,10 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { + const goldenFile = GoldenFiles(component: 'top_app_bar'); + setUpAll(() { - final testUri = Uri.parse(getCurrentPath('top_app_bar')); - goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01); + goldenFileComparator = TolerantComparator(goldenFile.uri); }); testWidgets('ZetaExtendedAppBarDelegate builds correctly', (WidgetTester tester) async { @@ -65,7 +65,7 @@ void main() { await expectLater( appBarFinder, - matchesGoldenFile(join(getCurrentPath('top_app_bar'), 'extended_app_bar_shrinks.png')), + matchesGoldenFile(goldenFile.getFileUri('extended_app_bar_shrinks')), ); }); @@ -163,7 +163,7 @@ void main() { await expectLater( appBarFinder, - matchesGoldenFile(join(getCurrentPath('top_app_bar'), 'extended_app_bar_shrinks_with_no_leading.png')), + matchesGoldenFile(goldenFile.getFileUri('extended_app_bar_shrinks_with_no_leading')), ); }); } diff --git a/test/test_utils/tolerant_comparator.dart b/test/test_utils/tolerant_comparator.dart index 7e5bdda4..fdfeed03 100644 --- a/test/test_utils/tolerant_comparator.dart +++ b/test/test_utils/tolerant_comparator.dart @@ -5,13 +5,13 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:image/image.dart' as img; class TolerantComparator extends LocalFileComparator { - TolerantComparator(super.testFile, {this.tolerance = 0.0}); + TolerantComparator(Uri testFile, {this.tolerance = 0.01}) : super(testFile.replace(scheme: 'file')); final double tolerance; @override Future compare(Uint8List imageBytes, Uri golden) async { - final goldenFile = File.fromUri(golden); + final goldenFile = File.fromUri(golden.replace(scheme: 'file')); if (!goldenFile.existsSync()) { goldenFile ..createSync(recursive: true) diff --git a/test/test_utils/utils.dart b/test/test_utils/utils.dart index 1afb1742..e8e7acc2 100644 --- a/test/test_utils/utils.dart +++ b/test/test_utils/utils.dart @@ -4,10 +4,6 @@ import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; import 'package:path/path.dart'; -String getCurrentPath(String component, {String type = 'components'}) { - return join(Directory.current.path, 'test', 'src', type, component, 'golden'); -} - extension Util on DiagnosticPropertiesBuilder { dynamic finder(String finder) { return properties.where((p) => p.name == finder).map((p) => p.toDescription()).firstOrNull; @@ -17,3 +13,17 @@ extension Util on DiagnosticPropertiesBuilder { return properties.firstWhereOrNull((p) => p.name == propertyName)?.value; } } + +class GoldenFiles { + const GoldenFiles({required this.component, this.type = 'components'}); + + final String component; + final String type; + + Uri get uri => getFileUri(''); + + Uri getFileUri(String fileName) { + return Uri.parse(join(Directory.current.path, 'test', 'src', type, component, 'golden', '$fileName.png')) + .replace(scheme: 'file'); + } +}