Skip to content

Commit

Permalink
fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IoanaAlexandru committed Sep 16, 2020
1 parent c9c0688 commit e6c697a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/navigation/bottom_navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class _AppBottomNavigationBarState extends State<AppBottomNavigationBar>
HomePage(key: PageStorageKey('Home')),
ClassesPage(key: PageStorageKey('Classes')),
PortalPage(key: PageStorageKey('Portal')),
ProfilePage(key: PageStorageKey('Profile')),
PeoplePage(key: PageStorageKey('People')),
ProfilePage(key: PageStorageKey('Profile')),
];
tabController = TabController(vsync: this, length: tabs.length);
}
Expand Down
17 changes: 17 additions & 0 deletions test/authentication_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'package:acs_upb_mobile/main.dart';
import 'package:acs_upb_mobile/pages/filter/model/filter.dart';
import 'package:acs_upb_mobile/pages/filter/service/filter_provider.dart';
import 'package:acs_upb_mobile/pages/home/home_page.dart';
import 'package:acs_upb_mobile/pages/people/service/person_provider.dart';
import 'package:acs_upb_mobile/pages/portal/service/website_provider.dart';
import 'package:acs_upb_mobile/pages/profile/profile_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
Expand All @@ -21,10 +23,13 @@ class MockFilterProvider extends Mock implements FilterProvider {}

class MockWebsiteProvider extends Mock implements WebsiteProvider {}

class MockPersonProvider extends Mock implements PersonProvider {}

void main() {
AuthProvider mockAuthProvider;
WebsiteProvider mockWebsiteProvider;
FilterProvider mockFilterProvider;
PersonProvider mockPersonProvider;

setUp(() async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -57,6 +62,12 @@ void main() {
.thenAnswer((_) => Future.value(Filter(localizedLevelNames: [
{'en': 'Level', 'ro': 'Nivel'}
], root: FilterNode(name: 'root'))));

mockPersonProvider = MockPersonProvider();
// ignore: invalid_use_of_protected_member
when(mockPersonProvider.hasListeners).thenReturn(false);
when(mockPersonProvider.fetchPeople(context: anyNamed('context')))
.thenAnswer((_) => Future.value([]));
});

group('Login', () {
Expand Down Expand Up @@ -376,6 +387,8 @@ void main() {
create: (_) => mockFilterProvider),
ChangeNotifierProvider<WebsiteProvider>(
create: (_) => mockWebsiteProvider),
ChangeNotifierProvider<PersonProvider>(
create: (_) => mockPersonProvider),
], child: MyApp(navigationObservers: [mockObserver])));
await tester.pumpAndSettle();

Expand All @@ -386,6 +399,7 @@ void main() {
await tester.tap(find.byIcon(Icons.person));
await tester.pumpAndSettle();

expect(find.byType(ProfilePage), findsOneWidget);
expect(find.text('Anonymous'), findsOneWidget);

// Press log in button
Expand All @@ -407,6 +421,8 @@ void main() {
create: (_) => mockFilterProvider),
ChangeNotifierProvider<WebsiteProvider>(
create: (_) => mockWebsiteProvider),
ChangeNotifierProvider<PersonProvider>(
create: (_) => mockPersonProvider),
], child: MyApp(navigationObservers: [mockObserver])));
await tester.pumpAndSettle();

Expand All @@ -417,6 +433,7 @@ void main() {
await tester.tap(find.byIcon(Icons.person));
await tester.pumpAndSettle();

expect(find.byType(ProfilePage), findsOneWidget);
expect(find.text('John Doe'), findsOneWidget);

// Press log out button
Expand Down
14 changes: 8 additions & 6 deletions test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,16 @@ void main() {
testWidgets('${size.width}x${size.height}', (WidgetTester tester) async {
await binding.setSurfaceSize(size);

await tester.pumpWidget(buildApp());
await tester.pumpAndSettle();
mockNetworkImagesFor(() async {
await tester.pumpWidget(buildApp());
await tester.pumpAndSettle();

// Open profile
await tester.tap(find.byIcon(Icons.person));
await tester.pumpAndSettle();
// Open profile
await tester.tap(find.byIcon(Icons.person));
await tester.pumpAndSettle();

expect(find.byType(ProfilePage), findsNWidgets(1));
expect(find.byType(ProfilePage), findsNWidgets(1));
});
});
}
});
Expand Down

0 comments on commit e6c697a

Please sign in to comment.