diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index c58f8ab5..a55af954 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -41,7 +41,7 @@ jobs: fi deploy-preview: - name: Deploy preview version of the storybook on firebase + name: Deploy preview version of the widgetbook on firebase needs: [code-quality, check-secret] if: needs.check-secret.outputs.secret-exists == 'true' runs-on: ubuntu-latest diff --git a/test/TESTING_README.mdx b/test/TESTING_README.md similarity index 72% rename from test/TESTING_README.mdx rename to test/TESTING_README.md index 0789e872..a98b8042 100644 --- a/test/TESTING_README.mdx +++ b/test/TESTING_README.md @@ -11,24 +11,34 @@ As you are writing tests think about helper function you could write and add the ### Groups -- Accessibility Tests +- **Accessibility Tests** Semantic labels, touch areas, contrast ratios, etc. -- Content Tests - Finds the widget, parameter statuses, etc. -- Dimensions Tests - Size, padding, margin, alignment, etc. -- Styling Tests + +- **Content Tests** + Finds the widget, parameter statuses, etc. + Checking for the value of props and attributes of the widget. Checking for the presence of widgets. + +- **Dimensions Tests** + Size, padding, margin, alignment, etc. + getSize(). + +- **Styling Tests** Rendered colors, fonts, borders, radii etc. -- Interaction Tests + Checking the style of widgets and child widgets. + +- **Interaction Tests** Gesture recognizers, taps, drags, etc. -- Golden Tests + For example, using a boolean to check if the widgets interaction function runs. + +- **Golden Tests** Compares the rendered widget with the golden file. Use the `goldenTest()` function from test_utils/utils.dart. -- Performance Tests + +- **Performance Tests** Animation performance, rendering performance, data manupulation performance, etc. ### Testing File Template -``` +```dart import 'dart:ui'; import 'package:flutter/foundation.dart'; @@ -41,7 +51,6 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { - const String componentName = 'ENTER_COMPONENT_NAME (e.g. ZetaButton)'; const String parentFolder = 'ENTER_PARENT_FOLDER (e.g. button)'; const goldenFile = GoldenFiles(component: parentFolder); @@ -49,8 +58,8 @@ void main() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - group('$componentName Accessibility Tests', () {}); - group('$componentName Content Tests', () { + group('Accessibility Tests', () {}); + group('Content Tests', () { final debugFillProperties = { '': '', }; @@ -59,13 +68,13 @@ void main() { debugFillProperties, ); }); - group('$componentName Dimensions Tests', () {}); - group('$componentName Styling Tests', () {}); - group('$componentName Interaction Tests', () {}); - group('$componentName Golden Tests', () { + group('Dimensions Tests', () {}); + group('Styling Tests', () {}); + group('Interaction Tests', () {}); + group('Golden Tests', () { goldenTest(goldenFile, widget, widgetType, 'PNG_FILE_NAME'); }); - group('$componentName Performance Tests', () {}); + group('Performance Tests', () {}); } ``` diff --git a/test/scripts/output/test_table.md b/test/scripts/output/test_table.md new file mode 100644 index 00000000..06d85966 --- /dev/null +++ b/test/scripts/output/test_table.md @@ -0,0 +1,26 @@ +| Component | Accessibility | Content | Dimensions | Styling | Interaction | Golden | Performance | Unorganised | Total Tests | +| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | +| Accordion | 0 | 2 | 0 | 1 | 2 | 0 | 0 | 0 | 5 | +| Avatar | 1 | 3 | 6 | 5 | 0 | 6 | 0 | 0 | 21 | +| Indicator | 0 | 7 | 0 | 0 | 0 | 5 | 0 | 0 | 12 | +| Label | 0 | 8 | 0 | 0 | 0 | 7 | 0 | 0 | 15 | +| Priority Pill | 0 | 5 | 0 | 0 | 0 | 4 | 0 | 0 | 9 | +| Status Label | 0 | 3 | 0 | 0 | 0 | 2 | 0 | 0 | 5 | +| Tag | 0 | 3 | 0 | 0 | 0 | 2 | 0 | 0 | 5 | +| Banner | 3 | 4 | 0 | 3 | 0 | 1 | 0 | 3 | 14 | +| Button | 0 | 10 | 0 | 2 | 1 | 8 | 0 | 0 | 21 | +| Chat Item | 0 | 10 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | +| Checkbox | 0 | 3 | 0 | 0 | 3 | 2 | 0 | 0 | 8 | +| Chip | 0 | 1 | 0 | 0 | 5 | 0 | 0 | 0 | 6 | +| Comms Button | 2 | 7 | 0 | 0 | 0 | 1 | 0 | 0 | 10 | +| Dialpad | 0 | 2 | 0 | 1 | 2 | 3 | 0 | 0 | 8 | +| Fab | 0 | 6 | 0 | 1 | 1 | 4 | 0 | 0 | 12 | +| Icon | 1 | 4 | 1 | 6 | 0 | 0 | 0 | 0 | 12 | +| In Page Banner | 0 | 4 | 0 | 4 | 2 | 4 | 0 | 0 | 14 | +| Password Input | 0 | 4 | 0 | 0 | 0 | 1 | 0 | 0 | 5 | +| Search Bar | 0 | 5 | 0 | 0 | 5 | 5 | 0 | 0 | 15 | +| Slider | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | +| Stepper Input | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 2 | +| Tooltip | 0 | 3 | 1 | 3 | 0 | 4 | 0 | 0 | 11 | +| Extended Top App Bar | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | 3 | +| Total Tests | 7 | 95 | 8 | 26 | 23 | 59 | 0 | 6 | 224 | \ No newline at end of file diff --git a/test/scripts/test_counter.dart b/test/scripts/test_counter.dart index 72dafe74..a74a69d3 100644 --- a/test/scripts/test_counter.dart +++ b/test/scripts/test_counter.dart @@ -124,7 +124,7 @@ class TestVisitor extends RecursiveAstVisitor { } } -/// Generates an MDX (Markdown Extended) table representation of the test counts. +/// Generates an MD (Markdown) table representation of the test counts. /// /// The function takes a nested map where the outer map's keys are test group names, /// and the inner map's keys are test names with their corresponding integer counts. @@ -139,7 +139,7 @@ class TestVisitor extends RecursiveAstVisitor { /// ``` /// /// Example output: -/// ```mdx +/// ```md /// | Component | Accessibility | Content | Dimensions | Styling | Interaction | Golden | Performance | Unorganised | Total Tests | /// | ----------- | ------------- | ------- | ---------- | ------- | ----------- | ------ | ----------- | ----------- | ----------- | /// | Banner | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | @@ -151,8 +151,8 @@ class TestVisitor extends RecursiveAstVisitor { /// of test names with their corresponding counts. /// /// Returns: -/// - A string in MDX format representing the test counts in a table with totals. -String generateMDX(Map> testCount) { +/// - A string in MD format representing the test counts in a table with totals. +String generateMD(Map> testCount) { final Map groupTotals = { 'Accessibility': 0, 'Content': 0, @@ -228,14 +228,17 @@ void main() async { final TestGroups testGroups = await parseTestFiles(testFiles); // write test groups to file - await writeJSONToFile('${outputDirectory.path}/test_groups.json', testGroups); + // await writeJSONToFile('${outputDirectory.path}/test_groups.json', testGroups); // count the number of tests in each group final TestCount testCount = countTests(testGroups); // write test counts to file - await writeJSONToFile('${outputDirectory.path}/test_counts.json', testCount); + // await writeJSONToFile('${outputDirectory.path}/test_counts.json', testCount); - // generate MDX table - await writeMDXToFile('${outputDirectory.path}/test_table.mdx', generateMDX(testCount)); + // generate MD table + await writeMDToFile('${outputDirectory.path}/test_table.md', generateMD(testCount)); + + // ignore: avoid_print + print('Test table generated successfully!'); } diff --git a/test/scripts/utils/utils.dart b/test/scripts/utils/utils.dart index bcfc30c3..d5796eb3 100644 --- a/test/scripts/utils/utils.dart +++ b/test/scripts/utils/utils.dart @@ -58,11 +58,7 @@ extension NodeExtension on MethodInvocation { /// Returns: /// A [String] containing the sanitized name of the group. String getGroupName() { - return argumentList.arguments.first - .toString() - .replaceAll("'", '') - .replaceAll(r'$componentName ', '') - .replaceAll(' Tests', ''); + return argumentList.arguments.first.toString().replaceAll("'", '').replaceAll(' Tests', ''); } /// Retrieves and sanitizes the name of the test. @@ -185,16 +181,16 @@ Future writeJSONToFile(String path, dynamic content) async { await outputFileGroups.writeAsString(jsonOutputGroups); } -/// Writes the given MDX data to a file at the specified path. +/// Writes the given MD data to a file at the specified path. /// -/// This function asynchronously writes the provided MDX data to a file +/// This function asynchronously writes the provided MD data to a file /// located at the given path. If the file does not exist, it will be created. /// -/// [path] The file path where the MDX data should be written. -/// [mdxData] The MDX data to write to the file. -Future writeMDXToFile(String path, String mdxData) async { - final mdxFile = File(path); - await mdxFile.writeAsString(mdxData); +/// [path] The file path where the MD data should be written. +/// [mdData] The MD data to write to the file. +Future writeMDToFile(String path, String mdData) async { + final mdFile = File(path); + await mdFile.writeAsString(mdData); } extension ListExtension on List { diff --git a/test/src/components/accordion/accordion_test.dart b/test/src/components/accordion/accordion_test.dart index 7cc78fe4..6ad08458 100644 --- a/test/src/components/accordion/accordion_test.dart +++ b/test/src/components/accordion/accordion_test.dart @@ -1,6 +1,5 @@ import 'dart:ui'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; @@ -9,145 +8,154 @@ import '../../../test_utils/test_app.dart'; import '../../../test_utils/utils.dart'; void main() { - testWidgets('ZetaAccordion expands and collapses correctly', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: ZetaAccordion( - title: 'Accordion Title', - child: Text('Accordion Content'), - ), + group('Accessibility Tests', () {}); + group('Content Tests', () { + final debugFillProperties = { + 'title': '"Title"', + 'rounded': 'null', + 'contained': 'false', + 'isOpen': 'false', + }; + debugFillPropertiesTest( + const ZetaAccordion( + title: 'Title', ), + debugFillProperties, ); - // Verify that the accordion is initially collapsed - final Finder accordionContent = find.byType(SizeTransition); - expect(accordionContent, findsOneWidget); - - final SizeTransition sizeTransition = tester.widget(accordionContent); - expect(sizeTransition.sizeFactor.value, 0); - - // Tap on the accordion to expand it - await tester.tap(find.text('Accordion Title')); - await tester.pumpAndSettle(); - - // Verify that the accordion is now expanded - expect(sizeTransition.sizeFactor.value, 1); - - // Tap on the accordion again to collapse it - await tester.tap(find.text('Accordion Title')); - await tester.pumpAndSettle(); - - expect(sizeTransition.sizeFactor.value, 0); - }); - - testWidgets('ZetaAccordion changes isOpen property correctly', (WidgetTester tester) async { - bool isOpen = false; - StateSetter? setState; + testWidgets('Programatically change child', (WidgetTester tester) async { + Widget? child = const Text('Text 1'); + StateSetter? setState; - await tester.pumpWidget( - TestApp( - home: StatefulBuilder( + await tester.pumpWidget( + StatefulBuilder( builder: (context, setState2) { setState = setState2; - return ZetaAccordion( - title: 'Accordion Title', - isOpen: isOpen, - child: const Text('Accordion Content'), + return TestApp( + home: ZetaAccordion( + title: 'Accordion Title', + child: child, + ), ); }, ), - ), - ); - - // Verify that the accordion is initially closed - final Finder accordionContent = find.byType(SizeTransition); - expect(accordionContent, findsOneWidget); - - final SizeTransition sizeTransition = tester.widget(accordionContent); - expect(sizeTransition.sizeFactor.value, 0); - - // Change isOpen property to true - setState?.call(() => isOpen = true); - - await tester.pumpAndSettle(); - - // Verify that the accordion is now open - expect(sizeTransition.sizeFactor.value, 1); - - // Change isOpen property to false - setState?.call(() => isOpen = false); + ); + + final Finder accordionContent = find.text('Text 1'); + expect(accordionContent, findsOneWidget); + setState?.call(() => child = null); + await tester.pumpAndSettle(); + expect(accordionContent, findsNothing); + }); + }); + group('Dimensions Tests', () {}); + group('Styling Tests', () { + testWidgets('ZetaAccordion changes color on hover', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: ZetaAccordion( + title: 'Accordion Title', + child: Text('Accordion Content'), + ), + ), + ); + + final textButtonFinder = find.byType(TextButton); + final textButton = tester.widget(textButtonFinder); + final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); + await gesture.addPointer(location: Offset.zero); + addTearDown(gesture.removePointer); + + await tester.pump(); + await gesture.moveTo(tester.getCenter(find.byType(ZetaAccordion))); + await tester.pumpAndSettle(); + // Verify that the textButton color matches the hover color + expect( + textButton.style!.overlayColor?.resolve({WidgetState.hovered}), + ZetaColorBase.cool.shade20, + ); + expect( + textButton.style!.overlayColor?.resolve({WidgetState.focused}), + Colors.transparent, + ); + expect(textButton.style!.side?.resolve({WidgetState.focused})?.color, ZetaColorBase.blue.shade50); + }); + }); + group('Interaction Tests', () { + testWidgets('ZetaAccordion expands and collapses correctly', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: ZetaAccordion( + title: 'Accordion Title', + child: Text('Accordion Content'), + ), + ), + ); + + // Verify that the accordion is initially collapsed + final Finder accordionContent = find.byType(SizeTransition); + expect(accordionContent, findsOneWidget); + + final SizeTransition sizeTransition = tester.widget(accordionContent); + expect(sizeTransition.sizeFactor.value, 0); + + // Tap on the accordion to expand it + await tester.tap(find.text('Accordion Title')); + await tester.pumpAndSettle(); + + // Verify that the accordion is now expanded + expect(sizeTransition.sizeFactor.value, 1); + + // Tap on the accordion again to collapse it + await tester.tap(find.text('Accordion Title')); + await tester.pumpAndSettle(); + + expect(sizeTransition.sizeFactor.value, 0); + }); + + testWidgets('ZetaAccordion changes isOpen property correctly', (WidgetTester tester) async { + bool isOpen = false; + StateSetter? setState; + + await tester.pumpWidget( + TestApp( + home: StatefulBuilder( + builder: (context, setState2) { + setState = setState2; + return ZetaAccordion( + title: 'Accordion Title', + isOpen: isOpen, + child: const Text('Accordion Content'), + ); + }, + ), + ), + ); - await tester.pumpAndSettle(); + // Verify that the accordion is initially closed + final Finder accordionContent = find.byType(SizeTransition); + expect(accordionContent, findsOneWidget); - // Verify that the accordion is now closed - expect(sizeTransition.sizeFactor.value, 0); - }); + final SizeTransition sizeTransition = tester.widget(accordionContent); + expect(sizeTransition.sizeFactor.value, 0); - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - const ZetaAccordion( - title: 'Title', - ).debugFillProperties(diagnostics); + // Change isOpen property to true + setState?.call(() => isOpen = true); - expect(diagnostics.finder('title'), '"Title"'); - expect(diagnostics.finder('rounded'), 'null'); - expect(diagnostics.finder('contained'), 'false'); - expect(diagnostics.finder('isOpen'), 'false'); - }); + await tester.pumpAndSettle(); - testWidgets('Programatically change child', (WidgetTester tester) async { - Widget? child = const Text('Text 1'); - StateSetter? setState; - - await tester.pumpWidget( - StatefulBuilder( - builder: (context, setState2) { - setState = setState2; - return TestApp( - home: ZetaAccordion( - title: 'Accordion Title', - child: child, - ), - ); - }, - ), - ); + // Verify that the accordion is now open + expect(sizeTransition.sizeFactor.value, 1); - final Finder accordionContent = find.text('Text 1'); - expect(accordionContent, findsOneWidget); - setState?.call(() => child = null); - await tester.pumpAndSettle(); - expect(accordionContent, findsNothing); - }); + // Change isOpen property to false + setState?.call(() => isOpen = false); - testWidgets('ZetaAccordion changes color on hover', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: ZetaAccordion( - title: 'Accordion Title', - child: Text('Accordion Content'), - ), - ), - ); + await tester.pumpAndSettle(); - final textButtonFinder = find.byType(TextButton); - final textButton = tester.widget(textButtonFinder); - final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); - await gesture.addPointer(location: Offset.zero); - addTearDown(gesture.removePointer); - - await tester.pump(); - await gesture.moveTo(tester.getCenter(find.byType(ZetaAccordion))); - await tester.pumpAndSettle(); - // Verify that the textButton color matches the hover color - expect( - textButton.style!.overlayColor?.resolve({WidgetState.hovered}), - ZetaColorBase.cool.shade20, - ); - expect( - textButton.style!.overlayColor?.resolve({WidgetState.focused}), - Colors.transparent, - ); - expect(textButton.style!.side?.resolve({WidgetState.focused})?.color, ZetaColorBase.blue.shade50); + // Verify that the accordion is now closed + expect(sizeTransition.sizeFactor.value, 0); + }); }); + group('Golden Tests', () {}); + group('Performance Tests', () {}); } diff --git a/test/src/components/avatar/avatar_test.dart b/test/src/components/avatar/avatar_test.dart index 9376f890..7e02d661 100644 --- a/test/src/components/avatar/avatar_test.dart +++ b/test/src/components/avatar/avatar_test.dart @@ -9,13 +9,14 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { - const goldenFile = GoldenFiles(component: 'avatar'); + const String parentFolder = 'avatar'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - group('ZetaAvatar Accessibility Tests', () { + group('Accessibility Tests', () { testWidgets('ZetaAvatar meets accessibility requirements', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); await tester.pumpWidget( @@ -43,7 +44,24 @@ void main() { }); }); - group('ZetaAvatar Content Tests', () { + group('Content Tests', () { + final debugFillProperties = { + 'size': 'ZetaAvatarSize.xl', + 'name': 'null', + 'specialStatus': 'null', + 'badge': 'null', + 'backgroundColor': 'null', + 'statusColor': 'null', + 'semanticUpperBadgeValue': '"upperBadge"', + 'semanticValue': '"avatar"', + 'semanticLowerBadgeValue': '"lowerBadge"', + 'initialTextStyle': 'null', + }; + debugFillPropertiesTest( + const ZetaAvatar(), + debugFillProperties, + ); + const names = [ 'John Doe', 'Jane Doe', @@ -96,7 +114,7 @@ void main() { } }); - group('ZetaAvatar Dimensions Tests', () { + group('Dimensions Tests', () { for (final size in ZetaAvatarSize.values) { testWidgets( 'ZetaAvatar size $size with upper badge', @@ -211,7 +229,7 @@ void main() { } }); - group('ZetaAvatar Styling Tests', () { + group('Styling Tests', () { for (final size in ZetaAvatarSize.values) { testWidgets('ZetaAvatar with initials $size text size is correct', (WidgetTester tester) async { await tester.pumpWidget( @@ -295,106 +313,65 @@ void main() { } }); - group('ZetaAvatar Interaction Tests', () {}); + group('Interaction Tests', () {}); - group('ZetaAvatar Golden Tests', () { + group('Golden Tests', () { for (final size in ZetaAvatarSize.values) { - testWidgets('ZetaAvatar default ${size.toString().split('.').last}', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaAvatar( - size: size, - ), - ), - ); - - await expectLater( - find.byType(ZetaAvatar), - matchesGoldenFile(goldenFile.getFileUri('avatar_default_${size.toString().split('.').last}')), - ); - }); - - testWidgets('ZetaAvatar with initials', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaAvatar.initials( - initials: 'AB', - size: size, - ), - ), - ); - - await expectLater( - find.byType(ZetaAvatar), - matchesGoldenFile(goldenFile.getFileUri('avatar_initials_${size.toString().split('.').last}')), - ); - }); - - testWidgets('ZetaAvatar with image', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaAvatar.image( - image: Image.file(File('/assets/maxresdefault.jpg')), - size: size, - ), - ), - ); - - await expectLater( - find.byType(ZetaAvatar), - matchesGoldenFile(goldenFile.getFileUri('avatar_image_${size.toString().split('.').last}')), - ); - }); - - testWidgets('ZetaAvatar with fromName', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaAvatar.fromName( - name: 'John Doe', - size: size, - ), - ), - ); - - await expectLater( - find.byType(ZetaAvatar), - matchesGoldenFile(goldenFile.getFileUri('avatar_from_name_${size.toString().split('.').last}')), - ); - }); - - testWidgets('ZetaAvatar with upper badge', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaAvatar( - upperBadge: const ZetaAvatarBadge.notification(value: 3), - size: size, - ), - ), - ); - - await expectLater( - find.byType(ZetaAvatar), - matchesGoldenFile(goldenFile.getFileUri('avatar_upper_badge_${size.toString().split('.').last}')), - ); - }); - - testWidgets('ZetaAvatar with lower badge', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaAvatar( - lowerBadge: const ZetaAvatarBadge.icon(icon: Icons.star), - size: size, - ), - ), - ); - - await expectLater( - find.byType(ZetaAvatar), - matchesGoldenFile(goldenFile.getFileUri('avatar_lower_badge_${size.toString().split('.').last}')), - ); - }); + goldenTest( + goldenFile, + ZetaAvatar( + size: size, + ), + ZetaAvatar, + 'avatar_default_${size.toString().split('.').last}', + ); + goldenTest( + goldenFile, + ZetaAvatar.initials( + initials: 'AB', + size: size, + ), + ZetaAvatar, + 'avatar_initials_${size.toString().split('.').last}', + ); + goldenTest( + goldenFile, + ZetaAvatar.image( + image: Image.file(File('/assets/maxresdefault.jpg')), + size: size, + ), + ZetaAvatar, + 'avatar_image_${size.toString().split('.').last}', + ); + goldenTest( + goldenFile, + ZetaAvatar.fromName( + name: 'John Doe', + size: size, + ), + ZetaAvatar, + 'avatar_from_name_${size.toString().split('.').last}', + ); + goldenTest( + goldenFile, + ZetaAvatar( + upperBadge: const ZetaAvatarBadge.notification(value: 3), + size: size, + ), + ZetaAvatar, + 'avatar_upper_badge_${size.toString().split('.').last}', + ); + goldenTest( + goldenFile, + ZetaAvatar( + lowerBadge: const ZetaAvatarBadge.icon(icon: Icons.star), + size: size, + ), + ZetaAvatar, + 'avatar_lower_badge_${size.toString().split('.').last}', + ); } }); - group('ZetaAvatar Performance Tests', () {}); + group('Performance Tests', () {}); } diff --git a/test/src/components/avatar/golden/avatar_from_name_xs.png b/test/src/components/avatar/golden/avatar_from_name_xs.png index ec8f22c7..9f715e2a 100644 Binary files a/test/src/components/avatar/golden/avatar_from_name_xs.png and b/test/src/components/avatar/golden/avatar_from_name_xs.png differ diff --git a/test/src/components/avatar/golden/avatar_initials_xs.png b/test/src/components/avatar/golden/avatar_initials_xs.png index ec8f22c7..9f715e2a 100644 Binary files a/test/src/components/avatar/golden/avatar_initials_xs.png and b/test/src/components/avatar/golden/avatar_initials_xs.png differ diff --git a/test/src/components/badge/golden/indicator_default.png b/test/src/components/badge/golden/indicator_default.png index 291fd461..51235d00 100644 Binary files a/test/src/components/badge/golden/indicator_default.png and b/test/src/components/badge/golden/indicator_default.png differ diff --git a/test/src/components/badge/golden/indicator_icon_default.png b/test/src/components/badge/golden/indicator_icon_default.png index c472cd38..c29ecee4 100644 Binary files a/test/src/components/badge/golden/indicator_icon_default.png and b/test/src/components/badge/golden/indicator_icon_default.png differ diff --git a/test/src/components/badge/golden/indicator_icon_values.png b/test/src/components/badge/golden/indicator_icon_values.png index 96e73834..9c17abf9 100644 Binary files a/test/src/components/badge/golden/indicator_icon_values.png and b/test/src/components/badge/golden/indicator_icon_values.png differ diff --git a/test/src/components/badge/golden/indicator_notification_default.png b/test/src/components/badge/golden/indicator_notification_default.png index 291fd461..51235d00 100644 Binary files a/test/src/components/badge/golden/indicator_notification_default.png and b/test/src/components/badge/golden/indicator_notification_default.png differ diff --git a/test/src/components/badge/golden/indicator_notification_values.png b/test/src/components/badge/golden/indicator_notification_values.png index 60afdfc9..45ceb87c 100644 Binary files a/test/src/components/badge/golden/indicator_notification_values.png and b/test/src/components/badge/golden/indicator_notification_values.png differ diff --git a/test/src/components/badge/golden/label_dark.png b/test/src/components/badge/golden/label_dark.png index 56650a35..a694b52a 100644 Binary files a/test/src/components/badge/golden/label_dark.png and b/test/src/components/badge/golden/label_dark.png differ diff --git a/test/src/components/badge/golden/label_default.png b/test/src/components/badge/golden/label_default.png index ab898e1a..4d0f0a23 100644 Binary files a/test/src/components/badge/golden/label_default.png and b/test/src/components/badge/golden/label_default.png differ diff --git a/test/src/components/badge/golden/label_negative.png b/test/src/components/badge/golden/label_negative.png index efd6692b..7f57efd0 100644 Binary files a/test/src/components/badge/golden/label_negative.png and b/test/src/components/badge/golden/label_negative.png differ diff --git a/test/src/components/badge/golden/label_neutral.png b/test/src/components/badge/golden/label_neutral.png index 8dc692ca..47cb8da9 100644 Binary files a/test/src/components/badge/golden/label_neutral.png and b/test/src/components/badge/golden/label_neutral.png differ diff --git a/test/src/components/badge/golden/label_positive.png b/test/src/components/badge/golden/label_positive.png index 5df40805..537944fa 100644 Binary files a/test/src/components/badge/golden/label_positive.png and b/test/src/components/badge/golden/label_positive.png differ diff --git a/test/src/components/badge/golden/label_sharp.png b/test/src/components/badge/golden/label_sharp.png index 3e96a777..5d02c668 100644 Binary files a/test/src/components/badge/golden/label_sharp.png and b/test/src/components/badge/golden/label_sharp.png differ diff --git a/test/src/components/badge/golden/label_warning.png b/test/src/components/badge/golden/label_warning.png index b4091b2c..2342243e 100644 Binary files a/test/src/components/badge/golden/label_warning.png and b/test/src/components/badge/golden/label_warning.png differ diff --git a/test/src/components/badge/golden/priority_pill_default.png b/test/src/components/badge/golden/priority_pill_default.png index 3ec6f2a1..6ff50feb 100644 Binary files a/test/src/components/badge/golden/priority_pill_default.png and b/test/src/components/badge/golden/priority_pill_default.png differ diff --git a/test/src/components/badge/golden/priority_pill_high.png b/test/src/components/badge/golden/priority_pill_high.png index 0384a884..02c9e252 100644 Binary files a/test/src/components/badge/golden/priority_pill_high.png and b/test/src/components/badge/golden/priority_pill_high.png differ diff --git a/test/src/components/badge/golden/priority_pill_low.png b/test/src/components/badge/golden/priority_pill_low.png index 6199e19f..ff465b65 100644 Binary files a/test/src/components/badge/golden/priority_pill_low.png and b/test/src/components/badge/golden/priority_pill_low.png differ diff --git a/test/src/components/badge/golden/priority_pill_medium.png b/test/src/components/badge/golden/priority_pill_medium.png index e5a1ab11..196178df 100644 Binary files a/test/src/components/badge/golden/priority_pill_medium.png and b/test/src/components/badge/golden/priority_pill_medium.png differ diff --git a/test/src/components/badge/golden/status_label_custom.png b/test/src/components/badge/golden/status_label_custom.png index dd961c4f..b3fd2c0b 100644 Binary files a/test/src/components/badge/golden/status_label_custom.png and b/test/src/components/badge/golden/status_label_custom.png differ diff --git a/test/src/components/badge/golden/status_label_default.png b/test/src/components/badge/golden/status_label_default.png index 00459554..a6807b7a 100644 Binary files a/test/src/components/badge/golden/status_label_default.png and b/test/src/components/badge/golden/status_label_default.png differ diff --git a/test/src/components/badge/golden/tag_left.png b/test/src/components/badge/golden/tag_left.png index 879b23a6..f2005eec 100644 Binary files a/test/src/components/badge/golden/tag_left.png and b/test/src/components/badge/golden/tag_left.png differ diff --git a/test/src/components/badge/golden/tag_right.png b/test/src/components/badge/golden/tag_right.png index 2f860de3..1951b8be 100644 Binary files a/test/src/components/badge/golden/tag_right.png and b/test/src/components/badge/golden/tag_right.png differ diff --git a/test/src/components/badge/indicator_test.dart b/test/src/components/badge/indicator_test.dart index cf732149..12f768e5 100644 --- a/test/src/components/badge/indicator_test.dart +++ b/test/src/components/badge/indicator_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; @@ -7,169 +6,183 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { - const goldenFile = GoldenFiles(component: 'badge'); + const String parentFolder = 'badge'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - testWidgets('Default constructor initializes with correct parameters', (WidgetTester tester) async { - await tester.pumpWidget(const TestApp(home: ZetaIndicator())); - - final zetaIndicatorFinder = find.byType(ZetaIndicator); - final ZetaIndicator indicator = tester.firstWidget(zetaIndicatorFinder); - - expect(indicator.rounded, null); - expect(indicator.type, ZetaIndicatorType.notification); - expect(indicator.size, ZetaWidgetSize.large); - expect(indicator.icon, null); - expect(indicator.value, null); - expect(indicator.inverse, false); - expect(indicator.color, null); - - await expectLater( - find.byType(ZetaIndicator), - matchesGoldenFile(goldenFile.getFileUri('indicator_default')), - ); - }); - - testWidgets('Copy with function works', (WidgetTester tester) async { - const Key key1 = Key('1'); - const Key key2 = Key('2'); - const ZetaIndicator one = ZetaIndicator(key: key1); - final ZetaIndicator two = one.copyWith( - key: key2, - ); - await tester.pumpWidget(TestApp(home: Column(children: [one, two]))); - - final zetaIndicatorFinder1 = find.byKey(key1); - final ZetaIndicator indicator1 = tester.firstWidget(zetaIndicatorFinder1); - final zetaIndicatorFinder2 = find.byKey(key2); - final ZetaIndicator indicator2 = tester.firstWidget(zetaIndicatorFinder2); - - expect(indicator1.rounded, null); - expect(indicator1.type, ZetaIndicatorType.notification); - expect(indicator1.size, ZetaWidgetSize.large); - expect(indicator1.icon, null); - expect(indicator1.value, null); - expect(indicator1.inverse, false); - expect(indicator1.color, null); - - expect(indicator2.rounded, null); - }); - testWidgets('Icon constructor initializes with correct parameters', (WidgetTester tester) async { - await tester.pumpWidget(const TestApp(home: ZetaIndicator.icon())); - - final zetaIndicatorFinder = find.byType(ZetaIndicator); - final ZetaIndicator indicator = tester.firstWidget(zetaIndicatorFinder); - - expect(indicator.rounded, null); - expect(indicator.type, ZetaIndicatorType.icon); - expect(indicator.size, ZetaWidgetSize.large); - expect(indicator.icon, null); - expect(indicator.value, null); - expect(indicator.inverse, false); - expect(indicator.color, null); - - await expectLater( - find.byType(ZetaIndicator), - matchesGoldenFile(goldenFile.getFileUri('indicator_icon_default')), - ); - }); - testWidgets('Icon constructor with values', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: ZetaIndicator.icon( - color: Colors.purple, - icon: Icons.abc, - inverse: true, - size: ZetaWidgetSize.medium, - ), + group('Accessibility Tests', () {}); + group('Content Tests', () { + final debugFillProperties = { + 'color': 'MaterialColor(primary value: Color(0xffff9800))', + 'icon': 'IconData(U+F04B6)', + 'inverse': 'true', + 'rounded': 'false', + 'size': 'ZetaWidgetSize.small', + 'type': 'ZetaIndicatorType.icon', + 'value': '1', + }; + debugFillPropertiesTest( + const ZetaIndicator( + color: Colors.orange, + icon: Icons.abc, + inverse: true, + rounded: false, + size: ZetaWidgetSize.small, + type: ZetaIndicatorType.icon, + value: 1, ), + debugFillProperties, ); - final zetaIndicatorFinder = find.byType(ZetaIndicator); - final ZetaIndicator indicator = tester.firstWidget(zetaIndicatorFinder); - - expect(indicator.rounded, null); - expect(indicator.type, ZetaIndicatorType.icon); - expect(indicator.size, ZetaWidgetSize.medium); - expect(indicator.icon, Icons.abc); - expect(indicator.value, null); - expect(indicator.inverse, true); - expect(indicator.color, Colors.purple); - - await expectLater( - find.byType(ZetaIndicator), - matchesGoldenFile(goldenFile.getFileUri('indicator_icon_values')), - ); - }); - testWidgets('Notification constructor initializes with correct parameters', (WidgetTester tester) async { - await tester.pumpWidget(const TestApp(home: ZetaIndicator.notification())); - - final zetaIndicatorFinder = find.byType(ZetaIndicator); - final ZetaIndicator indicator = tester.firstWidget(zetaIndicatorFinder); - - expect(indicator.rounded, null); - expect(indicator.type, ZetaIndicatorType.notification); - expect(indicator.size, ZetaWidgetSize.large); - expect(indicator.icon, null); - expect(indicator.value, null); - expect(indicator.inverse, false); - expect(indicator.color, null); - - await expectLater( - find.byType(ZetaIndicator), - matchesGoldenFile(goldenFile.getFileUri('indicator_notification_default')), - ); - }); - testWidgets('Notification constructor with values', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: ZetaIndicator.notification( - rounded: false, - color: Colors.green, - inverse: true, - size: ZetaWidgetSize.small, - value: 1, + testWidgets('Default constructor initializes with correct parameters', (WidgetTester tester) async { + await tester.pumpWidget(const TestApp(home: ZetaIndicator())); + + final zetaIndicatorFinder = find.byType(ZetaIndicator); + final ZetaIndicator indicator = tester.firstWidget(zetaIndicatorFinder); + + expect(indicator.rounded, null); + expect(indicator.type, ZetaIndicatorType.notification); + expect(indicator.size, ZetaWidgetSize.large); + expect(indicator.icon, null); + expect(indicator.value, null); + expect(indicator.inverse, false); + expect(indicator.color, null); + }); + + testWidgets('Copy with function works', (WidgetTester tester) async { + const Key key1 = Key('1'); + const Key key2 = Key('2'); + + const ZetaIndicator one = ZetaIndicator(key: key1); + final ZetaIndicator two = one.copyWith( + key: key2, + ); + await tester.pumpWidget(TestApp(home: Column(children: [one, two]))); + + final zetaIndicatorFinder1 = find.byKey(key1); + final ZetaIndicator indicator1 = tester.firstWidget(zetaIndicatorFinder1); + final zetaIndicatorFinder2 = find.byKey(key2); + final ZetaIndicator indicator2 = tester.firstWidget(zetaIndicatorFinder2); + + expect(indicator1.rounded, null); + expect(indicator1.type, ZetaIndicatorType.notification); + expect(indicator1.size, ZetaWidgetSize.large); + expect(indicator1.icon, null); + expect(indicator1.value, null); + expect(indicator1.inverse, false); + expect(indicator1.color, null); + + expect(indicator2.rounded, null); + }); + testWidgets('Icon constructor initializes with correct parameters', (WidgetTester tester) async { + await tester.pumpWidget(const TestApp(home: ZetaIndicator.icon())); + + final zetaIndicatorFinder = find.byType(ZetaIndicator); + final ZetaIndicator indicator = tester.firstWidget(zetaIndicatorFinder); + + expect(indicator.rounded, null); + expect(indicator.type, ZetaIndicatorType.icon); + expect(indicator.size, ZetaWidgetSize.large); + expect(indicator.icon, null); + expect(indicator.value, null); + expect(indicator.inverse, false); + expect(indicator.color, null); + }); + testWidgets('Icon constructor with values', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: ZetaIndicator.icon( + color: Colors.purple, + icon: Icons.abc, + inverse: true, + size: ZetaWidgetSize.medium, + ), ), + ); + + final zetaIndicatorFinder = find.byType(ZetaIndicator); + final ZetaIndicator indicator = tester.firstWidget(zetaIndicatorFinder); + + expect(indicator.rounded, null); + expect(indicator.type, ZetaIndicatorType.icon); + expect(indicator.size, ZetaWidgetSize.medium); + expect(indicator.icon, Icons.abc); + expect(indicator.value, null); + expect(indicator.inverse, true); + expect(indicator.color, Colors.purple); + }); + testWidgets('Notification constructor initializes with correct parameters', (WidgetTester tester) async { + await tester.pumpWidget(const TestApp(home: ZetaIndicator.notification())); + + final zetaIndicatorFinder = find.byType(ZetaIndicator); + final ZetaIndicator indicator = tester.firstWidget(zetaIndicatorFinder); + + expect(indicator.rounded, null); + expect(indicator.type, ZetaIndicatorType.notification); + expect(indicator.size, ZetaWidgetSize.large); + expect(indicator.icon, null); + expect(indicator.value, null); + expect(indicator.inverse, false); + expect(indicator.color, null); + }); + testWidgets('Notification constructor with values', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: ZetaIndicator.notification( + rounded: false, + color: Colors.green, + inverse: true, + size: ZetaWidgetSize.small, + value: 1, + ), + ), + ); + + final zetaIndicatorFinder = find.byType(ZetaIndicator); + final ZetaIndicator indicator = tester.firstWidget(zetaIndicatorFinder); + + expect(indicator.rounded, false); + expect(indicator.type, ZetaIndicatorType.notification); + expect(indicator.size, ZetaWidgetSize.small); + expect(indicator.icon, null); + expect(indicator.value, 1); + expect(indicator.inverse, true); + expect(indicator.color, Colors.green); + }); + }); + group('Dimensions Tests', () {}); + 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.icon( + color: Colors.purple, + icon: Icons.abc, + inverse: true, + size: ZetaWidgetSize.medium, ), + ZetaIndicator, + 'indicator_icon_values', ); - - final zetaIndicatorFinder = find.byType(ZetaIndicator); - final ZetaIndicator indicator = tester.firstWidget(zetaIndicatorFinder); - - expect(indicator.rounded, false); - expect(indicator.type, ZetaIndicatorType.notification); - expect(indicator.size, ZetaWidgetSize.small); - expect(indicator.icon, null); - expect(indicator.value, 1); - expect(indicator.inverse, true); - expect(indicator.color, Colors.green); - - await expectLater( - find.byType(ZetaIndicator), - matchesGoldenFile(goldenFile.getFileUri('indicator_notification_values')), + goldenTest(goldenFile, const ZetaIndicator.notification(), ZetaIndicator, 'indicator_notification_default'); + goldenTest( + goldenFile, + const ZetaIndicator.notification( + rounded: false, + color: Colors.green, + inverse: true, + size: ZetaWidgetSize.small, + value: 1, + ), + ZetaIndicator, + 'indicator_notification_values', ); }); - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - const ZetaIndicator( - color: Colors.orange, - icon: Icons.abc, - inverse: true, - rounded: false, - size: ZetaWidgetSize.small, - type: ZetaIndicatorType.icon, - value: 1, - ).debugFillProperties(diagnostics); - - expect(diagnostics.finder('color'), 'MaterialColor(primary value: Color(0xffff9800))'); - expect(diagnostics.finder('icon'), 'IconData(U+F04B6)'); - expect(diagnostics.finder('inverse'), 'true'); - expect(diagnostics.finder('rounded'), 'false'); - expect(diagnostics.finder('size'), 'ZetaWidgetSize.small'); - expect(diagnostics.finder('type'), 'ZetaIndicatorType.icon'); - expect(diagnostics.finder('value'), '1'); - }); + group('Performance Tests', () {}); } diff --git a/test/src/components/badge/label_test.dart b/test/src/components/badge/label_test.dart index d5bfb5d2..ee6fa91e 100644 --- a/test/src/components/badge/label_test.dart +++ b/test/src/components/badge/label_test.dart @@ -1,111 +1,136 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.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'); + const String parentFolder = 'badge'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - testWidgets('Initializes with correct parameters', (WidgetTester tester) async { - await tester.pumpWidget(const TestApp(home: ZetaLabel(label: 'Test Label'))); - - final zetaBadgeFinder = find.byType(ZetaLabel); - final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); - expect(label.rounded, null); - expect(label.label, 'Test Label'); - expect(label.status, ZetaWidgetStatus.info); + group('Accessibility Tests', () {}); + group('Content Tests', () { + final debugFillProperties = { + 'label': '"Test label"', + 'status': 'positive', + 'rounded': 'false', + }; + debugFillPropertiesTest( + const ZetaLabel( + label: 'Test label', + rounded: false, + status: ZetaWidgetStatus.positive, + ), + debugFillProperties, + ); - await expectLater(find.byType(ZetaLabel), matchesGoldenFile(goldenFile.getFileUri('label_default'))); - }); + testWidgets('Initializes with correct parameters', (WidgetTester tester) async { + await tester.pumpWidget(const TestApp(home: ZetaLabel(label: 'Test Label'))); - testWidgets('Positive status', (WidgetTester tester) async { - await tester.pumpWidget(const TestApp(home: ZetaLabel(label: 'Test Label', status: ZetaWidgetStatus.positive))); + final zetaBadgeFinder = find.byType(ZetaLabel); + final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); - final zetaBadgeFinder = find.byType(ZetaLabel); - final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); + expect(label.rounded, null); + expect(label.label, 'Test Label'); + expect(label.status, ZetaWidgetStatus.info); + }); - expect(label.status, ZetaWidgetStatus.positive); + testWidgets('Positive status', (WidgetTester tester) async { + await tester.pumpWidget(const TestApp(home: ZetaLabel(label: 'Test Label', status: ZetaWidgetStatus.positive))); - await expectLater(find.byType(ZetaLabel), matchesGoldenFile(goldenFile.getFileUri('label_positive'))); - }); + final zetaBadgeFinder = find.byType(ZetaLabel); + final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); - testWidgets('Warning status', (WidgetTester tester) async { - await tester.pumpWidget(const TestApp(home: ZetaLabel(label: 'Test Label', status: ZetaWidgetStatus.warning))); + expect(label.status, ZetaWidgetStatus.positive); + }); - final zetaBadgeFinder = find.byType(ZetaLabel); - final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); + testWidgets('Warning status', (WidgetTester tester) async { + await tester.pumpWidget(const TestApp(home: ZetaLabel(label: 'Test Label', status: ZetaWidgetStatus.warning))); - expect(label.status, ZetaWidgetStatus.warning); + final zetaBadgeFinder = find.byType(ZetaLabel); + final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); - 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))); + expect(label.status, ZetaWidgetStatus.warning); + }); + testWidgets('Negative status', (WidgetTester tester) async { + await tester.pumpWidget(const TestApp(home: ZetaLabel(label: 'Test Label', status: ZetaWidgetStatus.negative))); - final zetaBadgeFinder = find.byType(ZetaLabel); - final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); + final zetaBadgeFinder = find.byType(ZetaLabel); + final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); - expect(label.status, ZetaWidgetStatus.negative); + expect(label.status, ZetaWidgetStatus.negative); + }); + testWidgets('Neutral status', (WidgetTester tester) async { + await tester.pumpWidget(const TestApp(home: ZetaLabel(label: 'Test Label', status: ZetaWidgetStatus.neutral))); - 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))); + final zetaBadgeFinder = find.byType(ZetaLabel); + final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); - final zetaBadgeFinder = find.byType(ZetaLabel); - final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); + expect(label.status, ZetaWidgetStatus.neutral); + }); - expect(label.status, ZetaWidgetStatus.neutral); + testWidgets('Dark mode', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + themeMode: ThemeMode.dark, + home: ZetaLabel(label: 'Test Label'), + ), + ); - await expectLater(find.byType(ZetaLabel), matchesGoldenFile(goldenFile.getFileUri('label_neutral'))); - }); + final zetaBadgeFinder = find.byType(ZetaLabel); + final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); - testWidgets('Dark mode', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - themeMode: ThemeMode.dark, - home: ZetaLabel(label: 'Test Label'), - ), - ); + expect(label.status, ZetaWidgetStatus.info); + }); - final zetaBadgeFinder = find.byType(ZetaLabel); - final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); + testWidgets('Sharp', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp(home: ZetaLabel(label: 'Test Label', rounded: false)), + ); - expect(label.status, ZetaWidgetStatus.info); + final zetaBadgeFinder = find.byType(ZetaLabel); + final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); - await expectLater(find.byType(ZetaLabel), matchesGoldenFile(goldenFile.getFileUri('label_dark'))); + expect(label.rounded, false); + }); }); - - testWidgets('Sharp', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp(home: ZetaLabel(label: 'Test Label', rounded: false)), + group('Dimensions Tests', () {}); + 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', status: ZetaWidgetStatus.positive), + ZetaLabel, + 'label_positive', ); - - final zetaBadgeFinder = find.byType(ZetaLabel); - final ZetaLabel label = tester.firstWidget(zetaBadgeFinder); - - expect(label.rounded, false); - - await expectLater(find.byType(ZetaLabel), matchesGoldenFile(goldenFile.getFileUri('label_sharp'))); - }); - - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - const ZetaLabel( - label: 'Test label', - rounded: false, - status: ZetaWidgetStatus.positive, - ).debugFillProperties(diagnostics); - - expect(diagnostics.finder('label'), '"Test label"'); - expect(diagnostics.finder('status'), 'positive'); - expect(diagnostics.finder('rounded'), 'false'); + 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'); }); + group('Performance Tests', () {}); } diff --git a/test/src/components/badge/priority_pill_test.dart b/test/src/components/badge/priority_pill_test.dart index 8724eba2..0c4b281f 100644 --- a/test/src/components/badge/priority_pill_test.dart +++ b/test/src/components/badge/priority_pill_test.dart @@ -1,5 +1,4 @@ // ignore_for_file: avoid_dynamic_calls -import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; @@ -8,121 +7,152 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { - const goldenFile = GoldenFiles(component: 'badge'); + const String parentFolder = 'badge'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - testWidgets('Initializes with correct label and index', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: ZetaPriorityPill(), + + group('Accessibility Tests', () {}); + group('Content Tests', () { + final debugFillProperties = { + 'label': '"Test label"', + 'rounded': 'false', + 'isBadge': 'false', + 'index': '"1"', + 'customColor': + 'ZetaColorSwatch(4278219750, Brightness.light, ZetaContrast.aa, Color(0xfff1f8ff), Color(0xffe2f1ff), Color(0xffb7dbff), Color(0xff7ebeff), Color(0xff599fe5), Color(0xff0073e6), Color(0xff0061c2), Color(0xff004d99), Color(0xff002c58), Color(0xff101b25))', + 'type': 'urgent', + 'size': 'large', + }; + debugFillPropertiesTest( + const ZetaPriorityPill( + label: 'Test label', + rounded: false, + customColor: ZetaColorBase.blue, + index: '1', ), + debugFillProperties, ); - final zetaPriorityPillFinder = find.byType(ZetaPriorityPill); - final ZetaPriorityPill zetaPriorityPill = tester.firstWidget(zetaPriorityPillFinder); - expect(zetaPriorityPill.rounded, null); - expect(zetaPriorityPill.index, null); - expect(zetaPriorityPill.isBadge, false); - expect(zetaPriorityPill.customColor, null); - expect(zetaPriorityPill.label, null); - expect(zetaPriorityPill.size, ZetaPriorityPillSize.large); - expect(zetaPriorityPill.type, ZetaPriorityPillType.urgent); + testWidgets('Initializes with correct label and index', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: ZetaPriorityPill(), + ), + ); - expect(find.text('Urgent'), findsOneWidget); - expect(find.text('U'), findsOneWidget); + final zetaPriorityPillFinder = find.byType(ZetaPriorityPill); + final ZetaPriorityPill zetaPriorityPill = tester.firstWidget(zetaPriorityPillFinder); + expect(zetaPriorityPill.rounded, null); + expect(zetaPriorityPill.index, null); + expect(zetaPriorityPill.isBadge, false); + expect(zetaPriorityPill.customColor, null); + expect(zetaPriorityPill.label, null); + expect(zetaPriorityPill.size, ZetaPriorityPillSize.large); + expect(zetaPriorityPill.type, ZetaPriorityPillType.urgent); - await expectLater( - find.byType(ZetaPriorityPill), - matchesGoldenFile(goldenFile.getFileUri('priority_pill_default')), - ); - }); - testWidgets('High priority pill', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: ZetaPriorityPill( - type: ZetaPriorityPillType.high, - index: '10', - label: 'test label', - rounded: false, - size: ZetaPriorityPillSize.small, - ), - ), - ); + expect(find.text('Urgent'), findsOneWidget); + expect(find.text('U'), findsOneWidget); - final zetaPriorityPillFinder = find.byType(ZetaPriorityPill); - final ZetaPriorityPill zetaPriorityPill = tester.firstWidget(zetaPriorityPillFinder); - expect(zetaPriorityPill.rounded, false); - expect(zetaPriorityPill.index, '10'); - expect(zetaPriorityPill.isBadge, false); - expect(zetaPriorityPill.type, ZetaPriorityPillType.high); - expect(zetaPriorityPill.size, ZetaPriorityPillSize.small); + await expectLater( + find.byType(ZetaPriorityPill), + matchesGoldenFile(goldenFile.getFileUri('priority_pill_default')), + ); + }); + testWidgets('High priority pill', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: ZetaPriorityPill( + type: ZetaPriorityPillType.high, + index: '10', + label: 'test label', + rounded: false, + size: ZetaPriorityPillSize.small, + ), + ), + ); - expect(find.text('test label'), findsOneWidget); + final zetaPriorityPillFinder = find.byType(ZetaPriorityPill); + final ZetaPriorityPill zetaPriorityPill = tester.firstWidget(zetaPriorityPillFinder); + expect(zetaPriorityPill.rounded, false); + expect(zetaPriorityPill.index, '10'); + expect(zetaPriorityPill.isBadge, false); + expect(zetaPriorityPill.type, ZetaPriorityPillType.high); + expect(zetaPriorityPill.size, ZetaPriorityPillSize.small); - await expectLater( - find.byType(ZetaPriorityPill), - matchesGoldenFile(goldenFile.getFileUri('priority_pill_high')), - ); - }); - testWidgets('Medium priority pill', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: ZetaPriorityPill( - type: ZetaPriorityPillType.medium, - isBadge: true, + expect(find.text('test label'), findsOneWidget); + }); + testWidgets('Medium priority pill', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: ZetaPriorityPill( + type: ZetaPriorityPillType.medium, + isBadge: true, + ), ), - ), - ); + ); - final zetaPriorityPillFinder = find.byType(ZetaPriorityPill); - final ZetaPriorityPill zetaPriorityPill = tester.firstWidget(zetaPriorityPillFinder); - expect(zetaPriorityPill.type, ZetaPriorityPillType.medium); - expect(zetaPriorityPill.isBadge, true); + final zetaPriorityPillFinder = find.byType(ZetaPriorityPill); + final ZetaPriorityPill zetaPriorityPill = tester.firstWidget(zetaPriorityPillFinder); + expect(zetaPriorityPill.type, ZetaPriorityPillType.medium); + expect(zetaPriorityPill.isBadge, true); + }); + testWidgets('Low priority pill', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: ZetaPriorityPill( + type: ZetaPriorityPillType.low, + size: ZetaPriorityPillSize.small, + isBadge: true, + ), + ), + ); - await expectLater( - find.byType(ZetaPriorityPill), - matchesGoldenFile(goldenFile.getFileUri('priority_pill_medium')), - ); + final zetaPriorityPillFinder = find.byType(ZetaPriorityPill); + final ZetaPriorityPill zetaPriorityPill = tester.firstWidget(zetaPriorityPillFinder); + expect(zetaPriorityPill.type, ZetaPriorityPillType.low); + expect(zetaPriorityPill.isBadge, true); + expect(zetaPriorityPill.size, ZetaPriorityPillSize.small); + }); }); - testWidgets('Low priority pill', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: ZetaPriorityPill( - type: ZetaPriorityPillType.low, - size: ZetaPriorityPillSize.small, - isBadge: true, - ), + group('Dimensions Tests', () {}); + group('Styling Tests', () {}); + group('Interaction Tests', () {}); + group('Golden Tests', () { + goldenTest(goldenFile, const ZetaPriorityPill(), ZetaPriorityPill, 'priority_pill_default'); + goldenTest( + goldenFile, + const ZetaPriorityPill( + type: ZetaPriorityPillType.high, + index: '10', + label: 'test label', + rounded: false, + size: ZetaPriorityPillSize.small, ), + ZetaPriorityPill, + 'priority_pill_high', ); - - final zetaPriorityPillFinder = find.byType(ZetaPriorityPill); - final ZetaPriorityPill zetaPriorityPill = tester.firstWidget(zetaPriorityPillFinder); - expect(zetaPriorityPill.type, ZetaPriorityPillType.low); - expect(zetaPriorityPill.isBadge, true); - expect(zetaPriorityPill.size, ZetaPriorityPillSize.small); - - await expectLater( - find.byType(ZetaPriorityPill), - matchesGoldenFile(goldenFile.getFileUri('priority_pill_low')), + goldenTest( + goldenFile, + const ZetaPriorityPill( + type: ZetaPriorityPillType.medium, + isBadge: true, + ), + ZetaPriorityPill, + 'priority_pill_medium', + ); + goldenTest( + goldenFile, + const ZetaPriorityPill( + type: ZetaPriorityPillType.low, + size: ZetaPriorityPillSize.small, + isBadge: true, + ), + ZetaPriorityPill, + 'priority_pill_low', ); }); - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - const ZetaPriorityPill( - label: 'Test label', - rounded: false, - customColor: ZetaColorBase.blue, - index: '1', - ).debugFillProperties(diagnostics); - - expect(diagnostics.finder('label'), '"Test label"'); - expect(diagnostics.finder('rounded'), 'false'); - expect(diagnostics.finder('isBadge'), 'false'); - expect(diagnostics.finder('index'), '"1"'); - expect(diagnostics.finder('customColor').split('(').first, 'ZetaColorSwatch'); - expect(diagnostics.finder('type'), 'urgent'); - expect(diagnostics.finder('size'), 'large'); - }); + group('Performance Tests', () {}); } diff --git a/test/src/components/badge/status_label_test.dart b/test/src/components/badge/status_label_test.dart index 201a8ebc..2198a529 100644 --- a/test/src/components/badge/status_label_test.dart +++ b/test/src/components/badge/status_label_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; @@ -8,12 +7,30 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { - const goldenFile = GoldenFiles(component: 'badge'); + const String parentFolder = 'badge'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - group('ZetaStatusLabel Tests', () { + + group('Accessibility Tests', () {}); + group('Content Tests', () { + final debugFillProperties = { + 'label': '"Test label"', + 'rounded': 'false', + 'customIcon': 'IconData(U+F04B6)', + 'status': 'info', + }; + debugFillPropertiesTest( + const ZetaStatusLabel( + label: 'Test label', + rounded: false, + customIcon: Icons.abc, + ), + debugFillProperties, + ); + testWidgets('Initializes with correct properties', (WidgetTester tester) async { await tester.pumpWidget( const TestApp( @@ -21,42 +38,35 @@ void main() { ), ); expect(find.text('Test Label'), findsOneWidget); + }); - await expectLater( - find.byType(ZetaStatusLabel), - matchesGoldenFile(goldenFile.getFileUri('status_label_default')), + testWidgets('Initializes with correct label and custom icon', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: ZetaStatusLabel( + label: 'Custom Icon', + customIcon: Icons.person, + ), + ), ); + expect(find.text('Custom Icon'), findsOneWidget); + expect(find.byIcon(Icons.person), findsOneWidget); }); }); - - testWidgets('Initializes with correct label and custom icon', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: ZetaStatusLabel( - label: 'Custom Icon', - customIcon: Icons.person, - ), + group('Dimensions Tests', () {}); + 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: 'Custom Icon', + customIcon: Icons.person, ), + ZetaStatusLabel, + 'status_label_custom', ); - expect(find.text('Custom Icon'), findsOneWidget); - expect(find.byIcon(Icons.person), findsOneWidget); - - await expectLater( - find.byType(ZetaStatusLabel), - matchesGoldenFile(goldenFile.getFileUri('status_label_custom')), - ); - }); - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - const ZetaStatusLabel( - label: 'Test label', - rounded: false, - customIcon: Icons.abc, - ).debugFillProperties(diagnostics); - - expect(diagnostics.finder('label'), '"Test label"'); - expect(diagnostics.finder('rounded'), 'false'); - expect(diagnostics.finder('customIcon'), 'IconData(U+F04B6)'); - expect(diagnostics.finder('status'), 'info'); }); + group('Performance Tests', () {}); } diff --git a/test/src/components/badge/tag_test.dart b/test/src/components/badge/tag_test.dart index 3dd84531..c7990a11 100644 --- a/test/src/components/badge/tag_test.dart +++ b/test/src/components/badge/tag_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; @@ -7,12 +6,28 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { - const goldenFile = GoldenFiles(component: 'badge'); + const String parentFolder = 'badge'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - group('ZetaTag', () { + + group('Accessibility Tests', () {}); + group('Content Tests', () { + final debugFillProperties = { + 'label': '"Test label"', + 'rounded': 'false', + 'direction': 'left', + }; + debugFillPropertiesTest( + const ZetaTag( + label: 'Test label', + rounded: false, + ), + debugFillProperties, + ); + testWidgets('Initializes right with correct parameters', (WidgetTester tester) async { await tester.pumpWidget( const TestApp( @@ -21,13 +36,7 @@ void main() { ); expect(find.text('Tag'), findsOneWidget); - - await expectLater( - find.byType(ZetaTag), - matchesGoldenFile(goldenFile.getFileUri('tag_right')), - ); }); - testWidgets('Initializes left with correct parameters', (WidgetTester tester) async { await tester.pumpWidget( const TestApp( @@ -35,23 +44,14 @@ void main() { ), ); expect(find.byType(ZetaTag), findsOneWidget); - - await expectLater( - find.byType(ZetaTag), - matchesGoldenFile(goldenFile.getFileUri('tag_left')), - ); }); }); - - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - const ZetaTag( - label: 'Test label', - rounded: false, - ).debugFillProperties(diagnostics); - - expect(diagnostics.finder('label'), '"Test label"'); - expect(diagnostics.finder('rounded'), 'false'); - expect(diagnostics.finder('direction'), 'left'); + group('Dimensions Tests', () {}); + 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'); }); + group('Performance Tests', () {}); } diff --git a/test/src/components/banner/banner_test.dart b/test/src/components/banner/banner_test.dart index c733a75f..44d69c56 100644 --- a/test/src/components/banner/banner_test.dart +++ b/test/src/components/banner/banner_test.dart @@ -23,13 +23,15 @@ ZetaColorSwatch _backgroundColorFromType(BuildContext context, ZetaBannerStatus } void main() { - const goldenFile = GoldenFiles(component: 'banner'); + const String parentFolder = 'banner'; + + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - group('ZetaBanner Accessibility Tests', () { + group('Accessibility Tests', () { for (final type in ZetaBannerStatus.values) { testWidgets('meets contrast ratio guideline for $type', (WidgetTester tester) async { await tester.pumpWidget( @@ -118,7 +120,7 @@ void main() { }); }); - group('ZetaBanner Content Tests', () { + group('Content Tests', () { testWidgets('ZetaBanner title is correct', (WidgetTester tester) async { await tester.pumpWidget( TestApp( @@ -192,7 +194,7 @@ void main() { }); }); - group('ZetaBanner Dimension Tests', () { + group('Dimension Tests', () { testWidgets('icon is the correct size', (WidgetTester tester) async { await tester.pumpWidget( TestApp( @@ -256,7 +258,7 @@ void main() { }); }); - group('ZetaBanner Styling Tests', () { + group('Styling Tests', () { for (final type in ZetaBannerStatus.values) { testWidgets('title styles are correct for $type', (WidgetTester tester) async { await tester.pumpWidget( @@ -328,32 +330,28 @@ void main() { } }); - group('ZetaBanner Interaction Tests', () {}); + group('Interaction Tests', () {}); - group('ZetaBanner Golden Tests', () { + group('Golden Tests', () { for (final type in ZetaBannerStatus.values) { - testWidgets('ZetaBanner ${type.toString().split('.').last} golden', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: Builder( - builder: (context) { - return ZetaBanner( - context: context, - title: 'Banner Title', - leadingIcon: Icons.info, - trailing: const ZetaIcon(Icons.chevron_right), - type: type, - ); - }, - ), - ), - ); - - await expectLater( - find.byType(ZetaBanner), - matchesGoldenFile(goldenFile.getFileUri('banner_${type.toString().split('.').last}')), - ); - }); + goldenTest( + goldenFile, + Builder( + builder: (context) { + return ZetaBanner( + context: context, + title: 'Banner Title', + leadingIcon: Icons.info, + trailing: const ZetaIcon(Icons.chevron_right), + type: type, + ); + }, + ), + ZetaBanner, + 'banner_${type.toString().split('.').last}', + ); } }); + + group('Performace Tests', () {}); } diff --git a/test/src/components/button/button_test.dart b/test/src/components/button/button_test.dart index c14a9271..fb72ec0e 100644 --- a/test/src/components/button/button_test.dart +++ b/test/src/components/button/button_test.dart @@ -1,6 +1,5 @@ import 'dart:ui'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; @@ -10,13 +9,30 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { - const goldenFile = GoldenFiles(component: 'button'); + const String parentFolder = 'button'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - group('ZetaButton Tests', () { + group('Accessibility Tests', () {}); + + group('Content Tests', () { + final debugFillProperties = { + 'label': '"Test label"', + 'onPressed': 'null', + 'type': 'primary', + 'borderType': 'null', + 'size': 'medium', + 'leadingIcon': 'null', + 'trailingIcon': 'null', + }; + debugFillPropertiesTest( + const ZetaButton(label: 'Test label'), + debugFillProperties, + ); + testWidgets('Initializes with correct Label', (WidgetTester tester) async { await tester.pumpWidget( TestApp( @@ -26,255 +42,266 @@ void main() { expect(find.text('Test Button'), findsOneWidget); }); - }); - testWidgets('Triggers callback on tap', (WidgetTester tester) async { - bool callbackTriggered = false; - await tester.pumpWidget( - TestApp(home: ZetaButton(onPressed: () => callbackTriggered = true, label: 'Test Button')), - ); - await tester.tap(find.byType(ZetaButton)); - await tester.pump(); + testWidgets('Initializes primary with correct Label', (WidgetTester tester) async { + await tester.pumpWidget( + TestApp( + home: ZetaButton.primary(onPressed: () {}, label: 'Test Button'), + ), + ); - expect(callbackTriggered, isTrue); - }); + final buttonFinder = find.byType(ZetaButton); + final ZetaButton button = tester.firstWidget(buttonFinder); + expect(button.borderType, null); + expect(button.label, 'Test Button'); + expect(button.leadingIcon, null); + expect(button.trailingIcon, null); + expect(button.size, ZetaWidgetSize.medium); + expect(button.type, ZetaButtonType.primary); + }); - testWidgets('Initializes primary with correct Label', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaButton.primary(onPressed: () {}, label: 'Test Button'), - ), - ); + testWidgets('Initializes secondary with correct Label', (WidgetTester tester) async { + await tester.pumpWidget( + TestApp( + home: ZetaButton.secondary( + onPressed: () {}, + label: 'Test Button', + leadingIcon: Icons.abc, + size: ZetaWidgetSize.small, + ), + ), + ); - final buttonFinder = find.byType(ZetaButton); - final ZetaButton button = tester.firstWidget(buttonFinder); - expect(button.borderType, null); - expect(button.label, 'Test Button'); - expect(button.leadingIcon, null); - expect(button.trailingIcon, null); - expect(button.size, ZetaWidgetSize.medium); - expect(button.type, ZetaButtonType.primary); + final buttonFinder = find.byType(ZetaButton); + final ZetaButton button = tester.firstWidget(buttonFinder); + expect(button.borderType, null); + expect(button.label, 'Test Button'); + expect(button.leadingIcon, Icons.abc); + expect(button.trailingIcon, null); + expect(button.size, ZetaWidgetSize.small); + expect(button.type, ZetaButtonType.secondary); + }); + testWidgets('Initializes positive with correct Label', (WidgetTester tester) async { + await tester.pumpWidget( + TestApp( + home: ZetaButton.positive(onPressed: () {}, label: 'Test Button', trailingIcon: Icons.abc), + ), + ); - await expectLater(find.byType(ZetaButton), matchesGoldenFile(goldenFile.getFileUri('button_primary'))); - }); - testWidgets('Initializes secondary with correct Label', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaButton.secondary( - onPressed: () {}, - label: 'Test Button', - leadingIcon: Icons.abc, - size: ZetaWidgetSize.small, + final buttonFinder = find.byType(ZetaButton); + final ZetaButton button = tester.firstWidget(buttonFinder); + expect(button.borderType, null); + expect(button.label, 'Test Button'); + expect(button.leadingIcon, null); + expect(button.trailingIcon, Icons.abc); + expect(button.size, ZetaWidgetSize.medium); + expect(button.type, ZetaButtonType.positive); + }); + testWidgets('Initializes negative with correct Label', (WidgetTester tester) async { + await tester.pumpWidget( + TestApp( + home: ZetaButton.negative(onPressed: () {}, label: 'Test Button', size: ZetaWidgetSize.small), ), - ), - ); + ); - final buttonFinder = find.byType(ZetaButton); - final ZetaButton button = tester.firstWidget(buttonFinder); - expect(button.borderType, null); - expect(button.label, 'Test Button'); - expect(button.leadingIcon, Icons.abc); - expect(button.trailingIcon, null); - expect(button.size, ZetaWidgetSize.small); - expect(button.type, ZetaButtonType.secondary); - - await expectLater( - find.byType(ZetaButton), - matchesGoldenFile(goldenFile.getFileUri('button_secondary')), - ); - }); - testWidgets('Initializes positive with correct Label', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaButton.positive(onPressed: () {}, label: 'Test Button', trailingIcon: Icons.abc), - ), - ); + final buttonFinder = find.byType(ZetaButton); + final ZetaButton button = tester.firstWidget(buttonFinder); + expect(button.borderType, null); + expect(button.label, 'Test Button'); + expect(button.leadingIcon, null); + expect(button.trailingIcon, null); + expect(button.size, ZetaWidgetSize.small); + expect(button.type, ZetaButtonType.negative); + }); + testWidgets('Initializes outline with correct Label', (WidgetTester tester) async { + await tester.pumpWidget( + TestApp( + home: ZetaButton.outline(onPressed: () {}, label: 'Test Button', size: ZetaWidgetSize.large), + ), + ); - final buttonFinder = find.byType(ZetaButton); - final ZetaButton button = tester.firstWidget(buttonFinder); - expect(button.borderType, null); - expect(button.label, 'Test Button'); - expect(button.leadingIcon, null); - expect(button.trailingIcon, Icons.abc); - expect(button.size, ZetaWidgetSize.medium); - expect(button.type, ZetaButtonType.positive); - - await expectLater( - find.byType(ZetaButton), - matchesGoldenFile(goldenFile.getFileUri('button_positive')), - ); - }); - testWidgets('Initializes negative with correct Label', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaButton.negative(onPressed: () {}, label: 'Test Button', size: ZetaWidgetSize.small), - ), - ); + final buttonFinder = find.byType(ZetaButton); + final ZetaButton button = tester.firstWidget(buttonFinder); + expect(button.borderType, null); + expect(button.label, 'Test Button'); + expect(button.leadingIcon, null); + expect(button.trailingIcon, null); + expect(button.size, ZetaWidgetSize.large); + expect(button.type, ZetaButtonType.outline); + }); + testWidgets('Initializes outlineSubtle with correct Label', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: ZetaButton.outlineSubtle(label: 'Test Button', borderType: ZetaWidgetBorder.sharp), + ), + ); - final buttonFinder = find.byType(ZetaButton); - final ZetaButton button = tester.firstWidget(buttonFinder); - expect(button.borderType, null); - expect(button.label, 'Test Button'); - expect(button.leadingIcon, null); - expect(button.trailingIcon, null); - expect(button.size, ZetaWidgetSize.small); - expect(button.type, ZetaButtonType.negative); - - await expectLater( - find.byType(ZetaButton), - matchesGoldenFile(goldenFile.getFileUri('button_negative')), - ); - }); - testWidgets('Initializes outline with correct Label', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaButton.outline(onPressed: () {}, label: 'Test Button', size: ZetaWidgetSize.large), - ), - ); + final buttonFinder = find.byType(ZetaButton); + final ZetaButton button = tester.firstWidget(buttonFinder); + expect(button.borderType, ZetaWidgetBorder.sharp); + expect(button.label, 'Test Button'); + expect(button.leadingIcon, null); + expect(button.trailingIcon, null); + expect(button.size, ZetaWidgetSize.medium); + expect(button.type, ZetaButtonType.outlineSubtle); + }); + testWidgets('Initializes text with correct Label', (WidgetTester tester) async { + await tester.pumpWidget( + TestApp( + home: ZetaButton.text(onPressed: () {}, label: 'Test Button', borderType: ZetaWidgetBorder.full), + ), + ); - final buttonFinder = find.byType(ZetaButton); - final ZetaButton button = tester.firstWidget(buttonFinder); - expect(button.borderType, null); - expect(button.label, 'Test Button'); - expect(button.leadingIcon, null); - expect(button.trailingIcon, null); - expect(button.size, ZetaWidgetSize.large); - expect(button.type, ZetaButtonType.outline); + final buttonFinder = find.byType(ZetaButton); + final ZetaButton button = tester.firstWidget(buttonFinder); + expect(button.borderType, ZetaWidgetBorder.full); + expect(button.label, 'Test Button'); + expect(button.leadingIcon, null); + expect(button.trailingIcon, null); + expect(button.size, ZetaWidgetSize.medium); + expect(button.type, ZetaButtonType.text); + }); - await expectLater(find.byType(ZetaButton), matchesGoldenFile(goldenFile.getFileUri('button_outline'))); - }); - testWidgets('Initializes outlineSubtle with correct Label', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: ZetaButton.outlineSubtle(label: 'Test Button', borderType: ZetaWidgetBorder.sharp), - ), - ); + testWidgets('Disabled button', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: ZetaButton.text(label: 'Test Button', borderType: ZetaWidgetBorder.full), + ), + ); - final buttonFinder = find.byType(ZetaButton); - final ZetaButton button = tester.firstWidget(buttonFinder); - expect(button.borderType, ZetaWidgetBorder.sharp); - expect(button.label, 'Test Button'); - expect(button.leadingIcon, null); - expect(button.trailingIcon, null); - expect(button.size, ZetaWidgetSize.medium); - expect(button.type, ZetaButtonType.outlineSubtle); - - await expectLater( - find.byType(ZetaButton), - matchesGoldenFile(goldenFile.getFileUri('button_outline_subtle')), - ); + final buttonFinder = find.byType(ZetaButton); + final ZetaButton button = tester.firstWidget(buttonFinder); + expect(button.borderType, ZetaWidgetBorder.full); + expect(button.label, 'Test Button'); + expect(button.leadingIcon, null); + expect(button.trailingIcon, null); + expect(button.onPressed, null); + expect(button.size, ZetaWidgetSize.medium); + expect(button.type, ZetaButtonType.text); + }); }); - testWidgets('Initializes text with correct Label', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaButton.text(onPressed: () {}, label: 'Test Button', borderType: ZetaWidgetBorder.full), - ), - ); - final buttonFinder = find.byType(ZetaButton); - final ZetaButton button = tester.firstWidget(buttonFinder); - expect(button.borderType, ZetaWidgetBorder.full); - expect(button.label, 'Test Button'); - expect(button.leadingIcon, null); - expect(button.trailingIcon, null); - expect(button.size, ZetaWidgetSize.medium); - expect(button.type, ZetaButtonType.text); - - await expectLater( - find.byType(ZetaButton), - matchesGoldenFile(goldenFile.getFileUri('button_text')), - ); - }); + group('Dimensions Tests', () {}); - testWidgets('Disabled button', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: ZetaButton.text(label: 'Test Button', borderType: ZetaWidgetBorder.full), - ), - ); + group('Styling Tests', () { + testWidgets('Hover states are correct', (WidgetTester tester) async { + await tester.pumpWidget( + TestApp( + home: ZetaButton(label: 'Test Button', onPressed: () {}), + ), + ); - final buttonFinder = find.byType(ZetaButton); - final ZetaButton button = tester.firstWidget(buttonFinder); - expect(button.borderType, ZetaWidgetBorder.full); - expect(button.label, 'Test Button'); - expect(button.leadingIcon, null); - expect(button.trailingIcon, null); - expect(button.onPressed, null); - expect(button.size, ZetaWidgetSize.medium); - expect(button.type, ZetaButtonType.text); - - await expectLater( - find.byType(ZetaButton), - matchesGoldenFile(goldenFile.getFileUri('button_disabled')), - ); - }); - testWidgets('Interaction with button', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaButton(label: 'Test Button', onPressed: () {}), - ), - ); + final buttonFinder = find.byType(ZetaButton); + final ZetaButton button = tester.firstWidget(buttonFinder); + + final filledButtonFinder = find.byType(FilledButton); + final FilledButton filledButton = tester.firstWidget(filledButtonFinder); + + final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); + await gesture.addPointer(location: Offset.zero); + addTearDown(gesture.removePointer); + await tester.pump(); + await gesture.moveTo(tester.getCenter(find.byType(ZetaButton))); + await tester.pumpAndSettle(); - final buttonFinder = find.byType(ZetaButton); - final ZetaButton button = tester.firstWidget(buttonFinder); + expect(filledButton.style?.backgroundColor?.resolve({WidgetState.hovered}), ZetaColorBase.blue.shade50); - final filledButtonFinder = find.byType(FilledButton); - final FilledButton filledButton = tester.firstWidget(filledButtonFinder); + await gesture.down(tester.getCenter(find.byType(ZetaButton))); + await tester.pumpAndSettle(); + expect(filledButton.style?.backgroundColor?.resolve({WidgetState.pressed}), ZetaColorBase.blue.shade70); - final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); - await gesture.addPointer(location: Offset.zero); - addTearDown(gesture.removePointer); - await tester.pump(); - await gesture.moveTo(tester.getCenter(find.byType(ZetaButton))); - await tester.pumpAndSettle(); + await gesture.up(); - expect(filledButton.style?.backgroundColor?.resolve({WidgetState.hovered}), ZetaColorBase.blue.shade50); + await tester.pumpAndSettle(); + expect(button.label, 'Test Button'); + expect(button.leadingIcon, null); + expect(button.trailingIcon, null); + expect(button.size, ZetaWidgetSize.medium); + }); - await gesture.down(tester.getCenter(find.byType(ZetaButton))); - await tester.pumpAndSettle(); - expect(filledButton.style?.backgroundColor?.resolve({WidgetState.pressed}), ZetaColorBase.blue.shade70); + testWidgets('Focus state is correct', (WidgetTester tester) async { + final FocusNode focusNode = FocusNode(); + await tester.pumpWidget( + TestApp( + home: ZetaButton(label: 'Test Button', onPressed: () {}, focusNode: focusNode), + ), + ); + final buttonFinder = find.byType(ZetaButton); + final ZetaButton button = tester.firstWidget(buttonFinder); + focusNode.requestFocus(); + await tester.pump(); + final filledButtonFinder = find.byType(FilledButton); + final FilledButton filledButton = tester.firstWidget(filledButtonFinder); + + expect(button.label, 'Test Button'); + expect(button.leadingIcon, null); + expect(button.trailingIcon, null); + expect(button.size, ZetaWidgetSize.medium); + expect( + filledButton.style?.side?.resolve({WidgetState.focused}), + BorderSide(color: ZetaColorBase.blue, width: ZetaBorders.medium), + ); + }); + }); - await gesture.up(); + group('Interaction Tests', () { + testWidgets('Triggers callback on tap', (WidgetTester tester) async { + bool callbackTriggered = false; + await tester.pumpWidget( + TestApp(home: ZetaButton(onPressed: () => callbackTriggered = true, label: 'Test Button')), + ); + await tester.tap(find.byType(ZetaButton)); + await tester.pump(); - await tester.pumpAndSettle(); - expect(button.label, 'Test Button'); - expect(button.leadingIcon, null); - expect(button.trailingIcon, null); - expect(button.size, ZetaWidgetSize.medium); + expect(callbackTriggered, isTrue); + }); }); - testWidgets('Interaction with button', (WidgetTester tester) async { - final FocusNode focusNode = FocusNode(); - await tester.pumpWidget( - TestApp( - home: ZetaButton(label: 'Test Button', onPressed: () {}, focusNode: focusNode), - ), + + group('Golden Tests', () { + goldenTest(goldenFile, ZetaButton.primary(onPressed: () {}, label: 'Test Button'), ZetaButton, 'button_primary'); + goldenTest( + goldenFile, + ZetaButton.secondary(onPressed: () {}, label: 'Test Button', leadingIcon: Icons.abc, size: ZetaWidgetSize.small), + ZetaButton, + 'button_secondary', ); - final buttonFinder = find.byType(ZetaButton); - final ZetaButton button = tester.firstWidget(buttonFinder); - focusNode.requestFocus(); - await tester.pump(); - final filledButtonFinder = find.byType(FilledButton); - final FilledButton filledButton = tester.firstWidget(filledButtonFinder); - - expect(button.label, 'Test Button'); - expect(button.leadingIcon, null); - expect(button.trailingIcon, null); - expect(button.size, ZetaWidgetSize.medium); - expect( - filledButton.style?.side?.resolve({WidgetState.focused}), - BorderSide(color: ZetaColorBase.blue, width: ZetaBorders.medium), + 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', ); }); - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - const ZetaButton(label: 'Test label').debugFillProperties(diagnostics); - - expect(diagnostics.finder('label'), '"Test label"'); - expect(diagnostics.finder('onPressed'), 'null'); - expect(diagnostics.finder('type'), 'primary'); - expect(diagnostics.finder('borderType'), 'null'); - expect(diagnostics.finder('size'), 'medium'); - expect(diagnostics.finder('leadingIcon'), 'null'); - expect(diagnostics.finder('trailingIcon'), 'null'); - }); + + group('Performance Tests', () {}); } diff --git a/test/src/components/chat_item/chat_item_test.dart b/test/src/components/chat_item/chat_item_test.dart index 8bafbc00..e72a00bf 100644 --- a/test/src/components/chat_item/chat_item_test.dart +++ b/test/src/components/chat_item/chat_item_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:intl/intl.dart'; @@ -9,13 +8,67 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { - const goldenFile = GoldenFiles(component: 'chat_item'); + const String parentFolder = 'chat_item'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - group('ZetaChatItem Tests', () { + group('Accessibility Tests', () {}); + group('Content Tests', () { + final time = DateTime.now(); + final debugFillPropertiesChatItem = { + 'rounded': 'null', + 'highlighted': 'true', + 'time': time.toString(), + 'timeFormat': 'null', + 'enabledWarningIcon': 'true', + 'enabledNotificationIcon': 'true', + 'count': '1', + 'onTap': 'null', + 'starred': 'true', + 'onMenuMoreTap': 'null', + 'onCallTap': 'null', + 'onDeleteTap': 'null', + 'onPttTap': 'null', + 'explicitChildNodes': 'true', + 'paleButtonColors': 'null', + }; + debugFillPropertiesTest( + ZetaChatItem( + title: const Text('Title'), + subtitle: const Text('Subtitle'), + time: time, + leading: const ZetaAvatar(initials: 'AZ'), + slidableActions: [ + ZetaSlidableAction.menuMore(onPressed: () {}), + ZetaSlidableAction.call(onPressed: () {}), + ZetaSlidableAction.ptt(onPressed: () {}), + ZetaSlidableAction.delete(onPressed: () {}), + ], + count: 1, + enabledNotificationIcon: true, + highlighted: true, + enabledWarningIcon: true, + starred: true, + ), + debugFillPropertiesChatItem, + ); + final debugFillPropertiesSlidableAction = { + 'onPressed': 'null', + 'icon': 'IconData(U+0E5F9)', + 'foregroundColor': null, + 'backgroundColor': null, + 'color': ZetaColorBase.blue.toString(), + 'semanticLabel': 'null', + 'paleColor': 'false', + }; + debugFillPropertiesTest( + const ZetaSlidableAction(icon: Icons.star), + debugFillPropertiesSlidableAction, + ); + testWidgets('ZetaChatItem displays correctly', (WidgetTester tester) async { tester.view.devicePixelRatio = 1.0; tester.view.physicalSize = const Size(481, 480); @@ -64,11 +117,6 @@ void main() { await tester.tap(chatItemFinder); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); - - await expectLater( - chatItemFinder, - matchesGoldenFile(goldenFile.getFileUri('chat_item_default')), - ); }); testWidgets('ZetaChatItem highlighted', (WidgetTester tester) async { @@ -119,11 +167,6 @@ void main() { await tester.tap(chatItemFinder); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); - - await expectLater( - chatItemFinder, - matchesGoldenFile(goldenFile.getFileUri('chat_item_highlighted')), - ); }); testWidgets('ZetaChatItem slidable actions', (WidgetTester tester) async { @@ -181,11 +224,6 @@ void main() { await tester.tap(find.byIcon(ZetaIcons.delete_round)); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); - - await expectLater( - chatItemFinder, - matchesGoldenFile(goldenFile.getFileUri('chat_item_slidable_actions')), - ); }); testWidgets('ZetaChatItem with pale slidable button colors', (WidgetTester tester) async { @@ -235,11 +273,6 @@ void main() { expect(find.byIcon(ZetaIcons.phone_round), findsOneWidget); expect(find.byIcon(ZetaIcons.ptt_round), findsOneWidget); expect(find.byIcon(ZetaIcons.delete_round), findsOneWidget); - - await expectLater( - chatItemFinder, - matchesGoldenFile(goldenFile.getFileUri('chat_item_pale_slidable_buttons')), - ); }); testWidgets('ZetaChatItem with 2 pale buttons and 2 regular buttons', (WidgetTester tester) async { @@ -323,11 +356,6 @@ void main() { await tester.tap(find.byIcon(Icons.message)); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); - - await expectLater( - chatItemFinder, - matchesGoldenFile(goldenFile.getFileUri('chat_item_pale_and_regular_buttons')), - ); }); testWidgets('ZetaChatItem with custom leading widget', (WidgetTester tester) async { @@ -362,16 +390,9 @@ void main() { ), ); - final chatItemFinder = find.byType(ZetaChatItem); - // Verify that the custom leading widget is displayed correctly expect(find.byType(Container), findsOneWidget); expect(find.byWidgetPredicate((widget) => widget is Container && widget.color == Colors.blue), findsOneWidget); - - await expectLater( - chatItemFinder, - matchesGoldenFile(goldenFile.getFileUri('chat_item_custom_leading')), - ); }); testWidgets('ZetaChatItem with custom slidable buttons', (WidgetTester tester) async { @@ -425,60 +446,6 @@ void main() { await tester.tap(find.byIcon(Icons.delete)); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); - - await expectLater( - chatItemFinder, - matchesGoldenFile(goldenFile.getFileUri('chat_item_custom_slidable_buttons')), - ); - }); - - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnosticsZetaChatItem = DiagnosticPropertiesBuilder(); - final time = DateTime.now(); - ZetaChatItem( - title: const Text('Title'), - subtitle: const Text('Subtitle'), - time: time, - leading: const ZetaAvatar(initials: 'AZ'), - slidableActions: [ - ZetaSlidableAction.menuMore(onPressed: () {}), - ZetaSlidableAction.call(onPressed: () {}), - ZetaSlidableAction.ptt(onPressed: () {}), - ZetaSlidableAction.delete(onPressed: () {}), - ], - count: 1, - enabledNotificationIcon: true, - highlighted: true, - enabledWarningIcon: true, - starred: true, - ).debugFillProperties(diagnosticsZetaChatItem); - - expect(diagnosticsZetaChatItem.finder('rounded'), 'null'); - expect(diagnosticsZetaChatItem.finder('highlighted'), 'true'); - expect(diagnosticsZetaChatItem.finder('time'), time.toString()); - expect(diagnosticsZetaChatItem.finder('timeFormat'), 'null'); - expect(diagnosticsZetaChatItem.finder('enabledWarningIcon'), 'true'); - expect(diagnosticsZetaChatItem.finder('enabledNotificationIcon'), 'true'); - expect(diagnosticsZetaChatItem.finder('count'), '1'); - expect(diagnosticsZetaChatItem.finder('onTap'), 'null'); - expect(diagnosticsZetaChatItem.finder('starred'), 'true'); - expect(diagnosticsZetaChatItem.finder('onMenuMoreTap'), 'null'); - expect(diagnosticsZetaChatItem.finder('onCallTap'), 'null'); - expect(diagnosticsZetaChatItem.finder('onDeleteTap'), 'null'); - expect(diagnosticsZetaChatItem.finder('onPttTap'), 'null'); - expect(diagnosticsZetaChatItem.finder('explicitChildNodes'), 'true'); - expect(diagnosticsZetaChatItem.finder('paleButtonColors'), 'null'); - - final diagnosticsZetaSlidableAction = DiagnosticPropertiesBuilder(); - const ZetaSlidableAction(icon: Icons.star).debugFillProperties(diagnosticsZetaSlidableAction); - - expect(diagnosticsZetaSlidableAction.finder('onPressed'), 'null'); - expect(diagnosticsZetaSlidableAction.finder('icon'), 'IconData(U+0E5F9)'); - expect(diagnosticsZetaSlidableAction.finder('foregroundColor'), null); - expect(diagnosticsZetaSlidableAction.finder('backgroundColor'), null); - expect(diagnosticsZetaSlidableAction.finder('color'), ZetaColorBase.blue.toString()); - expect(diagnosticsZetaSlidableAction.finder('semanticLabel'), 'null'); - expect(diagnosticsZetaSlidableAction.finder('paleColor'), 'false'); }); testWidgets('ZetaChatItem displays correctly', (WidgetTester tester) async { @@ -541,11 +508,298 @@ void main() { await tester.tap(find.byIcon(ZetaIcons.delete_round)); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); - - await expectLater( - chatItemFinder, - matchesGoldenFile(goldenFile.getFileUri('chat_item_small_screen_slidable_button')), - ); }); }); + group('Dimensions Tests', () {}); + group('Styling Tests', () {}); + group('Interaction Tests', () {}); + group('Golden Tests', () { + const title = Text('John Doe'); + const subtitle = Text('Hello, how are you?'); + final time = DateTime.now(); + + goldenTestWithCallbacks( + goldenFile, + Scaffold( + body: Column( + children: [ + ZetaChatItem( + explicitChildNodes: false, + time: time, + enabledWarningIcon: true, + enabledNotificationIcon: true, + leading: const ZetaAvatar(initials: 'AZ'), + count: 100, + onTap: () {}, + paleButtonColors: true, + slidableActions: [ + ZetaSlidableAction.menuMore(onPressed: () {}), + ZetaSlidableAction.call(onPressed: () {}), + ZetaSlidableAction.ptt(onPressed: () {}), + ZetaSlidableAction.delete(onPressed: () {}), + ], + title: title, + subtitle: subtitle, + ), + ], + ), + ), + ZetaChatItem, + 'chat_item_default', + before: (tester) async { + tester.view.devicePixelRatio = 1.0; + tester.view.physicalSize = const Size(481, 480); + }, + ); + + goldenTestWithCallbacks( + goldenFile, + Column( + children: [ + ZetaChatItem( + explicitChildNodes: false, + time: time, + enabledWarningIcon: true, + enabledNotificationIcon: true, + leading: const ZetaAvatar(initials: 'AZ'), + count: 100, + onTap: () {}, + paleButtonColors: false, + starred: true, + slidableActions: [ + ZetaSlidableAction.menuMore(onPressed: () {}), + ZetaSlidableAction.call(onPressed: () {}), + ZetaSlidableAction.ptt(onPressed: () {}), + ZetaSlidableAction.delete(onPressed: () {}), + ], + highlighted: true, + title: title, + subtitle: subtitle, + ), + ], + ), + ZetaChatItem, + 'chat_item_highlighted', + before: (tester) async { + tester.view.devicePixelRatio = 1.0; + tester.view.physicalSize = const Size(481, 480); + }, + ); + + goldenTestWithCallbacks( + goldenFile, + Column( + children: [ + ZetaChatItem( + time: time, + leading: const ZetaAvatar(initials: 'AZ'), + slidableActions: [ + ZetaSlidableAction.menuMore(onPressed: () {}), + ZetaSlidableAction.call(onPressed: () {}), + ZetaSlidableAction.ptt(onPressed: () {}), + ZetaSlidableAction.delete(onPressed: () {}), + ], + title: title, + subtitle: subtitle, + ), + ], + ), + ZetaChatItem, + 'chat_item_slidable_actions', + before: (tester) async { + tester.view.devicePixelRatio = 1.0; + tester.view.physicalSize = const Size(481, 480); + }, + after: (tester) async { + final chatItemFinder = find.byType(ZetaChatItem); + await tester.drag(chatItemFinder, const Offset(-200, 0)); + await tester.pumpAndSettle(); + }, + ); + + goldenTestWithCallbacks( + goldenFile, + Column( + children: [ + ZetaChatItem( + time: time, + leading: const ZetaAvatar(initials: 'AZ'), + paleButtonColors: true, + slidableActions: [ + ZetaSlidableAction.menuMore( + onPressed: () {}, + ), + ZetaSlidableAction.call( + onPressed: () {}, + ), + ZetaSlidableAction.ptt( + onPressed: () {}, + ), + ZetaSlidableAction.delete( + onPressed: () {}, + ), + ], + title: title, + subtitle: subtitle, + ), + ], + ), + ZetaChatItem, + 'chat_item_pale_slidable_buttons', + before: (tester) async { + tester.view.devicePixelRatio = 1.0; + tester.view.physicalSize = const Size(481, 480); + }, + after: (tester) async { + final chatItemFinder = find.byType(ZetaChatItem); + await tester.drag(chatItemFinder, const Offset(-200, 0)); + await tester.pumpAndSettle(); + }, + ); + + goldenTestWithCallbacks( + goldenFile, + Column( + children: [ + ZetaChatItem( + time: time, + leading: const ZetaAvatar(initials: 'AZ'), + slidableActions: [ + ZetaSlidableAction( + onPressed: () {}, + paleColor: true, + icon: Icons.star, + ), + ZetaSlidableAction( + onPressed: () {}, + paleColor: true, + icon: Icons.delete, + ), + ZetaSlidableAction( + onPressed: () {}, + icon: Icons.call, + ), + ZetaSlidableAction( + onPressed: () {}, + icon: Icons.message, + ), + ], + title: title, + subtitle: subtitle, + ), + ], + ), + ZetaChatItem, + 'chat_item_pale_and_regular_buttons', + before: (tester) async { + tester.view.devicePixelRatio = 1.0; + tester.view.physicalSize = const Size(481, 480); + }, + after: (tester) async { + final chatItemFinder = find.byType(ZetaChatItem); + await tester.drag(chatItemFinder, const Offset(-200, 0)); + await tester.pumpAndSettle(); + }, + ); + + goldenTestWithCallbacks( + goldenFile, + Column( + children: [ + ZetaChatItem( + time: time, + leading: Container( + width: 40, + height: 40, + color: Colors.blue, + ), + slidableActions: [ + ZetaSlidableAction.menuMore(onPressed: () {}), + ZetaSlidableAction.call(onPressed: () {}), + ZetaSlidableAction.ptt(onPressed: () {}), + ZetaSlidableAction.delete(onPressed: () {}), + ], + title: title, + subtitle: subtitle, + ), + ], + ), + ZetaChatItem, + 'chat_item_custom_leading', + before: (tester) async { + tester.view.devicePixelRatio = 1.0; + tester.view.physicalSize = const Size(481, 480); + }, + ); + + goldenTestWithCallbacks( + goldenFile, + Column( + children: [ + ZetaChatItem( + time: time, + leading: const ZetaAvatar(initials: 'AZ'), + slidableActions: [ + ZetaSlidableAction( + onPressed: () {}, + color: ZetaColorBase.orange, + icon: Icons.star, + ), + ZetaSlidableAction( + onPressed: () {}, + color: ZetaColorBase.red, + icon: Icons.delete, + ), + ], + title: title, + subtitle: subtitle, + ), + ], + ), + ZetaChatItem, + 'chat_item_custom_slidable_buttons', + before: (tester) async { + tester.view.devicePixelRatio = 1.0; + tester.view.physicalSize = const Size(481, 480); + }, + after: (tester) async { + final chatItemFinder = find.byType(ZetaChatItem); + await tester.drag(chatItemFinder, const Offset(-200, 0)); + await tester.pumpAndSettle(); + }, + ); + + goldenTestWithCallbacks( + goldenFile, + Column( + children: [ + ZetaChatItem( + time: time, + leading: const ZetaAvatar(initials: 'AZ'), + slidableActions: [ + ZetaSlidableAction.menuMore(onPressed: () {}), + ZetaSlidableAction.call(onPressed: () {}), + ZetaSlidableAction.ptt(onPressed: () {}), + ZetaSlidableAction.delete(onPressed: () {}), + ], + title: title, + count: 1, + subtitle: subtitle, + ), + ], + ), + ZetaChatItem, + 'chat_item_small_screen_slidable_button', + before: (tester) async { + tester.view.devicePixelRatio = 1.0; + tester.view.physicalSize = const Size(315, 480); + }, + after: (tester) async { + final chatItemFinder = find.byType(ZetaChatItem); + await tester.drag(chatItemFinder, const Offset(-200, 0)); + await tester.pumpAndSettle(); + }, + ); + }); + group('Performance Tests', () {}); } diff --git a/test/src/components/chat_item/golden/chat_item_slidable_actions.png b/test/src/components/chat_item/golden/chat_item_slidable_actions.png index 797a78f2..c990b593 100644 Binary files a/test/src/components/chat_item/golden/chat_item_slidable_actions.png and b/test/src/components/chat_item/golden/chat_item_slidable_actions.png differ diff --git a/test/src/components/checkbox/checkbox_test.dart b/test/src/components/checkbox/checkbox_test.dart index c2c00c56..b718cef9 100644 --- a/test/src/components/checkbox/checkbox_test.dart +++ b/test/src/components/checkbox/checkbox_test.dart @@ -1,6 +1,5 @@ import 'dart:ui'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:zeta_flutter/src/components/checkbox/checkbox.dart'; @@ -11,13 +10,41 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { - const goldenFile = GoldenFiles(component: 'checkbox'); + const String parentFolder = 'checkbox'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - group('ZetaCheckbox Tests', () { + group('Accessibility Tests', () {}); + group('Content Tests', () { + final debugFillPropertiesCheckbox = { + 'value': 'false', + 'label': 'null', + 'onChanged': 'null', + 'rounded': 'null', + 'useIndeterminate': 'false', + 'focusNode': 'null', + }; + debugFillPropertiesTest( + ZetaCheckbox(), + debugFillPropertiesCheckbox, + ); + final debugFillPropertiesCheckboxInternal = { + 'value': 'false', + 'label': 'null', + 'rounded': 'null', + 'useIndeterminate': 'false', + 'error': 'false', + 'disabled': 'false', + 'focusNode': 'null', + }; + debugFillPropertiesTest( + ZetaInternalCheckbox(onChanged: (_) {}), + debugFillPropertiesCheckboxInternal, + ); + testWidgets('Initializes with correct parameters', (WidgetTester tester) async { await tester.pumpWidget( TestApp( @@ -36,7 +63,10 @@ void main() { expect(checkbox.rounded, null); expect(checkbox.label, 'Test Checkbox'); }); - + }); + group('Dimensions Tests', () {}); + group('Styling Tests', () {}); + group('Interaction Tests', () { testWidgets('ZetaCheckbox changes state on tap', (WidgetTester tester) async { bool? checkboxValue = true; @@ -51,11 +81,6 @@ void main() { ), ); - final checkboxFinder = find.byType(ZetaCheckbox); - await expectLater( - checkboxFinder, - matchesGoldenFile(goldenFile.getFileUri('checkbox_enabled')), - ); await tester.tap(find.byType(ZetaCheckbox)); await tester.pump(); @@ -71,10 +96,7 @@ void main() { ); final checkboxFinder = find.byType(ZetaCheckbox); - await expectLater( - checkboxFinder, - matchesGoldenFile(goldenFile.getFileUri('checkbox_disabled')), - ); + await tester.tap(find.byType(ZetaCheckbox)); await tester.pump(); final ZetaCheckbox checkbox = tester.firstWidget(checkboxFinder); @@ -115,51 +137,46 @@ void main() { await tester.tap(find.byType(ZetaCheckbox)); await tester.pump(); }); - - testWidgets('ZetaCheckbox UI changes on hover', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaCheckbox( - onChanged: (value) {}, - ), - ), - ); - - final checkboxFinder = find.byType(ZetaCheckbox); - - // Hover state - final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); - await gesture.addPointer(location: Offset.zero); - addTearDown(gesture.removePointer); - await tester.pump(); - await gesture.moveTo(tester.getCenter(checkboxFinder)); - await tester.pumpAndSettle(); - await expectLater( - checkboxFinder, - matchesGoldenFile(goldenFile.getFileUri('checkbox_hover')), - ); - }); - - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - ZetaCheckbox().debugFillProperties(diagnostics); - - expect(diagnostics.finder('value'), 'false'); - expect(diagnostics.finder('label'), 'null'); - expect(diagnostics.finder('onChanged'), 'null'); - expect(diagnostics.finder('rounded'), 'null'); - expect(diagnostics.finder('useIndeterminate'), 'false'); - expect(diagnostics.finder('focusNode'), 'null'); - - final internalDiagnostics = DiagnosticPropertiesBuilder(); - ZetaInternalCheckbox(onChanged: (_) {}).debugFillProperties(internalDiagnostics); - expect(internalDiagnostics.finder('value'), 'false'); - expect(internalDiagnostics.finder('label'), 'null'); - expect(internalDiagnostics.finder('rounded'), 'null'); - expect(internalDiagnostics.finder('useIndeterminate'), 'false'); - expect(internalDiagnostics.finder('error'), 'false'); - expect(internalDiagnostics.finder('disabled'), 'false'); - expect(internalDiagnostics.finder('focusNode'), 'null'); - }); }); + group('Golden Tests', () { + goldenTestWithCallbacks( + goldenFile, + ZetaCheckbox( + onChanged: (value) {}, + ), + ZetaCheckbox, + 'checkbox_hover', + after: (tester) async { + final checkboxFinder = find.byType(ZetaCheckbox); + + // Hover state + final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); + await gesture.addPointer(location: Offset.zero); + addTearDown(gesture.removePointer); + await tester.pump(); + await gesture.moveTo(tester.getCenter(checkboxFinder)); + await tester.pumpAndSettle(); + }, + ); + + goldenTest( + goldenFile, + ZetaCheckbox( + value: true, + onChanged: print, + ), + ZetaCheckbox, + 'checkbox_enabled', + ); + + goldenTest( + goldenFile, + ZetaCheckbox( + value: true, + ), + ZetaCheckbox, + 'checkbox_disabled', + ); + }); + group('Performance Tests', () {}); } diff --git a/test/src/components/chips/chip_test.dart b/test/src/components/chips/chip_test.dart index 0d1eb2d1..9a9781e2 100644 --- a/test/src/components/chips/chip_test.dart +++ b/test/src/components/chips/chip_test.dart @@ -3,9 +3,27 @@ import 'package:flutter_test/flutter_test.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() { - group('ZetaChip', () { + const String parentFolder = 'chips'; + + const goldenFile = GoldenFiles(component: parentFolder); + setUpAll(() { + goldenFileComparator = TolerantComparator(goldenFile.uri); + }); + + group('Accessibility Tests', () {}); + group('Content Tests', () { + // final debugFillProperties = { + // '': '', + // }; + // debugFillPropertiesTest( + // widget, + // debugFillProperties, + // ); + testWidgets('renders label correctly', (WidgetTester tester) async { await tester.pumpWidget( const TestApp(home: ZetaChip(label: 'Test Chip')), @@ -13,7 +31,10 @@ void main() { expect(find.text('Test Chip'), findsOneWidget); }); - + }); + group('Dimensions Tests', () {}); + group('Styling Tests', () {}); + group('Interaction Tests', () { testWidgets('triggers onTap callback when tapped', (WidgetTester tester) async { bool tapped = false; @@ -72,30 +93,33 @@ void main() { expect(find.byIcon(Icons.close), findsOneWidget); }); - }); + testWidgets('ZetaChip changes selected property correctly', (WidgetTester tester) async { + bool selected = false; + StateSetter? setState; - testWidgets('ZetaChip changes selected property correctly', (WidgetTester tester) async { - bool selected = false; - StateSetter? setState; - - await tester.pumpWidget( - TestApp( - home: StatefulBuilder( - builder: (context, setState2) { - setState = setState2; - return ZetaChip(label: 'Chip', selected: selected); - }, + await tester.pumpWidget( + TestApp( + home: StatefulBuilder( + builder: (context, setState2) { + setState = setState2; + return ZetaChip(label: 'Chip', selected: selected); + }, + ), ), - ), - ); + ); - final Finder iconFinder = find.byIcon(ZetaIcons.check_mark_round); - expect(iconFinder, findsNothing); + final Finder iconFinder = find.byIcon(ZetaIcons.check_mark_round); + expect(iconFinder, findsNothing); - // Change isOpen property to true - setState?.call(() => selected = true); - await tester.pumpAndSettle(); + // Change isOpen property to true + setState?.call(() => selected = true); + await tester.pumpAndSettle(); - expect(iconFinder, findsOne); + expect(iconFinder, findsOne); + }); + }); + group('Golden Tests', () { + // goldenTest(goldenFile, widget, widgetType, 'PNG_FILE_NAME'); }); + group('Performance Tests', () {}); } diff --git a/test/src/components/comms_button/comms_button_test.dart b/test/src/components/comms_button/comms_button_test.dart index 0322682e..2ff9c648 100644 --- a/test/src/components/comms_button/comms_button_test.dart +++ b/test/src/components/comms_button/comms_button_test.dart @@ -1,19 +1,95 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.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: 'comms_button'); + const String parentFolder = 'comms_button'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - group('ZetaCommsButton Tests', () { + group('Accessibility Tests', () { + testWidgets('Button meets accessibility requirements', (WidgetTester tester) async { + final SemanticsHandle handle = tester.ensureSemantics(); + await tester.pumpWidget( + const TestApp( + home: ZetaCommsButton( + label: 'Label', + semanticLabel: 'Phone', + icon: ZetaIcons.phone, + type: ZetaCommsButtonType.positive, + ), + ), + ); + await expectLater(tester, meetsGuideline(androidTapTargetGuideline)); + await expectLater(tester, meetsGuideline(iOSTapTargetGuideline)); + await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); + await expectLater(tester, meetsGuideline(textContrastGuideline)); + + handle.dispose(); + }); + + testWidgets('Button meets accessibility requirements when toggled', (WidgetTester tester) async { + final SemanticsHandle handle = tester.ensureSemantics(); + await tester.pumpWidget( + TestApp( + home: ZetaCommsButton( + label: 'Label', + semanticLabel: 'Phone', + icon: ZetaIcons.phone, + type: ZetaCommsButtonType.positive, + toggledLabel: 'Toggled Label', + toggledIcon: ZetaIcons.end_call, + toggledType: ZetaCommsButtonType.negative, + onToggle: (isToggled) {}, + ), + ), + ); + await expectLater(tester, meetsGuideline(androidTapTargetGuideline)); + await expectLater(tester, meetsGuideline(iOSTapTargetGuideline)); + await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); + await expectLater(tester, meetsGuideline(textContrastGuideline)); + + await tester.tap(find.byType(ZetaCommsButton)); + await tester.pumpAndSettle(); + + await expectLater(tester, meetsGuideline(androidTapTargetGuideline)); + await expectLater(tester, meetsGuideline(iOSTapTargetGuideline)); + await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); + await expectLater(tester, meetsGuideline(textContrastGuideline)); + + handle.dispose(); + }); + }); + group('Content Tests', () { + final debugFillProperties = { + 'label': '"Label"', + 'onPressed': 'null', + 'onToggle': 'null', + 'toggledIcon': 'null', + 'toggledLabel': 'null', + 'toggleType': null, + 'focusNode': 'null', + 'semanticLabel': 'null', + 'type': 'positive', + 'size': 'medium', + 'icon': 'IconData(U+0E16B)', + }; + debugFillPropertiesTest( + const ZetaCommsButton( + label: 'Label', + icon: ZetaIcons.phone, + type: ZetaCommsButtonType.positive, + ), + debugFillProperties, + ); + testWidgets('Initializes with correct label', (WidgetTester tester) async { await tester.pumpWidget( const TestApp( @@ -22,11 +98,6 @@ void main() { ); expect(find.text('Label'), findsOneWidget); - - await expectLater( - find.byType(ZetaCommsButton), - matchesGoldenFile(goldenFile.getFileUri('CommsButton_default')), - ); }); testWidgets('Initializes with correct icon', (WidgetTester tester) async { @@ -133,99 +204,23 @@ void main() { expect(pressed, isTrue); }); - - testWidgets('debugFillProperties Test', (WidgetTester tester) async { - final diagnostic = DiagnosticPropertiesBuilder(); - const ZetaCommsButton( - label: 'Label', - icon: ZetaIcons.phone, - type: ZetaCommsButtonType.positive, - ).debugFillProperties(diagnostic); - - expect(diagnostic.finder('label'), '"Label"'); - expect(diagnostic.finder('onPressed'), 'null'); - expect(diagnostic.finder('onToggle'), 'null'); - expect(diagnostic.finder('toggledIcon'), 'null'); - expect(diagnostic.finder('toggledLabel'), 'null'); - expect(diagnostic.finder('toggleType'), null); - expect(diagnostic.finder('focusNode'), 'null'); - expect(diagnostic.finder('semanticLabel'), 'null'); - expect(diagnostic.finder('type'), 'positive'); - expect(diagnostic.finder('size'), 'medium'); - expect(diagnostic.finder('icon'), 'IconData(U+0E16B)'); - }); - - testWidgets('Button meets accessibility requirements', (WidgetTester tester) async { - final SemanticsHandle handle = tester.ensureSemantics(); - await tester.pumpWidget( - const TestApp( - home: ZetaCommsButton( - label: 'Label', - semanticLabel: 'Phone', - icon: ZetaIcons.phone, - type: ZetaCommsButtonType.positive, - ), - ), - ); - await expectLater(tester, meetsGuideline(androidTapTargetGuideline)); - await expectLater(tester, meetsGuideline(iOSTapTargetGuideline)); - await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); - await expectLater(tester, meetsGuideline(textContrastGuideline)); - - handle.dispose(); - }); - - testWidgets('Button meets accessibility requirements when toggled', (WidgetTester tester) async { - final SemanticsHandle handle = tester.ensureSemantics(); - await tester.pumpWidget( - TestApp( - home: ZetaCommsButton( - label: 'Label', - semanticLabel: 'Phone', - icon: ZetaIcons.phone, - type: ZetaCommsButtonType.positive, - toggledLabel: 'Toggled Label', - toggledIcon: ZetaIcons.end_call, - toggledType: ZetaCommsButtonType.negative, - onToggle: (isToggled) {}, - ), - ), - ); - await expectLater(tester, meetsGuideline(androidTapTargetGuideline)); - await expectLater(tester, meetsGuideline(iOSTapTargetGuideline)); - await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); - await expectLater(tester, meetsGuideline(textContrastGuideline)); - - await tester.tap(find.byType(ZetaCommsButton)); - await tester.pumpAndSettle(); - - await expectLater(tester, meetsGuideline(androidTapTargetGuideline)); - await expectLater(tester, meetsGuideline(iOSTapTargetGuideline)); - await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); - await expectLater(tester, meetsGuideline(textContrastGuideline)); - - handle.dispose(); - }); }); - - group('ZetaCommsButton Golden Tests', () { + group('Dimensions Tests', () {}); + group('Styling Tests', () {}); + group('Interaction Tests', () {}); + group('Golden Tests', () { for (final type in ZetaCommsButtonType.values) { - testWidgets('ZetaCommsButton with type $type', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaCommsButton( - label: 'Label', - icon: ZetaIcons.phone, - type: type, - ), - ), - ); - - await expectLater( - find.byType(ZetaCommsButton), - matchesGoldenFile(goldenFile.getFileUri('CommsButton_${type.name}')), - ); - }); + goldenTest( + goldenFile, + ZetaCommsButton( + label: 'Label', + icon: ZetaIcons.phone, + type: type, + ), + ZetaCommsButton, + 'CommsButton_${type.name}', + ); } }); + group('Performance Tests', () {}); } diff --git a/test/src/components/comms_button/golden/CommsButton_default.png b/test/src/components/comms_button/golden/CommsButton_default.png deleted file mode 100644 index 3f4c2f73..00000000 Binary files a/test/src/components/comms_button/golden/CommsButton_default.png and /dev/null differ diff --git a/test/src/components/dialpad/dialpad_test.dart b/test/src/components/dialpad/dialpad_test.dart index f85a2d54..b4f5cc7e 100644 --- a/test/src/components/dialpad/dialpad_test.dart +++ b/test/src/components/dialpad/dialpad_test.dart @@ -1,6 +1,5 @@ import 'dart:ui'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; @@ -10,13 +9,64 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { - const goldenFile = GoldenFiles(component: 'dialpad'); + const String parentFolder = 'dialpad'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - group('ZetaDialPad Tests', () { + group('Accessibility Tests', () {}); + + group('Content Tests', () { + final debugFillProperties = { + 'onNumber': 'null', + 'onText': 'null', + 'buttonsPerRow': '3', + 'buttonValues': '{1: , 2: ABC, 3: DEF, 4: GHI, 5: JKL, 6: MNO, 7: PQRS, 8: TUV, 9: WXYZ, *: , 0: +, #: }', + }; + debugFillPropertiesTest( + const ZetaDialPad(), + debugFillProperties, + ); + + final debugFillPropertiesSingleButton = { + 'primary': '"1"', + 'secondary': '""', + 'onTap': 'null', + 'topPadding': '3.0', + }; + debugFillPropertiesTest( + const ZetaDialPadButton(primary: '1'), + debugFillPropertiesSingleButton, + ); + }); + + group('Dimensions Tests', () {}); + + group('Styling Tests', () { + testWidgets('Hover styles for button are correct', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + screenSize: Size(1000, 1000), + home: ZetaDialPadButton(primary: '1'), + ), + ); + final buttonFinder = find.byType(ZetaDialPadButton); + final inkwellFinder = find.byType(InkWell); + final InkWell inkWell = tester.firstWidget(inkwellFinder); + + final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); + await gesture.addPointer(location: Offset.zero); + await tester.pump(); + await gesture.moveTo(tester.getCenter(buttonFinder)); + await tester.pumpAndSettle(); + + expect(inkWell.overlayColor?.resolve({WidgetState.hovered}), ZetaColorBase.cool.shade20); + }); + }); + + group('Interaction Tests', () { testWidgets('Initializes with correct parameters and is enabled', (WidgetTester tester) async { String number = ''; String text = ''; @@ -123,163 +173,139 @@ void main() { /// Allow all timers to end in text debounce await debounceWait(); + }); - await expectLater( - dialPadFinder, - matchesGoldenFile(goldenFile.getFileUri('dialpad_enabled')), + testWidgets('Initializes with correct parameters and is disabled', (WidgetTester tester) async { + const String number = ''; + const String text = ''; + + Future debounceWait() => tester.binding.delayed(const Duration(milliseconds: 500)); + + await tester.pumpWidget( + const TestApp( + screenSize: Size(1000, 1000), + home: ZetaDialPad(), + ), ); - }); - }); - testWidgets('Initializes with correct parameters and is disabled', (WidgetTester tester) async { - const String number = ''; - const String text = ''; + final dialPadFinder = find.byType(ZetaDialPad); + final buttonFinder = find.byType(ZetaDialPadButton); - Future debounceWait() => tester.binding.delayed(const Duration(milliseconds: 500)); + final oneFinder = find.byWidgetPredicate((widget) => widget is ZetaDialPadButton && widget.primary == '1'); + final twoFinder = find.byWidgetPredicate((widget) => widget is ZetaDialPadButton && widget.primary == '2'); + final threeFinder = find.byWidgetPredicate((widget) => widget is ZetaDialPadButton && widget.primary == '3'); + final starFinder = find.byWidgetPredicate((widget) => widget is ZetaDialPadButton && widget.primary == '*'); + final hashFinder = find.byWidgetPredicate((widget) => widget is ZetaDialPadButton && widget.primary == '#'); - await tester.pumpWidget( - const TestApp( - screenSize: Size(1000, 1000), - home: ZetaDialPad(), - ), - ); - final dialPadFinder = find.byType(ZetaDialPad); - final buttonFinder = find.byType(ZetaDialPadButton); - - final oneFinder = find.byWidgetPredicate((widget) => widget is ZetaDialPadButton && widget.primary == '1'); - final twoFinder = find.byWidgetPredicate((widget) => widget is ZetaDialPadButton && widget.primary == '2'); - final threeFinder = find.byWidgetPredicate((widget) => widget is ZetaDialPadButton && widget.primary == '3'); - final starFinder = find.byWidgetPredicate((widget) => widget is ZetaDialPadButton && widget.primary == '*'); - final hashFinder = find.byWidgetPredicate((widget) => widget is ZetaDialPadButton && widget.primary == '#'); - - final ZetaDialPad dialPad = tester.firstWidget(dialPadFinder); - final List dialPadButtons = tester.widgetList(buttonFinder).toList(); - - final ZetaDialPadButton one = tester.firstWidget(oneFinder); - final ZetaDialPadButton two = tester.firstWidget(twoFinder); - final ZetaDialPadButton three = tester.firstWidget(threeFinder); - - /// Dial Pad built correctly. - expect(dialPad.buttonsPerRow, 3); - expect(dialPadButtons.length, 12); - - /// Dial Pad buttons built correctly. - expect(one.primary, '1'); - expect(one.secondary, ''); - expect(two.primary, '2'); - expect(two.secondary, 'ABC'); - expect(three.primary, '3'); - expect(three.secondary, 'DEF'); - - /// Tap button with only number. - await tester.tap(oneFinder); - await tester.pump(); - expect(number, ''); - - /// Tap button with number and text. - await tester.tap(twoFinder); - await tester.pump(); - await debounceWait(); - expect(number, ''); - expect(text, ''); - - /// Tap different button. - await tester.tap(threeFinder); - await tester.pump(); - await debounceWait(); - expect(number, ''); - expect(text, ''); - - /// Tap text button twice. - await tester.tap(twoFinder); - await tester.tap(twoFinder); - await tester.pump(); - await debounceWait(); - expect(text, ''); - - /// Tap text button thrice. - await tester.tap(twoFinder); - await tester.tap(twoFinder); - await tester.tap(twoFinder); - await tester.pump(); - await debounceWait(); - expect(text, ''); - - /// Tap different text buttons to ensure debounce is cancelled. - await tester.tap(twoFinder); - await tester.tap(threeFinder); - await tester.tap(twoFinder); - await tester.pump(); - await debounceWait(); - expect(text, ''); - - /// Tap text button more times than there is options to ensure it loops around correctly. - await tester.tap(threeFinder); - await tester.tap(threeFinder); - await tester.tap(threeFinder); - await tester.tap(threeFinder); - await tester.tap(threeFinder); - await tester.tap(threeFinder); - await tester.tap(oneFinder); - await tester.pump(); - expect(text, ''); - - /// Tap buttons with symbols - await tester.ensureVisible(starFinder); - await tester.tap(starFinder); - await tester.tap(hashFinder); - await tester.pump(); - expect(number, ''); - - /// Allow all timers to end in text debounce - await debounceWait(); - - await expectLater( - dialPadFinder, - matchesGoldenFile(goldenFile.getFileUri('dialpad_disabled')), - ); - }); - testWidgets('ZetaDialPadButton interaction', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - screenSize: Size(1000, 1000), - home: ZetaDialPadButton(primary: '1'), - ), - ); - final buttonFinder = find.byType(ZetaDialPadButton); - final inkwellFinder = find.byType(InkWell); - final InkWell inkWell = tester.firstWidget(inkwellFinder); + final ZetaDialPad dialPad = tester.firstWidget(dialPadFinder); + final List dialPadButtons = tester.widgetList(buttonFinder).toList(); - final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); - await gesture.addPointer(location: Offset.zero); - await tester.pump(); - await gesture.moveTo(tester.getCenter(buttonFinder)); - await tester.pumpAndSettle(); + final ZetaDialPadButton one = tester.firstWidget(oneFinder); + final ZetaDialPadButton two = tester.firstWidget(twoFinder); + final ZetaDialPadButton three = tester.firstWidget(threeFinder); - expect(inkWell.overlayColor?.resolve({WidgetState.hovered}), ZetaColorBase.cool.shade20); + /// Dial Pad built correctly. + expect(dialPad.buttonsPerRow, 3); + expect(dialPadButtons.length, 12); - await expectLater( - buttonFinder, - matchesGoldenFile(goldenFile.getFileUri('dialpadbutton')), - ); - }); + /// Dial Pad buttons built correctly. + expect(one.primary, '1'); + expect(one.secondary, ''); + expect(two.primary, '2'); + expect(two.secondary, 'ABC'); + expect(three.primary, '3'); + expect(three.secondary, 'DEF'); - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - const ZetaDialPad().debugFillProperties(diagnostics); + /// Tap button with only number. + await tester.tap(oneFinder); + await tester.pump(); + expect(number, ''); - expect(diagnostics.finder('onNumber'), 'null'); - expect(diagnostics.finder('onText'), 'null'); - expect(diagnostics.finder('buttonsPerRow'), '3'); - expect( - diagnostics.finder('buttonValues'), - '{1: , 2: ABC, 3: DEF, 4: GHI, 5: JKL, 6: MNO, 7: PQRS, 8: TUV, 9: WXYZ, *: , 0: +, #: }', - ); + /// Tap button with number and text. + await tester.tap(twoFinder); + await tester.pump(); + await debounceWait(); + expect(number, ''); + expect(text, ''); + + /// Tap different button. + await tester.tap(threeFinder); + await tester.pump(); + await debounceWait(); + expect(number, ''); + expect(text, ''); + + /// Tap text button twice. + await tester.tap(twoFinder); + await tester.tap(twoFinder); + await tester.pump(); + await debounceWait(); + expect(text, ''); + + /// Tap text button thrice. + await tester.tap(twoFinder); + await tester.tap(twoFinder); + await tester.tap(twoFinder); + await tester.pump(); + await debounceWait(); + expect(text, ''); + + /// Tap different text buttons to ensure debounce is cancelled. + await tester.tap(twoFinder); + await tester.tap(threeFinder); + await tester.tap(twoFinder); + await tester.pump(); + await debounceWait(); + expect(text, ''); + + /// Tap text button more times than there is options to ensure it loops around correctly. + await tester.tap(threeFinder); + await tester.tap(threeFinder); + await tester.tap(threeFinder); + await tester.tap(threeFinder); + await tester.tap(threeFinder); + await tester.tap(threeFinder); + await tester.tap(oneFinder); + await tester.pump(); + expect(text, ''); + + /// Tap buttons with symbols + await tester.ensureVisible(starFinder); + await tester.tap(starFinder); + await tester.tap(hashFinder); + await tester.pump(); + expect(number, ''); + + /// Allow all timers to end in text debounce + await debounceWait(); + }); + }); - final internalDiagnostics = DiagnosticPropertiesBuilder(); - const ZetaDialPadButton(primary: '1').debugFillProperties(internalDiagnostics); - expect(internalDiagnostics.finder('primary'), '"1"'); - expect(internalDiagnostics.finder('secondary'), '""'); - expect(internalDiagnostics.finder('onTap'), 'null'); - expect(internalDiagnostics.finder('topPadding'), '3.0'); + group('Golden Tests', () { + goldenTest( + goldenFile, + const ZetaDialPad( + onNumber: print, + onText: print, + ), + ZetaDialPad, + 'dialpad_enabled', + screenSize: const Size(1000, 1000), + ); + goldenTest( + goldenFile, + const ZetaDialPad(), + ZetaDialPad, + 'dialpad_disabled', + screenSize: const Size(1000, 1000), + ); + goldenTest( + goldenFile, + const ZetaDialPadButton(primary: '1'), + ZetaDialPadButton, + 'dialpadbutton', + screenSize: const Size(1000, 1000), + ); }); + + group('Performance Tests', () {}); } diff --git a/test/src/components/dialpad/golden/dialpad_disabled.png b/test/src/components/dialpad/golden/dialpad_disabled.png index 5ee42187..2e70f968 100644 Binary files a/test/src/components/dialpad/golden/dialpad_disabled.png and b/test/src/components/dialpad/golden/dialpad_disabled.png differ diff --git a/test/src/components/dialpad/golden/dialpad_enabled.png b/test/src/components/dialpad/golden/dialpad_enabled.png index 5ee42187..2e70f968 100644 Binary files a/test/src/components/dialpad/golden/dialpad_enabled.png and b/test/src/components/dialpad/golden/dialpad_enabled.png differ diff --git a/test/src/components/dialpad/golden/dialpadbutton.png b/test/src/components/dialpad/golden/dialpadbutton.png index 7bbc925e..efb8765e 100644 Binary files a/test/src/components/dialpad/golden/dialpadbutton.png and b/test/src/components/dialpad/golden/dialpadbutton.png differ diff --git a/test/src/components/fab/fab_test.dart b/test/src/components/fab/fab_test.dart new file mode 100644 index 00000000..2820f8ef --- /dev/null +++ b/test/src/components/fab/fab_test.dart @@ -0,0 +1,270 @@ +import 'dart:ui'; + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.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 String parentFolder = 'fab'; + + const goldenFile = GoldenFiles(component: parentFolder); + setUpAll(() { + goldenFileComparator = TolerantComparator(goldenFile.uri); + }); + + group('Accessibility Tests', () {}); + + group('Content Tests', () { + final debugFillProperties = { + 'label': 'null', + 'onPressed': 'null', + 'type': 'primary', + 'size': 'small', + 'shape': 'full', + 'icon': 'IconData(U+0E009)', + 'initiallyExpanded': 'false', + 'focusNode': 'null', + }; + debugFillPropertiesTest( + const ZetaFAB(), + debugFillProperties, + ); + + testWidgets('Initializes with correct parameters', (WidgetTester tester) async { + final scrollController = ScrollController(); + await tester.pumpWidget( + TestApp( + home: ZetaFAB(scrollController: scrollController, label: 'Label', onPressed: () {}), + ), + ); + + expect(find.byType(ZetaFAB), findsOneWidget); + }); + + testWidgets('Icon Test', (WidgetTester tester) async { + final scrollController = ScrollController(); + await tester.pumpWidget( + TestApp( + home: ZetaFAB( + scrollController: scrollController, + onPressed: () {}, + type: ZetaFabType.inverse, + shape: ZetaWidgetBorder.rounded, + size: ZetaFabSize.large, + ), + ), + ); + expect(find.byIcon(ZetaIcons.add_round), findsOneWidget); + final fabFinder = find.byType(ZetaFAB); + final ZetaFAB fab = tester.firstWidget(fabFinder); + + expect(fab.expanded, false); + expect(fab.type, ZetaFabType.inverse); + expect(fab.shape, ZetaWidgetBorder.rounded); + }); + + testWidgets('Expanded', (WidgetTester tester) async { + await tester.pumpWidget( + TestApp( + home: ZetaFAB( + expanded: true, + onPressed: () {}, + label: 'Label', + type: ZetaFabType.secondary, + shape: ZetaWidgetBorder.sharp, + ), + ), + ); + + final fabFinder = find.byType(ZetaFAB); + final ZetaFAB fab = tester.firstWidget(fabFinder); + + expect(fab.expanded, true); + expect(fab.type, ZetaFabType.secondary); + expect(fab.shape, ZetaWidgetBorder.sharp); + }); + + testWidgets('Disabled FAB', (WidgetTester tester) async { + final scrollController = ScrollController(); + await tester.pumpWidget( + TestApp( + home: ZetaFAB(scrollController: scrollController, label: 'Disabled'), + ), + ); + + final fabFinder = find.byType(ZetaFAB); + final ZetaFAB fab = tester.firstWidget(fabFinder); + + expect(fab.onPressed, isNull); + expect(fab.type, ZetaFabType.primary); + expect(fab.shape, ZetaWidgetBorder.full); + }); + + testWidgets('Label is correct', (WidgetTester tester) async { + final scrollController = ScrollController(); + StateSetter? setState; + bool expanded = false; + + await tester.pumpWidget( + TestApp( + home: StatefulBuilder( + builder: (context, setState2) { + setState = setState2; + return ZetaFAB( + scrollController: scrollController, + expanded: expanded, + label: 'Label', + onPressed: () {}, + ); + }, + ), + ), + ); + + final labelFinder = find.text('Label'); + + expect(labelFinder, findsOne); + + setState?.call(() => expanded = true); + + await tester.pumpAndSettle(); + expect(labelFinder, findsOne); + }); + }); + + group('Dimensions Tests', () {}); + + group('Styling Tests', () { + testWidgets('hover colours are correct', (WidgetTester tester) async { + final FocusNode node = FocusNode(); + + await tester.pumpWidget( + TestApp( + home: ZetaFAB( + expanded: true, + onPressed: () {}, + label: 'Label', + type: ZetaFabType.secondary, + shape: ZetaWidgetBorder.sharp, + focusNode: node, + ), + ), + ); + + final fabFinder = find.byType(ZetaFAB); + final ZetaFAB fab = tester.firstWidget(fabFinder); + final filledButtonFinder = find.byType(FilledButton); + final FilledButton filledButton = tester.firstWidget(filledButtonFinder); + + expect(fab.expanded, true); + expect(fab.type, ZetaFabType.secondary); + expect(fab.shape, ZetaWidgetBorder.sharp); + + final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); + await gesture.addPointer(location: Offset.zero); + await tester.pumpAndSettle(); + await gesture.moveTo(tester.getCenter(fabFinder)); + await tester.pumpAndSettle(); + + expect(filledButton.style?.backgroundColor?.resolve({WidgetState.hovered}), ZetaColorBase.yellow.shade70); + + await gesture.moveTo(Offset.zero); + await tester.pumpAndSettle(); + + node.requestFocus(); + await tester.pumpAndSettle(); + expect( + filledButton.style?.side?.resolve({WidgetState.focused}), + BorderSide(color: ZetaColorBase.blue[50]!, width: ZetaBorders.medium), + ); + }); + }); + + group('Interaction Tests', () { + testWidgets('OnPressed callback', (WidgetTester tester) async { + bool isPressed = false; + final scrollController = ScrollController(); + + await tester.pumpWidget( + TestApp( + home: ZetaFAB(scrollController: scrollController, label: 'Label', onPressed: () => isPressed = true), + ), + ); + final TestGesture e = await tester.press(find.byType(ZetaFAB)); + + await tester.pumpAndSettle(); + + await e.up(); + expect(isPressed, isTrue); + }); + }); + + group('Golden Tests', () { + goldenTest( + goldenFile, + ZetaFAB( + scrollController: ScrollController(), + label: 'Label', + onPressed: () {}, + ), + ZetaFAB, + 'FAB_default', + ); + goldenTestWithCallbacks( + goldenFile, + ZetaFAB(scrollController: ScrollController(), label: 'Label', onPressed: () => {}), + ZetaFAB, + 'FAB_pressed', + after: (tester) async { + await tester.press(find.byType(ZetaFAB)); + await tester.pumpAndSettle(); + }, + ); + goldenTest( + goldenFile, + ZetaFAB( + scrollController: ScrollController(), + onPressed: () {}, + type: ZetaFabType.inverse, + shape: ZetaWidgetBorder.rounded, + size: ZetaFabSize.large, + ), + ZetaFAB, + 'FAB_inverse', + ); + goldenTestWithCallbacks( + goldenFile, + ZetaFAB(scrollController: ScrollController(), label: 'Label', onPressed: () => {}), + ZetaFAB, + 'FAB_pressed', + after: (tester) async { + await tester.press(find.byType(ZetaFAB)); + await tester.pumpAndSettle(); + }, + ); + goldenTest( + goldenFile, + ZetaFAB( + expanded: true, + onPressed: () {}, + label: 'Label', + type: ZetaFabType.secondary, + shape: ZetaWidgetBorder.sharp, + ), + ZetaFAB, + 'FAB_secondary', + ); + goldenTest( + goldenFile, + ZetaFAB(scrollController: ScrollController(), label: 'Disabled'), + ZetaFAB, + 'FAB_disabled', + ); + }); + + group('Performance Tests', () {}); +} diff --git a/test/src/components/fabs/fab_test.dart b/test/src/components/fabs/fab_test.dart deleted file mode 100644 index f82fd5ed..00000000 --- a/test/src/components/fabs/fab_test.dart +++ /dev/null @@ -1,219 +0,0 @@ -import 'dart:ui'; - -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.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(() { - goldenFileComparator = TolerantComparator(goldenFile.uri); - }); - - group('ZetaFAB Tests', () { - testWidgets('Initializes with correct parameters', (WidgetTester tester) async { - final scrollController = ScrollController(); - await tester.pumpWidget( - TestApp( - home: ZetaFAB(scrollController: scrollController, label: 'Label', onPressed: () {}), - ), - ); - - expect(find.byType(ZetaFAB), findsOneWidget); - - await expectLater( - find.byType(ZetaFAB), - matchesGoldenFile(goldenFile.getFileUri('FAB_default')), - ); - }); - - testWidgets('OnPressed callback', (WidgetTester tester) async { - bool isPressed = false; - final scrollController = ScrollController(); - - await tester.pumpWidget( - TestApp( - home: ZetaFAB(scrollController: scrollController, label: 'Label', onPressed: () => isPressed = true), - ), - ); - final TestGesture e = await tester.press(find.byType(ZetaFAB)); - - await tester.pumpAndSettle(); - - await expectLater( - find.byType(ZetaFAB), - matchesGoldenFile(goldenFile.getFileUri('FAB_pressed')), - ); - - await e.up(); - expect(isPressed, isTrue); - }); - }); - - testWidgets('Icon Test', (WidgetTester tester) async { - final scrollController = ScrollController(); - await tester.pumpWidget( - TestApp( - home: ZetaFAB( - scrollController: scrollController, - onPressed: () {}, - type: ZetaFabType.inverse, - shape: ZetaWidgetBorder.rounded, - size: ZetaFabSize.large, - ), - ), - ); - expect(find.byIcon(ZetaIcons.add_round), findsOneWidget); - final fabFinder = find.byType(ZetaFAB); - final ZetaFAB fab = tester.firstWidget(fabFinder); - - expect(fab.expanded, false); - expect(fab.type, ZetaFabType.inverse); - expect(fab.shape, ZetaWidgetBorder.rounded); - - await expectLater( - find.byType(ZetaFAB), - matchesGoldenFile(goldenFile.getFileUri('FAB_inverse')), - ); - }); - - testWidgets('Expanded', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaFAB( - expanded: true, - onPressed: () {}, - label: 'Label', - type: ZetaFabType.secondary, - shape: ZetaWidgetBorder.sharp, - ), - ), - ); - - final fabFinder = find.byType(ZetaFAB); - final ZetaFAB fab = tester.firstWidget(fabFinder); - - expect(fab.expanded, true); - expect(fab.type, ZetaFabType.secondary); - expect(fab.shape, ZetaWidgetBorder.sharp); - - await expectLater( - find.byType(ZetaFAB), - matchesGoldenFile(goldenFile.getFileUri('FAB_secondary')), - ); - }); - testWidgets('ZetaFAB interactive', (WidgetTester tester) async { - final FocusNode node = FocusNode(); - - await tester.pumpWidget( - TestApp( - home: ZetaFAB( - expanded: true, - onPressed: () {}, - label: 'Label', - type: ZetaFabType.secondary, - shape: ZetaWidgetBorder.sharp, - focusNode: node, - ), - ), - ); - - final fabFinder = find.byType(ZetaFAB); - final ZetaFAB fab = tester.firstWidget(fabFinder); - final filledButtonFinder = find.byType(FilledButton); - final FilledButton filledButton = tester.firstWidget(filledButtonFinder); - - expect(fab.expanded, true); - expect(fab.type, ZetaFabType.secondary); - expect(fab.shape, ZetaWidgetBorder.sharp); - - final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); - await gesture.addPointer(location: Offset.zero); - await tester.pumpAndSettle(); - await gesture.moveTo(tester.getCenter(fabFinder)); - await tester.pumpAndSettle(); - - expect(filledButton.style?.backgroundColor?.resolve({WidgetState.hovered}), ZetaColorBase.yellow.shade70); - - await gesture.moveTo(Offset.zero); - await tester.pumpAndSettle(); - - node.requestFocus(); - await tester.pumpAndSettle(); - expect( - filledButton.style?.side?.resolve({WidgetState.focused}), - BorderSide(color: ZetaColorBase.blue[50]!, width: ZetaBorders.medium), - ); - }); - - testWidgets('Disabled FAB', (WidgetTester tester) async { - final scrollController = ScrollController(); - await tester.pumpWidget( - TestApp( - home: ZetaFAB(scrollController: scrollController, label: 'Disabled'), - ), - ); - - final fabFinder = find.byType(ZetaFAB); - final ZetaFAB fab = tester.firstWidget(fabFinder); - - expect(fab.onPressed, isNull); - expect(fab.type, ZetaFabType.primary); - expect(fab.shape, ZetaWidgetBorder.full); - - await expectLater( - find.byType(ZetaFAB), - matchesGoldenFile(goldenFile.getFileUri('FAB_disabled')), - ); - }); - - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - const ZetaFAB().debugFillProperties(diagnostics); - - expect(diagnostics.finder('label'), 'null'); - expect(diagnostics.finder('onPressed'), 'null'); - expect(diagnostics.finder('type'), 'primary'); - expect(diagnostics.finder('size'), 'small'); - expect(diagnostics.finder('shape'), 'full'); - expect(diagnostics.finder('icon'), 'IconData(U+0E009)'); - expect(diagnostics.finder('initiallyExpanded'), 'false'); - expect(diagnostics.finder('focusNode'), 'null'); - }); - - testWidgets('Label is correct', (WidgetTester tester) async { - final scrollController = ScrollController(); - StateSetter? setState; - bool expanded = false; - - await tester.pumpWidget( - TestApp( - home: StatefulBuilder( - builder: (context, setState2) { - setState = setState2; - return ZetaFAB( - scrollController: scrollController, - expanded: expanded, - label: 'Label', - onPressed: () {}, - ); - }, - ), - ), - ); - - final labelFinder = find.text('Label'); - - expect(labelFinder, findsOne); - - setState?.call(() => expanded = true); - - await tester.pumpAndSettle(); - expect(labelFinder, findsOne); - }); -} diff --git a/test/src/components/fabs/golden/FAB_default.png b/test/src/components/fabs/golden/FAB_default.png deleted file mode 100644 index 8ab4dac2..00000000 Binary files a/test/src/components/fabs/golden/FAB_default.png and /dev/null differ diff --git a/test/src/components/fabs/golden/FAB_disabled.png b/test/src/components/fabs/golden/FAB_disabled.png deleted file mode 100644 index 24e1062f..00000000 Binary files a/test/src/components/fabs/golden/FAB_disabled.png and /dev/null differ diff --git a/test/src/components/fabs/golden/FAB_inverse.png b/test/src/components/fabs/golden/FAB_inverse.png deleted file mode 100644 index 41bf5c0f..00000000 Binary files a/test/src/components/fabs/golden/FAB_inverse.png and /dev/null differ diff --git a/test/src/components/fabs/golden/FAB_pressed.png b/test/src/components/fabs/golden/FAB_pressed.png deleted file mode 100644 index 10365d11..00000000 Binary files a/test/src/components/fabs/golden/FAB_pressed.png and /dev/null differ diff --git a/test/src/components/fabs/golden/FAB_secondary.png b/test/src/components/fabs/golden/FAB_secondary.png deleted file mode 100644 index 40f2cf3b..00000000 Binary files a/test/src/components/fabs/golden/FAB_secondary.png and /dev/null differ diff --git a/test/src/components/icon/icon_test.dart b/test/src/components/icon/icon_test.dart index 05cbbb5e..3afa42bd 100644 --- a/test/src/components/icon/icon_test.dart +++ b/test/src/components/icon/icon_test.dart @@ -1,28 +1,60 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.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() { - group('Zeta Icon', () { - testWidgets('renders icon correctly', (WidgetTester tester) async { - await tester.pumpWidget(const TestApp(home: ZetaIcon(ZetaIcons.add_round))); + const String parentFolder = 'icon'; + + const goldenFile = GoldenFiles(component: parentFolder); + setUpAll(() { + goldenFileComparator = TolerantComparator(goldenFile.uri); + }); + + group('Accessibility Tests', () { + testWidgets('applies correct semantic label to icon', (WidgetTester tester) async { + const String semanticLabel = 'Add Icon'; + await tester.pumpWidget(const TestApp(home: ZetaIcon(ZetaIcons.add_round, semanticLabel: semanticLabel))); final iconFinder = find.byIcon(ZetaIcons.add_round); - expect(iconFinder, findsOneWidget); + final iconWidget = tester.widget(iconFinder); + expect(iconWidget.semanticLabel, equals(semanticLabel)); }); + }); + group('Content Tests', () { + final debugFillProperties = { + 'icon': 'IconData(U+0E045)', + 'rounded': 'false', + 'size': '10.0', + 'fill': 'null', + 'weight': 'null', + 'grade': 'null', + 'opticalSize': 'null', + 'color': 'null', + 'shadows': 'null', + 'semanticLabel': '"Cached"', + 'textDirection': 'null', + 'applyTextScaling': 'null', + }; + debugFillPropertiesTest( + const ZetaIcon( + ZetaIcons.cached, + rounded: false, + size: 10, + semanticLabel: 'Cached', + ), + debugFillProperties, + ); - testWidgets('applies correct size to icon', (WidgetTester tester) async { - const double iconSize = 24; - await tester.pumpWidget(const TestApp(home: ZetaIcon(ZetaIcons.add_round, size: iconSize))); + testWidgets('renders icon correctly', (WidgetTester tester) async { + await tester.pumpWidget(const TestApp(home: ZetaIcon(ZetaIcons.add_round))); final iconFinder = find.byIcon(ZetaIcons.add_round); - final iconWidget = tester.widget(iconFinder); - expect(iconWidget.size, equals(iconSize)); + expect(iconFinder, findsOneWidget); }); - testWidgets('applies correct color to icon', (WidgetTester tester) async { + testWidgets('color value is correct', (WidgetTester tester) async { const Color iconColor = Colors.red; await tester.pumpWidget(const TestApp(home: ZetaIcon(ZetaIcons.add_round, color: iconColor))); final iconFinder = find.byIcon(ZetaIcons.add_round); @@ -30,14 +62,6 @@ void main() { expect(iconWidget.color, equals(iconColor)); }); - testWidgets('applies correct semantic label to icon', (WidgetTester tester) async { - const String semanticLabel = 'Add Icon'; - await tester.pumpWidget(const TestApp(home: ZetaIcon(ZetaIcons.add_round, semanticLabel: semanticLabel))); - final iconFinder = find.byIcon(ZetaIcons.add_round); - final iconWidget = tester.widget(iconFinder); - expect(iconWidget.semanticLabel, equals(semanticLabel)); - }); - testWidgets('applies sharp family to icon', (WidgetTester tester) async { await tester.pumpWidget( const TestApp( @@ -58,7 +82,18 @@ void main() { expect(iconFinderRound, findsOneWidget); expect(iconFinderSharp, findsExactly(1)); }); - + }); + group('Dimensions Tests', () { + testWidgets('applies correct size to icon', (WidgetTester tester) async { + const double iconSize = 24; + await tester.pumpWidget(const TestApp(home: ZetaIcon(ZetaIcons.add_round, size: iconSize))); + final iconFinder = find.byIcon(ZetaIcons.add_round); + final sizeOfIcon = tester.getSize(iconFinder); + expect(sizeOfIcon.width, equals(iconSize)); + expect(sizeOfIcon.height, equals(iconSize)); + }); + }); + group('Styling Tests', () { testWidgets('applies correct font family to icon', (WidgetTester tester) async { await tester.pumpWidget(const TestApp(home: ZetaIcon(ZetaIcons.add_round))); final iconFinder = find.byIcon(ZetaIcons.add_round); @@ -145,28 +180,10 @@ void main() { final iconWidget = tester.widget(iconFinder); expect(iconWidget.icon?.fontFamily, equals('MaterialIcons')); }); - - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - const ZetaIcon( - ZetaIcons.cached, - rounded: false, - size: 10, - semanticLabel: 'Cached', - ).debugFillProperties(diagnostics); - - expect(diagnostics.finder('icon'), 'IconData(U+0E045)'); - expect(diagnostics.finder('rounded'), 'false'); - expect(diagnostics.finder('size'), '10.0'); - expect(diagnostics.finder('fill'), 'null'); - expect(diagnostics.finder('weight'), 'null'); - expect(diagnostics.finder('grade'), 'null'); - expect(diagnostics.finder('opticalSize'), 'null'); - expect(diagnostics.finder('color'), 'null'); - expect(diagnostics.finder('shadows'), 'null'); - expect(diagnostics.finder('semanticLabel'), '"Cached"'); - expect(diagnostics.finder('textDirection'), 'null'); - expect(diagnostics.finder('applyTextScaling'), 'null'); - }); }); + group('Interaction Tests', () {}); + group('Golden Tests', () { + // goldenTest(goldenFile, widget, widgetType, 'PNG_FILE_NAME'); + }); + group('Performance Tests', () {}); } 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 4c825515..f29bffed 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,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; @@ -8,120 +7,174 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { - const goldenFile = GoldenFiles(component: 'in_page_banner'); + const String parentFolder = 'in_page_banner'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - group('ZetaInPageBanner Tests', () { - testWidgets('ZetaInPageBanner creation', (WidgetTester tester) async { + group('Accessibility Tests', () {}); + group('Content Tests', () { + final debugFillProperties = { + 'onClose': 'null', + 'status': 'info', + 'title': 'null', + 'customIcon': 'null', + }; + debugFillPropertiesTest( + const ZetaInPageBanner(content: Placeholder()), + debugFillProperties, + ); + + testWidgets('renders correct icon and text', (WidgetTester tester) async { await tester.pumpWidget( const TestApp( home: ZetaInPageBanner(content: Text('Test'), title: 'Title'), ), ); - final Finder decoratedBoxFinder = find.byType(DecoratedBox); - final DecoratedBox box = tester.firstWidget(decoratedBoxFinder); - expect(find.byType(ZetaInPageBanner), findsOneWidget); expect(find.text('Test'), findsOneWidget); + }); + + testWidgets("ZetaInPageBanner shows 'close icon' correctly", (WidgetTester tester) async { + await tester.pumpWidget( + TestApp(home: ZetaInPageBanner(content: const Text('Test'), onClose: () {}, status: ZetaWidgetStatus.negative)), + ); + + expect(find.byIcon(ZetaIcons.close_round), findsOneWidget); + }); + + testWidgets("ZetaInPageBanner hides 'close icon' correctly", (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp(home: ZetaInPageBanner(content: Text('Test'), status: ZetaWidgetStatus.positive)), + ); + expect(find.byIcon(ZetaIcons.close_round), findsNothing); + }); + }); + group('Dimensions Tests', () {}); + group('Styling Tests', () { + testWidgets('default background colour is correct', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: ZetaInPageBanner(content: Text('Test'), title: 'Title'), + ), + ); + final Finder decoratedBoxFinder = find.byType(DecoratedBox); + final DecoratedBox box = tester.firstWidget(decoratedBoxFinder); expect(box.decoration.runtimeType, BoxDecoration); final BoxDecoration decoration = box.decoration as BoxDecoration; expect(decoration.color, ZetaColorBase.purple.shade10); + }); - await expectLater( - find.byType(ZetaInPageBanner), - matchesGoldenFile(goldenFile.getFileUri('in_page_banner_default')), + testWidgets('negative background colour is correct', (WidgetTester tester) async { + await tester.pumpWidget( + TestApp(home: ZetaInPageBanner(content: const Text('Test'), onClose: () {}, status: ZetaWidgetStatus.negative)), ); + + final Finder decoratedBoxFinder = find.byType(DecoratedBox); + final DecoratedBox box = tester.firstWidget(decoratedBoxFinder); + expect(box.decoration.runtimeType, BoxDecoration); + final BoxDecoration decoration = box.decoration as BoxDecoration; + expect(decoration.color, ZetaColorBase.red.shade10); }); - }); - testWidgets("ZetaInPageBanner shows 'close icon' correctly", (WidgetTester tester) async { - await tester.pumpWidget( - TestApp(home: ZetaInPageBanner(content: const Text('Test'), onClose: () {}, status: ZetaWidgetStatus.negative)), - ); + testWidgets('positive background colour is correct', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp(home: ZetaInPageBanner(content: Text('Test'), status: ZetaWidgetStatus.positive)), + ); - expect(find.byIcon(ZetaIcons.close_round), findsOneWidget); - final Finder decoratedBoxFinder = find.byType(DecoratedBox); - final DecoratedBox box = tester.firstWidget(decoratedBoxFinder); - expect(box.decoration.runtimeType, BoxDecoration); - final BoxDecoration decoration = box.decoration as BoxDecoration; - expect(decoration.color, ZetaColorBase.red.shade10); - await expectLater( - find.byType(ZetaInPageBanner), - matchesGoldenFile(goldenFile.getFileUri('in_page_banner_negative')), - ); - }); + final Finder decoratedBoxFinder = find.byType(DecoratedBox); + final DecoratedBox box = tester.firstWidget(decoratedBoxFinder); + expect(box.decoration.runtimeType, BoxDecoration); + final BoxDecoration decoration = box.decoration as BoxDecoration; + expect(decoration.color, ZetaColorBase.green.shade10); + }); - testWidgets("ZetaInPageBanner hides 'close icon' correctly", (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp(home: ZetaInPageBanner(content: Text('Test'), status: ZetaWidgetStatus.positive)), - ); - expect(find.byIcon(ZetaIcons.close_round), findsNothing); - final Finder decoratedBoxFinder = find.byType(DecoratedBox); - final DecoratedBox box = tester.firstWidget(decoratedBoxFinder); - expect(box.decoration.runtimeType, BoxDecoration); - final BoxDecoration decoration = box.decoration as BoxDecoration; - expect(decoration.color, ZetaColorBase.green.shade10); - await expectLater( - find.byType(ZetaInPageBanner), - matchesGoldenFile(goldenFile.getFileUri('in_page_banner_positive')), - ); - }); + testWidgets('neutral background colour is correct', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp(home: ZetaInPageBanner(content: Text('Test'), status: ZetaWidgetStatus.neutral)), + ); - testWidgets('ZetaInPageBanner button callbacks work', (WidgetTester tester) async { - bool onPressed = false; - final key = GlobalKey(); - await tester.pumpWidget( - TestApp( - home: ZetaInPageBanner( - content: const Text('Test'), - status: ZetaWidgetStatus.neutral, - actions: [ - ZetaButton( - label: 'Test button', - onPressed: () => onPressed = true, - key: key, - ), - ], + final Finder decoratedBoxFinder = find.byType(DecoratedBox); + final DecoratedBox box = tester.firstWidget(decoratedBoxFinder); + expect(box.decoration.runtimeType, BoxDecoration); + final BoxDecoration decoration = box.decoration as BoxDecoration; + expect(decoration.color, ZetaColorBase.cool.shade10); + }); + }); + group('Interaction Tests', () { + testWidgets('button callback works', (WidgetTester tester) async { + bool onPressed = false; + final key = GlobalKey(); + await tester.pumpWidget( + TestApp( + home: ZetaInPageBanner( + content: const Text('Test'), + status: ZetaWidgetStatus.neutral, + actions: [ + ZetaButton( + label: 'Test button', + onPressed: () => onPressed = true, + key: key, + ), + ], + ), ), - ), - ); + ); - final Finder decoratedBoxFinder = find.byType(DecoratedBox); - final DecoratedBox box = tester.firstWidget(decoratedBoxFinder); - expect(box.decoration.runtimeType, BoxDecoration); - final BoxDecoration decoration = box.decoration as BoxDecoration; - expect(decoration.color, ZetaColorBase.cool.shade10); + await tester.tap(find.byKey(key)); + await tester.pumpAndSettle(); + expect(onPressed, isTrue); + }); - await tester.tap(find.byKey(key)); - await tester.pumpAndSettle(); - expect(onPressed, isTrue); + testWidgets("ZetaInPageBanner 'close' icon tap test", (WidgetTester tester) async { + bool closeIconIsTapped = false; + await tester.pumpWidget( + TestApp(home: ZetaInPageBanner(onClose: () => closeIconIsTapped = true, content: const Text('Test'))), + ); + final closeIcon = find.byIcon(ZetaIcons.close_round); + await tester.tap(closeIcon); + await tester.pump(); + expect(closeIconIsTapped, isTrue); + }); + }); - await expectLater( - find.byType(ZetaInPageBanner), - matchesGoldenFile(goldenFile.getFileUri('in_page_banner_buttons')), + group('Golden Tests', () { + goldenTest( + goldenFile, + const ZetaInPageBanner(content: Text('Test'), title: 'Title'), + ZetaInPageBanner, + 'in_page_banner_default', ); - }); - testWidgets("ZetaInPageBanner 'close' icon tap test", (WidgetTester tester) async { - bool closeIconIsTapped = false; - await tester.pumpWidget( - TestApp(home: ZetaInPageBanner(onClose: () => closeIconIsTapped = true, content: const Text('Test'))), + goldenTest( + goldenFile, + ZetaInPageBanner(content: const Text('Test'), onClose: () {}, status: ZetaWidgetStatus.negative), + ZetaInPageBanner, + 'in_page_banner_negative', + ); + goldenTest( + goldenFile, + const ZetaInPageBanner(content: Text('Test'), status: ZetaWidgetStatus.positive), + ZetaInPageBanner, + 'in_page_banner_positive', + ); + goldenTest( + goldenFile, + ZetaInPageBanner( + content: const Text('Test'), + status: ZetaWidgetStatus.neutral, + actions: [ + ZetaButton( + label: 'Test button', + onPressed: () {}, + ), + ], + ), + ZetaInPageBanner, + 'in_page_banner_buttons', ); - final closeIcon = find.byIcon(ZetaIcons.close_round); - await tester.tap(closeIcon); - await tester.pump(); - expect(closeIconIsTapped, isTrue); - }); - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - const ZetaInPageBanner(content: Placeholder()).debugFillProperties(diagnostics); - - expect(diagnostics.finder('onClose'), 'null'); - expect(diagnostics.finder('status'), 'info'); - expect(diagnostics.finder('title'), 'null'); - expect(diagnostics.finder('customIcon'), 'null'); }); + group('Performance Tests', () {}); } diff --git a/test/src/components/password/password_input_test.dart b/test/src/components/password/password_input_test.dart index 57dbbd28..c67a7ad6 100644 --- a/test/src/components/password/password_input_test.dart +++ b/test/src/components/password/password_input_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; @@ -8,87 +7,112 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { - const goldenFile = GoldenFiles(component: 'password'); + const String parentFolder = 'password'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - testWidgets('ZetaPasswordInput initializes correctly', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaPasswordInput(), - ), + group('Accessibility Tests', () {}); + group('Content Tests', () { + final debugFillProperties = { + 'size': 'medium', + 'placeholder': 'null', + 'label': 'null', + 'hintText': 'null', + 'errorText': 'null', + 'semanticLabel': 'null', + 'showSemanticLabel': 'null', + 'obscureSemanticLabel': 'null', + }; + debugFillPropertiesTest( + ZetaPasswordInput(), + debugFillProperties, ); - expect(find.byType(ZetaPasswordInput), findsOneWidget); - await expectLater( - find.byType(ZetaPasswordInput), - matchesGoldenFile(goldenFile.getFileUri('password_default')), - ); - }); + testWidgets('ZetaPasswordInput initializes correctly', (WidgetTester tester) async { + await tester.pumpWidget( + TestApp( + home: ZetaPasswordInput(), + ), + ); + expect(find.byType(ZetaPasswordInput), findsOneWidget); + }); - testWidgets('Test password visibility', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaPasswordInput(), - ), - ); - final obscureIconOff = find.byIcon(ZetaIcons.visibility_off_round); - expect(obscureIconOff, findsOneWidget); - await tester.tap(obscureIconOff); - await tester.pump(); + testWidgets('obscure icon in rendered correctly', (WidgetTester tester) async { + await tester.pumpWidget( + TestApp( + home: ZetaPasswordInput(), + ), + ); + final obscureIconOff = find.byIcon(ZetaIcons.visibility_off_round); + expect(obscureIconOff, findsOneWidget); + await tester.tap(obscureIconOff); + await tester.pump(); - final obscureIconOn = find.byIcon(ZetaIcons.visibility_round); - expect(obscureIconOn, findsOneWidget); - }); + final obscureIconOn = find.byIcon(ZetaIcons.visibility_round); + expect(obscureIconOn, findsOneWidget); + }); - testWidgets('Test error message visibility', (WidgetTester tester) async { - String? testValidator(String? value) { - final regExp = RegExp(r'\d'); - if (value != null && regExp.hasMatch(value)) return 'Error'; - return null; - } + testWidgets('Test error message visibility', (WidgetTester tester) async { + String? testValidator(String? value) { + final regExp = RegExp(r'\d'); + if (value != null && regExp.hasMatch(value)) return 'Error'; + return null; + } - final controller = TextEditingController()..text = 'password123'; - final formKey = GlobalKey(); + final controller = TextEditingController()..text = 'password123'; + final formKey = GlobalKey(); - await tester.pumpWidget( - TestApp( - home: Form( - key: formKey, - child: ZetaPasswordInput( - controller: controller, - validator: testValidator, - rounded: false, + await tester.pumpWidget( + TestApp( + home: Form( + key: formKey, + child: ZetaPasswordInput( + controller: controller, + validator: testValidator, + rounded: false, + ), ), ), - ), - ); - formKey.currentState?.validate(); - await tester.pump(); - - // There will be two matches for the error text as the form field itself contains a hidden one. - expect(find.text('Error'), findsExactly(2)); - final obscureIconOn = find.byIcon(ZetaIcons.visibility_off_sharp); - expect(obscureIconOn, findsOneWidget); + ); + formKey.currentState?.validate(); + await tester.pump(); - await expectLater( - find.byType(ZetaPasswordInput), - matchesGoldenFile(goldenFile.getFileUri('password_error')), - ); + // There will be two matches for the error text as the form field itself contains a hidden one. + expect(find.text('Error'), findsExactly(2)); + final obscureIconOn = find.byIcon(ZetaIcons.visibility_off_sharp); + expect(obscureIconOn, findsOneWidget); + }); }); - testWidgets('Test debugFillProperties', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - ZetaPasswordInput().debugFillProperties(diagnostics); - - expect(diagnostics.finder('size'), 'medium'); - expect(diagnostics.finder('placeholder'), 'null'); - expect(diagnostics.finder('label'), 'null'); - expect(diagnostics.finder('hintText'), 'null'); - expect(diagnostics.finder('errorText'), 'null'); - expect(diagnostics.finder('semanticLabel'), 'null'); - expect(diagnostics.finder('showSemanticLabel'), 'null'); - expect(diagnostics.finder('obscureSemanticLabel'), 'null'); + group('Dimensions Tests', () {}); + group('Styling Tests', () {}); + group('Interaction Tests', () {}); + group('Golden Tests', () { + goldenTest(goldenFile, ZetaPasswordInput(), ZetaPasswordInput, 'password_default'); + final formKey = GlobalKey(); + goldenTestWithCallbacks( + goldenFile, + Form( + key: formKey, + child: ZetaPasswordInput( + controller: TextEditingController()..text = 'password123', + validator: (String? value) { + final regExp = RegExp(r'\d'); + if (value != null && regExp.hasMatch(value)) return 'Error'; + return null; + }, + rounded: false, + ), + ), + ZetaPasswordInput, + 'password_error', + after: (tester) async { + formKey.currentState?.validate(); + await tester.pump(); + }, + ); }); + group('Performance Tests', () {}); } diff --git a/test/src/components/search_bar/search_bar_test.dart b/test/src/components/search_bar/search_bar_test.dart index 120b326a..42e1ed7b 100644 --- a/test/src/components/search_bar/search_bar_test.dart +++ b/test/src/components/search_bar/search_bar_test.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; @@ -26,8 +25,9 @@ abstract class ISearchBarEvents { ]) void main() { late MockISearchBarEvents callbacks; - const goldenFile = GoldenFiles(component: 'search_bar'); + const String parentFolder = 'search_bar'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); @@ -36,8 +36,25 @@ void main() { callbacks = MockISearchBarEvents(); }); - group('ZetaSearchBar', () { - testWidgets('renders with default parameters', (WidgetTester tester) async { + group('Accessibility Tests', () {}); + group('Content Tests', () { + final debugFillProperties = { + 'size': 'medium', + 'shape': 'rounded', + 'placeholder': 'null', + 'textInputAction': 'null', + 'onSpeechToText': 'null', + 'showSpeechToText': 'true', + 'focusNode': 'null', + 'microphoneSemanticLabel': 'null', + 'clearSemanticLabel': 'null', + }; + debugFillPropertiesTest( + ZetaSearchBar(), + debugFillProperties, + ); + + testWidgets('renders text field', (WidgetTester tester) async { await tester.pumpWidget( TestApp( home: Scaffold( @@ -50,82 +67,6 @@ void main() { expect(find.byType(TextField), findsOneWidget); }); - testWidgets('golden: renders initializes correctly', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaSearchBar(), - ), - ); - expect(find.byType(ZetaSearchBar), findsOneWidget); - - await expectLater( - find.byType(ZetaSearchBar), - matchesGoldenFile(goldenFile.getFileUri('search_bar_default')), - ); - }); - - testWidgets('golden: renders size medium correctly', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaSearchBar(), - ), - ); - expect(find.byType(ZetaSearchBar), findsOneWidget); - - await expectLater( - find.byType(ZetaSearchBar), - matchesGoldenFile(goldenFile.getFileUri('search_bar_medium')), - ); - }); - - testWidgets('golden: renders size small correctly', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaSearchBar( - size: ZetaWidgetSize.small, - ), - ), - ); - expect(find.byType(ZetaSearchBar), findsOneWidget); - - await expectLater( - find.byType(ZetaSearchBar), - matchesGoldenFile(goldenFile.getFileUri('search_bar_small')), - ); - }); - - testWidgets('golden: renders shape full correctly', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaSearchBar( - shape: ZetaWidgetBorder.full, - ), - ), - ); - expect(find.byType(ZetaSearchBar), findsOneWidget); - - await expectLater( - find.byType(ZetaSearchBar), - matchesGoldenFile(goldenFile.getFileUri('search_bar_full')), - ); - }); - - testWidgets('golden: renders shape sharp correctly', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: ZetaSearchBar( - shape: ZetaWidgetBorder.sharp, - ), - ), - ); - expect(find.byType(ZetaSearchBar), findsOneWidget); - - await expectLater( - find.byType(ZetaSearchBar), - matchesGoldenFile(goldenFile.getFileUri('search_bar_sharp')), - ); - }); - testWidgets('sets initial value correctly', (WidgetTester tester) async { const initialValue = 'Initial value'; @@ -168,6 +109,25 @@ void main() { expect(find.text(updatedValue), findsOneWidget); }); + testWidgets('speech-to-text button visibility', (WidgetTester tester) async { + await tester.pumpWidget( + TestApp( + home: Scaffold( + body: ZetaSearchBar( + showSpeechToText: false, + ), + ), + ), + ); + + await tester.pumpAndSettle(); + expect(find.byIcon(ZetaIcons.search), findsNothing); + expect(find.byIcon(ZetaIcons.microphone), findsNothing); + }); + }); + group('Dimensions Tests', () {}); + group('Styling Tests', () {}); + group('Interaction Tests', () { testWidgets('triggers onChanged callback when text is entered', (WidgetTester tester) async { await tester.pumpWidget( TestApp( @@ -237,22 +197,6 @@ void main() { expect(find.text('Disabled input'), findsNothing); }); - testWidgets('speech-to-text button visibility', (WidgetTester tester) async { - await tester.pumpWidget( - TestApp( - home: Scaffold( - body: ZetaSearchBar( - showSpeechToText: false, - ), - ), - ), - ); - - await tester.pumpAndSettle(); - expect(find.byIcon(ZetaIcons.search), findsNothing); - expect(find.byIcon(ZetaIcons.microphone), findsNothing); - }); - testWidgets('clear button functionality', (WidgetTester tester) async { await tester.pumpWidget( TestApp( @@ -273,20 +217,34 @@ void main() { verify(callbacks.onChange.call('')).called(1); }); - - test('debugFillProperties', () { - final diagnostics = DiagnosticPropertiesBuilder(); - ZetaSearchBar().debugFillProperties(diagnostics); - - expect(diagnostics.finder('size'), 'medium'); - expect(diagnostics.finder('shape'), 'rounded'); - expect(diagnostics.finder('placeholder'), 'null'); - expect(diagnostics.finder('textInputAction'), 'null'); - expect(diagnostics.finder('onSpeechToText'), 'null'); - expect(diagnostics.finder('showSpeechToText'), 'true'); - expect(diagnostics.finder('focusNode'), 'null'); - expect(diagnostics.finder('microphoneSemanticLabel'), 'null'); - expect(diagnostics.finder('clearSemanticLabel'), 'null'); - }); }); + group('Golden Tests', () { + goldenTest(goldenFile, ZetaSearchBar(), ZetaSearchBar, 'search_bar_default'); + goldenTest(goldenFile, ZetaSearchBar(), ZetaSearchBar, 'search_bar_medium'); + goldenTest( + goldenFile, + ZetaSearchBar( + size: ZetaWidgetSize.small, + ), + ZetaSearchBar, + 'search_bar_small', + ); + goldenTest( + goldenFile, + ZetaSearchBar( + shape: ZetaWidgetBorder.full, + ), + ZetaSearchBar, + 'search_bar_full', + ); + goldenTest( + goldenFile, + ZetaSearchBar( + shape: ZetaWidgetBorder.sharp, + ), + ZetaSearchBar, + 'search_bar_sharp', + ); + }); + group('Performance Tests', () {}); } diff --git a/test/src/components/slider/slider_test.dart b/test/src/components/slider/slider_test.dart index 70522376..5c11e203 100644 --- a/test/src/components/slider/slider_test.dart +++ b/test/src/components/slider/slider_test.dart @@ -3,33 +3,66 @@ import 'package:flutter_test/flutter_test.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() { - testWidgets('ZetaSlider min/max values', (WidgetTester tester) async { - const double sliderValue = 0.5; - double? changedValue; - - await tester.pumpWidget( - TestApp( - home: ZetaSlider( - value: sliderValue, - onChange: (value) { - changedValue = value; - }, + const String parentFolder = 'slider'; + + const goldenFile = GoldenFiles(component: parentFolder); + setUpAll(() { + goldenFileComparator = TolerantComparator(goldenFile.uri); + }); + + group('Accessibility Tests', () {}); + + group('Content Tests', () { + // final debugFillProperties = { + // '': '', + // }; + // debugFillPropertiesTest( + // widget, + // debugFillProperties, + // ); + }); + + group('Dimensions Tests', () {}); + + group('Styling Tests', () {}); + + group('Interaction Tests', () { + testWidgets('ZetaSlider min/max values', (WidgetTester tester) async { + const double sliderValue = 0.5; + double? changedValue; + + await tester.pumpWidget( + TestApp( + home: ZetaSlider( + value: sliderValue, + onChange: (value) { + changedValue = value; + }, + ), ), - ), - ); + ); - final slider = tester.widget(find.byType(Slider)); - expect(slider.min, 0.0); - expect(slider.max, 1.0); + final slider = tester.widget(find.byType(Slider)); + expect(slider.min, 0.0); + expect(slider.max, 1.0); - // Drag the slider to the minimum value - await tester.drag(find.byType(Slider), const Offset(-400, 0)); - expect(changedValue, 0.0); + // Drag the slider to the minimum value + await tester.drag(find.byType(Slider), const Offset(-400, 0)); + expect(changedValue, 0.0); - // Drag the slider to the maximum value - await tester.drag(find.byType(Slider), const Offset(400, 0)); - expect(changedValue, 1.0); + // Drag the slider to the maximum value + await tester.drag(find.byType(Slider), const Offset(400, 0)); + expect(changedValue, 1.0); + }); }); + + group('Golden Tests', () { + // goldenTest(goldenFile, widget, widgetType, 'PNG_FILE_NAME'); + }); + + group('Performance Tests', () {}); } diff --git a/test/src/components/stepper input/stepper_input_test.dart b/test/src/components/stepper input/stepper_input_test.dart deleted file mode 100644 index 53c4b4c1..00000000 --- a/test/src/components/stepper input/stepper_input_test.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:zeta_flutter/src/components/stepper_input/stepper_input.dart'; -import 'package:zeta_flutter/zeta_flutter.dart'; - -import '../../../test_utils/test_app.dart'; - -void main() { - testWidgets('ZetaStepperInput increases value when increment button is pressed', (WidgetTester tester) async { - int value = 0; - await tester.pumpWidget( - TestApp( - home: ZetaStepperInput( - value: value, - onChange: (newValue) { - value = newValue; - }, - ), - ), - ); - - expect(value, 0); - - await tester.tap(find.byIcon(ZetaIcons.add_round)); - await tester.pump(); - - expect(value, 1); - }); - - testWidgets('ZetaStepperInput increases value when programatically changed', (WidgetTester tester) async { - int value = 0; - StateSetter? setState; - await tester.pumpWidget( - StatefulBuilder( - builder: (context, setState2) { - setState = setState2; - - return TestApp( - home: ZetaStepperInput( - value: value, - onChange: (newValue) { - value = newValue; - }, - ), - ); - }, - ), - ); - - final ZetaStepperInputState stepperInputState = tester.state(find.byType(ZetaStepperInput)); - - expect(value, stepperInputState.value); - - setState?.call(() { - value = 1; - }); - - await tester.pump(); - - expect(value, stepperInputState.value); - }); -} diff --git a/test/src/components/stepper_input/stepper_input_test.dart b/test/src/components/stepper_input/stepper_input_test.dart new file mode 100644 index 00000000..95b97b06 --- /dev/null +++ b/test/src/components/stepper_input/stepper_input_test.dart @@ -0,0 +1,94 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:zeta_flutter/src/components/stepper_input/stepper_input.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 String parentFolder = 'stepper_input'; + + const goldenFile = GoldenFiles(component: parentFolder); + setUpAll(() { + goldenFileComparator = TolerantComparator(goldenFile.uri); + }); + + group('Accessibility Tests', () {}); + group('Content Tests', () { + // final debugFillProperties = { + // '': '', + // }; + // debugFillPropertiesTest( + // widget, + // debugFillProperties, + // ); + + testWidgets('ZetaStepperInput increases value when programatically changed', (WidgetTester tester) async { + int value = 0; + StateSetter? setState; + await tester.pumpWidget( + StatefulBuilder( + builder: (context, setState2) { + setState = setState2; + + return TestApp( + home: ZetaStepperInput( + value: value, + onChange: (newValue) { + value = newValue; + }, + ), + ); + }, + ), + ); + + final ZetaStepperInputState stepperInputState = tester.state(find.byType(ZetaStepperInput)); + + expect(value, stepperInputState.value); + + setState?.call(() { + value = 1; + }); + + await tester.pump(); + + expect(value, stepperInputState.value); + }); + }); + + group('Dimensions Tests', () {}); + + group('Styling Tests', () {}); + + group('Interaction Tests', () { + testWidgets('ZetaStepperInput increases value when increment button is pressed', (WidgetTester tester) async { + int value = 0; + await tester.pumpWidget( + TestApp( + home: ZetaStepperInput( + value: value, + onChange: (newValue) { + value = newValue; + }, + ), + ), + ); + + expect(value, 0); + + await tester.tap(find.byIcon(ZetaIcons.add_round)); + await tester.pump(); + + expect(value, 1); + }); + }); + + group('Golden Tests', () { + // goldenTest(goldenFile, widget, widgetType, 'PNG_FILE_NAME'); + }); + + group('Performance Tests', () {}); +} diff --git a/test/src/components/tooltip/tooltip_test.dart b/test/src/components/tooltip/tooltip_test.dart index b1c5284f..ef2e6efc 100644 --- a/test/src/components/tooltip/tooltip_test.dart +++ b/test/src/components/tooltip/tooltip_test.dart @@ -15,15 +15,55 @@ import 'tooltip_test.mocks.dart'; MockSpec(), ]) void main() { + const String parentFolder = 'tooltip'; + final mockZeta = MockZeta(); when(mockZeta.radius).thenReturn(const ZetaRadiiAA(primitives: ZetaPrimitivesLight())); - const goldenFile = GoldenFiles(component: 'tooltip'); + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - group('ZetaTooltip Widget Tests', () { + group('Accessibility Tests', () {}); + group('Content Tests', () { + final debugFillProperties = { + 'rounded': 'null', + 'padding': 'EdgeInsets.all(8.0)', + 'color': 'MaterialColor(primary value: Color(0xffffc107))', + 'textStyle': 'TextStyle(inherit: true, size: 9.0)', + 'arrowDirection': 'down', + 'maxWidth': '170.0', + }; + debugFillPropertiesTest( + const ZetaTooltip( + padding: EdgeInsets.all(8), + color: Colors.amber, + textStyle: TextStyle(fontSize: 9), + maxWidth: 170, + child: Text('Rounded tooltip'), + ), + debugFillProperties, + ); + + testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { + final diagnostics = DiagnosticPropertiesBuilder(); + const ZetaTooltip( + padding: EdgeInsets.all(8), + color: Colors.amber, + textStyle: TextStyle(fontSize: 9), + maxWidth: 170, + child: Text('Rounded tooltip'), + ).debugFillProperties(diagnostics); + + expect(diagnostics.finder('rounded'), 'null'); + expect(diagnostics.finder('padding'), 'EdgeInsets.all(8.0)'); + expect(diagnostics.finder('color').toLowerCase(), contains(Colors.amber.hexCode.toLowerCase())); + expect(diagnostics.finder('textStyle'), contains('size: 9.0')); + expect(diagnostics.finder('arrowDirection'), 'down'); + expect(diagnostics.finder('maxWidth'), '170.0'); + }); + testWidgets('renders with default properties', (WidgetTester tester) async { await tester.pumpWidget( const TestApp( @@ -38,13 +78,13 @@ void main() { expect(find.text('Tooltip text'), findsOneWidget); expect(find.byType(ZetaTooltip), findsOneWidget); }); - - testWidgets('renders with custom color and padding', (WidgetTester tester) async { + }); + group('Dimensions Tests', () { + testWidgets('renders with custom padding', (WidgetTester tester) async { await tester.pumpWidget( const TestApp( home: Scaffold( body: ZetaTooltip( - color: Colors.red, padding: EdgeInsets.all(20), child: Text('Tooltip text'), ), @@ -52,23 +92,38 @@ void main() { ), ); - final tooltipBox = tester.widget( + final padding = tester.widget( find.descendant( of: find.byType(ZetaTooltip), - matching: find.byType(DecoratedBox), + matching: find.byType(Padding), ), ); - expect((tooltipBox.decoration as BoxDecoration).color, Colors.red); + expect(padding.padding, const EdgeInsets.all(20)); + }); + }); + group('Styling Tests', () { + testWidgets('renders with custom color', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: Scaffold( + body: ZetaTooltip( + color: Colors.red, + padding: EdgeInsets.all(20), + child: Text('Tooltip text'), + ), + ), + ), + ); - final padding = tester.widget( + final tooltipBox = tester.widget( find.descendant( of: find.byType(ZetaTooltip), - matching: find.byType(Padding), + matching: find.byType(DecoratedBox), ), ); - expect(padding.padding, const EdgeInsets.all(20)); + expect((tooltipBox.decoration as BoxDecoration).color, Colors.red); }); testWidgets('renders with custom text style', (WidgetTester tester) async { @@ -99,89 +154,6 @@ void main() { expect(textSpan.style?.color, Colors.blue); }); - testWidgets('renders with arrow correctly in up direction', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: Scaffold( - body: ZetaTooltip( - arrowDirection: ZetaTooltipArrowDirection.up, - child: Text('Tooltip up'), - ), - ), - ), - ); - - expect(find.text('Tooltip up'), findsOneWidget); - - // Verifying the CustomPaint with different arrow directions. - await expectLater( - find.byType(ZetaTooltip), - matchesGoldenFile(goldenFile.getFileUri('arrow_up')), - ); - }); - - testWidgets('renders with arrow correctly in down direction', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: Scaffold( - body: ZetaTooltip( - child: Text('Tooltip down'), - ), - ), - ), - ); - - expect(find.text('Tooltip down'), findsOneWidget); - - // Verifying the CustomPaint with different arrow directions. - await expectLater( - find.byType(ZetaTooltip), - matchesGoldenFile(goldenFile.getFileUri('arrow_down')), - ); - }); - - testWidgets('renders with arrow correctly in left direction', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: Scaffold( - body: ZetaTooltip( - arrowDirection: ZetaTooltipArrowDirection.left, - child: Text('Tooltip left'), - ), - ), - ), - ); - - expect(find.text('Tooltip left'), findsOneWidget); - - // Verifying the CustomPaint with different arrow directions. - await expectLater( - find.byType(ZetaTooltip), - matchesGoldenFile(goldenFile.getFileUri('arrow_left')), - ); - }); - - testWidgets('renders with arrow correctly in right direction', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: Scaffold( - body: ZetaTooltip( - arrowDirection: ZetaTooltipArrowDirection.right, - child: Text('Tooltip right'), - ), - ), - ), - ); - - expect(find.text('Tooltip right'), findsOneWidget); - - // Verifying the CustomPaint with different arrow directions. - await expectLater( - find.byType(ZetaTooltip), - matchesGoldenFile(goldenFile.getFileUri('arrow_right')), - ); - }); - testWidgets('renders with rounded and sharp corners', (WidgetTester tester) async { await tester.pumpWidget( const TestApp( @@ -221,23 +193,52 @@ void main() { expect((roundedTooltipBox.decoration as BoxDecoration).borderRadius, mockZeta.radius.minimal); expect((sharpTooltipBox.decoration as BoxDecoration).borderRadius, null); }); - - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - const ZetaTooltip( - padding: EdgeInsets.all(8), - color: Colors.amber, - textStyle: TextStyle(fontSize: 9), - maxWidth: 170, - child: Text('Rounded tooltip'), - ).debugFillProperties(diagnostics); - - expect(diagnostics.finder('rounded'), 'null'); - expect(diagnostics.finder('padding'), 'EdgeInsets.all(8.0)'); - expect(diagnostics.finder('color').toLowerCase(), contains(Colors.amber.hexCode.toLowerCase())); - expect(diagnostics.finder('textStyle'), contains('size: 9.0')); - expect(diagnostics.finder('arrowDirection'), 'down'); - expect(diagnostics.finder('maxWidth'), '170.0'); - }); }); + group('Interaction Tests', () {}); + group('Golden Tests', () { + goldenTest( + goldenFile, + const Scaffold( + body: ZetaTooltip( + arrowDirection: ZetaTooltipArrowDirection.up, + child: Text('Tooltip up'), + ), + ), + ZetaTooltip, + 'arrow_up', + ); + goldenTest( + goldenFile, + const Scaffold( + body: ZetaTooltip( + child: Text('Tooltip down'), + ), + ), + ZetaTooltip, + 'arrow_down', + ); + goldenTest( + goldenFile, + const Scaffold( + body: ZetaTooltip( + arrowDirection: ZetaTooltipArrowDirection.left, + child: Text('Tooltip left'), + ), + ), + ZetaTooltip, + 'arrow_left', + ); + goldenTest( + goldenFile, + const Scaffold( + body: ZetaTooltip( + arrowDirection: ZetaTooltipArrowDirection.right, + child: Text('Tooltip right'), + ), + ), + ZetaTooltip, + 'arrow_right', + ); + }); + group('Performance Tests', () {}); } diff --git a/test/test_utils/utils.dart b/test/test_utils/utils.dart index 1bfb59f1..5117d045 100644 --- a/test/test_utils/utils.dart +++ b/test/test_utils/utils.dart @@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:path/path.dart'; +import '../test_utils/test_app.dart'; extension Util on DiagnosticPropertiesBuilder { dynamic finder(String finder) { @@ -30,6 +31,77 @@ class GoldenFiles { } } +void goldenTest( + GoldenFiles goldenFile, + Widget widget, + Type widgetType, + String fileName, { + ThemeMode themeMode = ThemeMode.system, + Size? screenSize, + bool? rounded, +}) { + testWidgets('$fileName golden', (WidgetTester tester) async { + await tester.pumpWidget( + TestApp( + screenSize: screenSize, + themeMode: themeMode, + rounded: rounded, + home: widget, + ), + ); + + await expectLater( + find.byType(widgetType), + matchesGoldenFile(goldenFile.getFileUri(fileName)), + ); + }); +} + +void goldenTestWithCallbacks( + GoldenFiles goldenFile, + Widget widget, + Type widgetType, + String fileName, { + Future Function(WidgetTester)? before, + Future Function(WidgetTester)? after, + bool darkMode = false, + Size? screenSize, +}) { + testWidgets('$fileName golden', (WidgetTester tester) async { + if (before != null) { + await before(tester); + } + + await tester.pumpWidget( + TestApp( + screenSize: screenSize, + themeMode: darkMode ? ThemeMode.dark : ThemeMode.light, + home: widget, + ), + ); + + if (after != null) { + await after(tester); + } + + await expectLater( + find.byType(widgetType), + matchesGoldenFile(goldenFile.getFileUri(fileName)), + ); + }); +} + BuildContext getBuildContext(WidgetTester tester, Type type) { return tester.element(find.byType(type)); } + +void debugFillPropertiesTest(Widget widget, Map properties) { + testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { + final diagnostics = DiagnosticPropertiesBuilder(); + widget.debugFillProperties(diagnostics); + + properties.forEach((key, value) { + expect(diagnostics.finder(key), value); + }); + }); +}