Skip to content

Commit

Permalink
Added more tests for reordering tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Nov 12, 2023
1 parent 00d907e commit 422c0ce
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
59 changes: 59 additions & 0 deletions test/pages/dashboard_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,65 @@ void main() {
expect(find.byType(DashboardGrid, skipOffstage: false), findsNWidgets(1));
});

testWidgets('Reordering tabs', (widgetTester) async {
FlutterError.onError = ignoreOverflowErrors;
setupMockOfflineNT4();

await widgetTester.pumpWidget(
MaterialApp(
home: DashboardPage(
connectionStream: Stream.value(false),
preferences: preferences,
version: '0.0.0.0',
),
),
);

await widgetTester.pumpAndSettle();

expect(find.byType(DashboardGrid, skipOffstage: false), findsNWidgets(2));

final editableTabBar = find.byType(EditableTabBar);

expect(editableTabBar, findsOneWidget);

final tabLeftButton =
find.descendant(of: editableTabBar, matching: find.byIcon(Icons.west));
final tabRightButton =
find.descendant(of: editableTabBar, matching: find.byIcon(Icons.east));

expect(tabLeftButton, findsOneWidget);
expect(tabRightButton, findsOneWidget);

editableTabBarWidget() =>
(editableTabBar.evaluate().first.widget as EditableTabBar);

expect(editableTabBarWidget().currentIndex, 0);

await widgetTester.tap(tabLeftButton);
await widgetTester.pumpAndSettle();

expect(editableTabBarWidget().currentIndex, 0,
reason: 'Tab index should not change since index is 0');

await widgetTester.tap(tabRightButton);
await widgetTester.pumpAndSettle();

expect(editableTabBarWidget().currentIndex, 1);

await widgetTester.tap(tabRightButton);
await widgetTester.pumpAndSettle();

expect(editableTabBarWidget().currentIndex, 1,
reason:
'Tab index should not change since index is equal to number of tabs');

await widgetTester.tap(tabLeftButton);
await widgetTester.pumpAndSettle();

expect(editableTabBarWidget().currentIndex, 0);
});

testWidgets('Renaming tab', (widgetTester) async {
FlutterError.onError = ignoreOverflowErrors;
setupMockOfflineNT4();
Expand Down
8 changes: 1 addition & 7 deletions test/widgets/editable_tab_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ void main() {
DashboardGrid(),
DashboardGrid(),
],
newDashboardGridBuilder: () => DashboardGrid(key: GlobalKey()),
onTabCreate: (tab) {},
onTabDestroy: (index) {},
onTabMoveLeft: () {},
Expand Down Expand Up @@ -89,7 +88,6 @@ void main() {
DashboardGrid(),
DashboardGrid(),
],
newDashboardGridBuilder: () => DashboardGrid(key: GlobalKey()),
onTabCreate: (tab) {
tabBarFunctions.onTabCreate();
},
Expand Down Expand Up @@ -141,7 +139,6 @@ void main() {
DashboardGrid(),
DashboardGrid(),
],
newDashboardGridBuilder: () => DashboardGrid(key: GlobalKey()),
onTabCreate: (tab) {
tabBarFunctions.onTabCreate();
},
Expand Down Expand Up @@ -177,7 +174,7 @@ void main() {
verify(tabBarFunctions.onTabDestroy()).called(1);
});

testWidgets('Move tabs', (widgetTester) async {
testWidgets('Reordering tabs', (widgetTester) async {
FlutterError.onError = ignoreOverflowErrors;

await widgetTester.pumpWidget(
Expand All @@ -193,7 +190,6 @@ void main() {
DashboardGrid(),
DashboardGrid(),
],
newDashboardGridBuilder: () => DashboardGrid(key: GlobalKey()),
onTabCreate: (tab) {
tabBarFunctions.onTabCreate();
},
Expand Down Expand Up @@ -258,7 +254,6 @@ void main() {
DashboardGrid(),
DashboardGrid(),
],
newDashboardGridBuilder: () => DashboardGrid(key: GlobalKey()),
onTabCreate: (tab) {
tabBarFunctions.onTabCreate();
},
Expand Down Expand Up @@ -335,7 +330,6 @@ void main() {
DashboardGrid(),
DashboardGrid(),
],
newDashboardGridBuilder: () => DashboardGrid(key: GlobalKey()),
onTabCreate: (tab) {
tabBarFunctions.onTabCreate();
},
Expand Down

0 comments on commit 422c0ce

Please sign in to comment.