Skip to content

Commit

Permalink
feat: Setup tests (#141)
Browse files Browse the repository at this point in the history
## Description
- Integration - interaction between different components of the app.

- Unit - individual functions and methods in isolation (will only cover
the Bloc).

- Widget - user interface components of the app.

- To make the process easier for other developers, we would like you to
create reusable components for testing which can easily be used by the
rest of the team.

## Type of Change

<!--- Put an `x` in all the boxes that apply: -->

- [x] ✨ New feature (non-breaking change which adds functionality)
- [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
- [ ] ❌ Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] 🧹 Code refactor
- [ ] ✅ Build configuration change
- [ ] 📝 Documentation
- [ ] 🗑️ Chore


## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read and ran all relevant commands as specififed in the Running
Tests section of the [Contributor Guide].
- [ ] The title of the PR follows the [Conventional Commits] guideline
- [ ] My local branch follows the naming standards in the [Deepsource
Branch Naming Convention] or [Biodiversity Branch Naming Convention]
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated `pubspec.yaml` with an appropriate new version according
to the [pub versioning philosophy],
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] All existing and new tests are passing.


[Contributor Guide]:
https://github.com/FlutterPlaza/.github/blob/main/CONTRIBUTING.md
[Conventional Commits]:
https://www.conventionalcommits.org/en/v1.0.0-beta.4/
[pub versioning philosophy]: https://dart.dev/tools/pub/versioning
[Biodiversity Branch Naming Convention]: https://bit.ly/3DyYSwM
[Deepsource Branch Naming Convention]: https://bit.ly/3Y08Gs4
  • Loading branch information
jeffrey0606 authored Mar 27, 2023
2 parents bfd5fd9 + 8c70d94 commit 7ce6fab
Show file tree
Hide file tree
Showing 27 changed files with 1,252 additions and 172 deletions.
12 changes: 12 additions & 0 deletions integration_test/app_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

import 'bottom_nav_bar_test.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('Development App', () {
bottomNavBarTest();
});
}
85 changes: 85 additions & 0 deletions integration_test/bottom_nav_bar_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fpb/core/domain/user.dart';
import 'package:fpb/core/shared/helpers/value_injector.dart';
import 'package:fpb/home/home_screen.dart';
import 'package:fpb/home/view/budget_screen.dart';
import 'package:fpb/home/view/dashboard.dart';
import 'package:fpb/home/view/home_container.dart';
import 'package:fpb/home/view/widgets/bottom_nav_bar.dart';
import 'package:fpb/savings/view/savings_page.dart';

import '../test/helpers/helpers.dart';

void bottomNavBarTest() {
late MockCached cached;
late MockIFacebookRepositoryFacade mockIFacebookRepositoryFacade;
late MockIGoogleRepositoryFacade mockIGoogleRepositoryFacade;
late MockIAuthFacade mockIAuthFacade;

setUp(() {
cached = MockCached();
mockIAuthFacade = MockIAuthFacade();
mockIFacebookRepositoryFacade = MockIFacebookRepositoryFacade();
mockIGoogleRepositoryFacade = MockIGoogleRepositoryFacade();
});

testWidgets('renders home bottom nav bar buttons', (tester) async {
arrangeAuthRepositoryReturnsStreamWithUser(mockIAuthFacade);
arrangeAuthRepositoryReturnsCurrentUser(mockIAuthFacade);
arrangeCachedReturnsLastView(cached, 0);

await tester.pumpApp(
ValueInjector<User>(
value: testUser,
child: HomeBody(
user: testUser,
),
),
mockCachedForHomeBloc: cached,
mockIAuthFacadeForAuthBloc: mockIAuthFacade,
);

await tester.pumpAndSettle();

// await tester.pump();

expect(find.byType(HomeContainer), findsOneWidget);
expect(find.byType(BottomNavBar), findsOneWidget);
expect(find.byType(DashBoard), findsOneWidget);

await tester.tap(
find.byKey(
Key("BNB-savings-page-button"),
),
);

await tester.pumpAndSettle();

expect(find.byType(SavingsPage), findsOneWidget);

await tester.tap(
find.byKey(
Key("BNB-budget-page-button"),
),
);

await tester.pumpAndSettle();

expect(find.byType(BudgetScreen), findsOneWidget);

// await tester.tap(
// find.byKey(
// Key("BNB-userSearch-page-button"),
// ),
// );

// await tester.pumpAndSettle();

// expect(find.byType(UserSearchScreen), findsOneWidget);

await Future.delayed(
const Duration(seconds: 3),
);
});
}
3 changes: 1 addition & 2 deletions lib/app/view/app.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fpb/core/presentation/theming/themes/theme.dart';

import 'package:fpb/authentication_mock_without_backend/application/bloc/authentication_bloc.dart';
import 'package:fpb/authentication_with_firebase/application/bloc/auth_bloc.dart';
import 'package:fpb/core/application/internet_and_time_bloc/internet_and_time_bloc.dart';
import 'package:fpb/core/presentation/theming/themes/theme.dart';
import 'package:fpb/injection.dart';
import 'package:fpb/l10n/l10n.dart';
import 'package:fpb/router/app_route.gr.dart';
Expand Down
34 changes: 24 additions & 10 deletions lib/home/application/home_view_bloc/home_view_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// ignore_for_file: inference_failure_on_untyped_parameter

import 'package:bloc/bloc.dart';
import 'package:fpb/core/settings/app_settings_helper.dart';
import 'package:fpb/core/settings/cached.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';

