Skip to content

Commit

Permalink
tests: organised tests for chip and comms button
Browse files Browse the repository at this point in the history
  • Loading branch information
DE7924 committed Oct 14, 2024
1 parent 2580887 commit ec0e710
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 121 deletions.
72 changes: 50 additions & 22 deletions test/src/components/chips/chip_test.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
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')),
);

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;

Expand Down Expand Up @@ -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', () {});
}
194 changes: 95 additions & 99 deletions test/src/components/comms_button/comms_button_test.dart
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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 {
Expand Down Expand Up @@ -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', () {});
}
Binary file not shown.
4 changes: 4 additions & 0 deletions test/src/components/dialpad/dialpad_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ec0e710

Please sign in to comment.