Skip to content

Commit

Permalink
Add tab switching to navbar style test
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3rndt committed Nov 1, 2024
1 parent 01cd3ae commit ea47e31
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 40 deletions.
44 changes: 19 additions & 25 deletions test/nav_bar_styles_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,31 @@ import "package:flutter/material.dart";
import "package:flutter_test/flutter_test.dart";
import "package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart";

import "persistent_tab_view_test.dart";

typedef StyleBuilder = Widget Function(NavBarConfig navBarConfig);

PersistentTabConfig tabConfig(int id) => PersistentTabConfig(
screen: Text("Screen$id"),
item: ItemConfig(title: "Item$id", icon: const Icon(Icons.add)),
);
Future<void> testStyle(WidgetTester tester, StyleBuilder builder) async {
await tester.pumpWidget(
wrapTabView(
(context) => PersistentTabView(
tabs: List.generate(3, (id) => tabConfig(id, defaultScreen(id))),
navBarBuilder: (navBarConfig) => builder(navBarConfig),
),
),
);

void main() {
Widget wrapTabView(WidgetBuilder builder) => MaterialApp(
home: Builder(
builder: (context) => builder(context),
),
);
await tester.pumpAndSettle();

Future<void> testStyle(WidgetTester tester, StyleBuilder builder) async {
await tester.pumpWidget(
wrapTabView(
(context) => PersistentTabView(
tabs: [1, 2, 3].map(tabConfig).toList(),
navBarBuilder: (navBarConfig) => builder(navBarConfig),
),
),
);
await tester.pumpAndSettle();
expect(
find.byType(DecoratedNavBar).hitTestable(at: Alignment.centerLeft),
findsOneWidget,
);

expect(
find.byType(DecoratedNavBar).hitTestable(at: Alignment.centerLeft),
findsOneWidget,
);
}
await tapItem(tester, 1);
}

void main() {
testWidgets("builds every style", (tester) async {
await testStyle(
tester,
Expand Down
34 changes: 19 additions & 15 deletions test/persistent_tab_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ PersistentTabConfig tabConfig(
PersistentTabConfig(
screen: screen,
scrollController: scrollController,
item: ItemConfig(title: "Item$id", icon: const Icon(Icons.add)),
item: ItemConfig(
title: "Item$id",
icon: Icon(key: Key("Item$id"), Icons.add),
),
);

Widget defaultScreen(
Expand Down Expand Up @@ -82,7 +85,7 @@ List<PersistentRouterTabConfig> routerTabs([
scrollController:
scrollControllers != null ? scrollControllers[id] : null,
item: ItemConfig(
icon: const Icon(Icons.add),
icon: Icon(key: Key("Item$id"), Icons.add),
title: "Item$id",
),
),
Expand All @@ -101,7 +104,7 @@ Future<void> tapElevatedButton(WidgetTester tester) async {
}

Future<void> tapItem(WidgetTester tester, int id) async {
await tester.tap(find.text("Item$id"));
await tester.tap(find.byKey(Key("Item$id")));
await tester.pumpAndSettle();
}

Expand Down Expand Up @@ -222,7 +225,7 @@ void main() {
screen: defaultScreen(0),
item: ItemConfig(
title: "Item0",
icon: const Icon(Icons.add),
icon: const Icon(key: Key("Item0"), Icons.add),
),
),
PersistentTabConfig.noScreen(
Expand All @@ -231,7 +234,7 @@ void main() {
},
item: ItemConfig(
title: "Item1",
icon: const Icon(Icons.add),
icon: const Icon(key: Key("Item1"), Icons.add),
),
),
],
Expand Down Expand Up @@ -1583,7 +1586,8 @@ void main() {

expect(keys[0].currentState!.controller.value, equals(1));
expect(keys[1].currentState!.controller.value, equals(0));
await tapItem(tester, 1);
await tester.tap(find.text("Item1"));
await tester.pumpAndSettle();

expect(keys[0].currentState!.controller.value, equals(0));
expect(keys[1].currentState!.controller.value, equals(1));
Expand All @@ -1605,7 +1609,7 @@ void main() {
),
item: ItemConfig(
title: "Item$id",
icon: const Icon(Icons.add),
icon: Icon(key: Key("Item$id"), Icons.add),
),
navigatorConfig: NavigatorConfig(
routes: {
Expand Down Expand Up @@ -1646,7 +1650,7 @@ void main() {
),
item: ItemConfig(
title: "Item$id",
icon: const Icon(Icons.add),
icon: Icon(key: Key("Item$id"), Icons.add),
),
navigatorConfig: NavigatorConfig(
onGenerateRoute: (settings) => MaterialPageRoute(
Expand Down Expand Up @@ -1687,7 +1691,7 @@ void main() {
),
item: ItemConfig(
title: "Item$id",
icon: const Icon(Icons.add),
icon: Icon(key: Key("Item$id"), Icons.add),
),
navigatorConfig: NavigatorConfig(
onUnknownRoute: (settings) => MaterialPageRoute(
Expand Down Expand Up @@ -1727,7 +1731,7 @@ void main() {
),
item: ItemConfig(
title: "Item$id",
icon: const Icon(Icons.add),
icon: Icon(key: Key("Item$id"), Icons.add),
),
),
),
Expand Down Expand Up @@ -1758,7 +1762,7 @@ void main() {
),
item: ItemConfig(
title: "Item$id",
icon: const Icon(Icons.add),
icon: Icon(key: Key("Item$id"), Icons.add),
),
navigatorConfig: NavigatorConfig(
onUnknownRoute: (settings) => null,
Expand Down Expand Up @@ -1796,7 +1800,7 @@ void main() {
),
item: ItemConfig(
title: "Item$id",
icon: const Icon(Icons.add),
icon: Icon(key: Key("Item$id"), Icons.add),
),
),
),
Expand Down Expand Up @@ -1835,7 +1839,7 @@ void main() {
),
item: ItemConfig(
title: "Item$id",
icon: const Icon(Icons.add),
icon: Icon(key: Key("Item$id"), Icons.add),
),
),
),
Expand Down Expand Up @@ -1870,7 +1874,7 @@ void main() {
),
item: ItemConfig(
title: "Item$id",
icon: const Icon(Icons.add),
icon: Icon(key: Key("Item$id"), Icons.add),
),
),
),
Expand Down Expand Up @@ -1902,7 +1906,7 @@ void main() {
),
item: ItemConfig(
title: "Item$id",
icon: const Icon(Icons.add),
icon: Icon(key: Key("Item$id"), Icons.add),
),
),
),
Expand Down

0 comments on commit ea47e31

Please sign in to comment.