diff --git a/test/src/components/chips/chip_test.dart b/test/src/components/chips/chip_test.dart index 0d1eb2d1..fa97e52c 100644 --- a/test/src/components/chips/chip_test.dart +++ b/test/src/components/chips/chip_test.dart @@ -1,11 +1,33 @@ +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() { - group('ZetaChip', () { + const String componentName = 'ZetaChip'; + const String parentFolder = 'chips'; + + const goldenFile = GoldenFiles(component: parentFolder); + setUpAll(() { + goldenFileComparator = TolerantComparator(goldenFile.uri); + }); + + group('$componentName Accessibility Tests', () {}); + group('$componentName 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 +35,10 @@ void main() { expect(find.text('Test Chip'), findsOneWidget); }); - + }); + group('$componentName Dimensions Tests', () {}); + group('$componentName Styling Tests', () {}); + group('$componentName Interaction Tests', () { testWidgets('triggers onTap callback when tapped', (WidgetTester tester) async { bool tapped = false; @@ -72,30 +97,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('$componentName Golden Tests', () { + // goldenTest(goldenFile, widget, widgetType, 'PNG_FILE_NAME'); }); + group('$componentName 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..d3ae6d1d 100644 --- a/test/src/components/comms_button/comms_button_test.dart +++ b/test/src/components/comms_button/comms_button_test.dart @@ -1,19 +1,96 @@ -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 componentName = 'ZetaCommsButton'; + const String parentFolder = 'comms_button'; + const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); - group('ZetaCommsButton Tests', () { + group('$componentName 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('$componentName 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 +99,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 +205,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('$componentName Dimensions Tests', () {}); + group('$componentName Styling Tests', () {}); + group('$componentName Interaction Tests', () {}); + group('$componentName 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('$componentName 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..33bf66fe 100644 --- a/test/src/components/dialpad/dialpad_test.dart +++ b/test/src/components/dialpad/dialpad_test.dart @@ -25,6 +25,10 @@ void main() { await tester.pumpWidget( TestApp( + // before: (tester) async { + // tester.view.devicePixelRatio = 1.0; + // tester.view.physicalSize = const Size(481, 480); + // }, screenSize: const Size(1000, 1000), home: ZetaDialPad( onNumber: (value) => number += value,