part 'home_view_bloc.freezed.dart';
part 'home_view_event.dart';
part 'home_view_state.dart';
part 'home_view_bloc.freezed.dart';

@injectable
class HomeViewBloc extends Bloc<HomeViewEvent, HomeViewState> {
final AppSettingsHelper _appSettingsHelper;
HomeViewBloc(this._appSettingsHelper) : super(HomeViewState.home()) {
final Cached _cached;
HomeViewBloc(this._cached) : super(HomeViewState.home()) {
on<_HomeE>(_home);
on<_SavingsE>(_savings);
on<_QuickCashE>(_quickCash);
Expand All @@ -21,33 +21,41 @@ class HomeViewBloc extends Bloc<HomeViewEvent, HomeViewState> {
on<_SearchE>(_search);
}

int? lastView;

void _search(event, Emitter<HomeViewState> emit) {
emit(HomeViewState.search());
_appSettingsHelper.appCache.setLastView = 4;
lastView = 4;
}

void _home(event, Emitter<HomeViewState> emit) {
emit(HomeViewState.home());
_appSettingsHelper.appCache.setLastView = 0;
lastView = 0;
}

void _savings(event, Emitter<HomeViewState> emit) {
emit(HomeViewState.savings());
_appSettingsHelper.appCache.setLastView = 1;
lastView = 1;
}

void _quickCash(event, Emitter<HomeViewState> emit) {
emit(HomeViewState.quickCash());
_appSettingsHelper.appCache.setLastView = 2;
lastView = 2;
}

void _budget(event, Emitter<HomeViewState> emit) {
emit(HomeViewState.budget());
_appSettingsHelper.appCache.setLastView = 3;
lastView = 3;
}

void _lastState(event, Emitter<HomeViewState> emit) {
final lastState = _appSettingsHelper.appCache.getLastView;
late int lastState;
if (lastView != null) {
lastState = lastView!;
} else {
lastState = _cached.getLastView;
}

switch (lastState) {
case 0:
_home(event, emit);
Expand All @@ -69,4 +77,10 @@ class HomeViewBloc extends Bloc<HomeViewEvent, HomeViewState> {
break;
}
}

@override
Future<void> close() {
if (lastView != null) _cached.setLastView = lastView!;
return super.close();
}
}
1 change: 0 additions & 1 deletion lib/home/view/dashboard.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:fpb/authentication_with_firebase/application/bloc/auth_bloc.dart';
import 'package:fpb/core/domain/user.dart';
import 'package:fpb/core/presentation/animations/slide_up_route_transition.dart';
Expand Down
5 changes: 5 additions & 0 deletions lib/home/view/widgets/bottom_nav_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class _BottomNavBarState extends State<BottomNavBar> {
IconButton(
enableFeedback: false,
padding: EdgeInsets.zero,
key: Key("BNB-home-page-button"),
onPressed: () {
setState(() {
pageIndex = 0;
Expand Down Expand Up @@ -56,6 +57,7 @@ class _BottomNavBarState extends State<BottomNavBar> {
IconButton(
enableFeedback: false,
padding: EdgeInsets.zero,
key: Key("BNB-savings-page-button"),
onPressed: () {
setState(() {
pageIndex = 1;
Expand Down Expand Up @@ -86,6 +88,7 @@ class _BottomNavBarState extends State<BottomNavBar> {
IconButton(
enableFeedback: false,
padding: EdgeInsets.zero,
key: Key("BNB-quickCash-page-button"),
onPressed: () {
setState(() {
pageIndex = 2;
Expand Down Expand Up @@ -116,6 +119,7 @@ class _BottomNavBarState extends State<BottomNavBar> {
IconButton(
enableFeedback: false,
padding: EdgeInsets.zero,
key: Key("BNB-budget-page-button"),
onPressed: () {
setState(() {
pageIndex = 3;
Expand Down Expand Up @@ -147,6 +151,7 @@ class _BottomNavBarState extends State<BottomNavBar> {
IconButton(
enableFeedback: false,
padding: EdgeInsets.zero,
key: Key("BNB-userSearch-page-button"),
onPressed: () {
setState(() {
pageIndex = 4;
Expand Down
55 changes: 27 additions & 28 deletions lib/injection.config.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 11 additions & 12 deletions lib/sign_in/view/sign_in_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'package:auto_route/auto_route.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/svg.dart';

import 'package:fpb/assets/fpb_icons/fpb_icons_icons.dart';
import 'package:fpb/assets/fpb_svg.dart';
import 'package:fpb/authenticate_with_biometrics/application/bloc/biometric_auth_bloc.dart';
Expand Down Expand Up @@ -60,7 +58,6 @@ class SignInBody extends StatefulWidget {
class _SignInBodyState extends State<SignInBody>
with SingleTickerProviderStateMixin {
late TabController tabController;
final user = FirebaseAuth.instance.currentUser;

@override
void initState() {
Expand Down Expand Up @@ -163,15 +160,17 @@ class _SignInBodyState extends State<SignInBody>
physics: const BouncingScrollPhysics(),
controller: tabController,
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
EmailInput(box: cts),
PasswordInput(box: cts),
Text(l10n.signInForgotPasswordText),
],
SingleChildScrollView(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
EmailInput(box: cts),
PasswordInput(box: cts),
Text(l10n.signInForgotPasswordText),
],
),
),
Column(
mainAxisAlignment:
Expand Down
Loading

0 comments on commit 7ce6fab

Please sign in to comment.