Skip to content

Commit

Permalink
test: breadcrumb label and icon default colors
Browse files Browse the repository at this point in the history
test: breadcrumb items are spaced equally
  • Loading branch information
DE7924 committed Nov 15, 2024
1 parent cd843a6 commit bdcbe67
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lib/src/components/breadcrumb/breadcrumb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class _ZetaBreadcrumbsState extends State<ZetaBreadcrumb> {
ZetaIcons.chevron_right,
size: Zeta.of(context).spacing.xl,
rounded: rounded,
color: Zeta.of(context).colors.textSubtle,
),
SizedBox(width: Zeta.of(context).spacing.small),
],
Expand Down Expand Up @@ -351,7 +352,11 @@ class _TruncatedItemState extends State<_TruncatedItem> {
Row(
children: [
SizedBox(width: Zeta.of(context).spacing.small),
ZetaIcon(ZetaIcons.chevron_right, size: Zeta.of(context).spacing.xl),
ZetaIcon(
ZetaIcons.chevron_right,
size: Zeta.of(context).spacing.xl,
color: Zeta.of(context).colors.textSubtle,
),
SizedBox(width: Zeta.of(context).spacing.small),
],
),
Expand Down
72 changes: 68 additions & 4 deletions test/src/components/breadcrumb/breadcrumb_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
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';
Expand Down Expand Up @@ -141,10 +138,77 @@ void main() {

group('Dimensions Tests', () {
// each item is equally spaced
testWidgets('ZetaBreadcrumb items are equally spaced', (tester) async {
await tester.pumpWidget(
TestApp(
home: ZetaBreadcrumb(
maxItemsShown: 7,
children: [
ZetaBreadcrumbItem(label: 'Item 0', onPressed: () {}),
ZetaBreadcrumbItem(label: 'Item 1', onPressed: () {}),
ZetaBreadcrumbItem(label: 'Item 2', onPressed: () {}),
ZetaBreadcrumbItem(label: 'Item 3', onPressed: () {}),
ZetaBreadcrumbItem(label: 'Item 4', onPressed: () {}),
ZetaBreadcrumbItem(label: 'Item 5', onPressed: () {}),
ZetaBreadcrumbItem(label: 'Item 6', onPressed: () {}),
],
),
),
);

final itemFinder = find.byType(ZetaBreadcrumbItem);

final List<double> itemPositions = [];
for (int i = 0; i < children.length; i++) {
expect(itemFinder.at(i), findsOneWidget);
itemPositions.add(tester.getTopLeft(itemFinder.at(i)).dx);
}

final double distance = itemPositions[1] - itemPositions[0];
for (int i = 1; i < itemPositions.length; i++) {
expect(itemPositions[i] - itemPositions[i - 1], distance);
}
});
});

group('Styling Tests', () {
// label and icon colors are correct
testWidgets('ZetaBreadcrumb label and icon colors are correct', (tester) async {
await tester.pumpWidget(
TestApp(
home: ZetaBreadcrumb(
maxItemsShown: 7,
children: children,
),
),
);
final context = getBuildContext(tester, ZetaBreadcrumb);
final colors = Zeta.of(context).colors;

final labelFinder = find.byType(Text);
final iconFinder = find.byType(ZetaIcon);

for (int i = 0; i < children.length; i++) {
if (i == children.length - 1) {
expect(
(tester.firstWidget(labelFinder.at(i)) as Text).style?.color,
colors.black,
);
} else {
expect(
(tester.firstWidget(labelFinder.at(i)) as Text).style?.color,
colors.textSubtle,
);
}
}

for (int i = 0; i < iconFinder.evaluate().length; i++) {
expect(
(tester.firstWidget(iconFinder.at(i)) as ZetaIcon).color,
colors.textSubtle,
);
}
});

// label font styles are correct
// icon sizes are correct

Expand Down

0 comments on commit bdcbe67

Please sign in to comment.