Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit test to login, portal and register page
- Loading branch information
1 parent
ee0cb4b
commit 417bf1b
Showing
52 changed files
with
948 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
class AppplicationConstants { | ||
static final baseEndpoint = 'https://node-buildozer.herokuapp.com/api/'; | ||
static final appName = 'Learning Flutter'; | ||
static final tokenKey = 'token'; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
class Storage { | ||
final _storage = FlutterSecureStorage(); | ||
factory Storage() => Storage._internal(); | ||
Storage._internal(); | ||
final _storage = SharedPreferences.getInstance(); | ||
|
||
/// Get specific field | ||
Future<String> get(String key) { | ||
return _storage.read(key: key); | ||
Future<String> get(String key) async { | ||
return (await _storage).getString(key); | ||
} | ||
|
||
Future<void> set(String key, String payload) { | ||
return _storage.write(key: key, value: payload); | ||
Future<void> set(String key, String payload) async { | ||
return (await _storage).setString(key, payload); | ||
} | ||
|
||
/// Remove specific field | ||
Future<void> remove(String key) { | ||
return _storage.delete(key: key); | ||
Future<void> remove(String key) async { | ||
return (await _storage).remove(key); | ||
} | ||
|
||
/// Remove all storage | ||
Future<void> clear(String key) { | ||
return _storage.deleteAll(); | ||
Future<void> clear(String key) async { | ||
return (await _storage).clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
import 'package:learning_flutter/app/core/constants/index.dart'; | ||
import 'package:learning_flutter/app/core/helpers/storage.dart'; | ||
|
||
const token_key = 'token'; | ||
import 'package:learning_flutter/app/locator.dart'; | ||
|
||
class TokenHelper { | ||
factory TokenHelper() => const TokenHelper._internal(); | ||
const TokenHelper._internal(); | ||
|
||
Future<void> removeToken() async { | ||
return await Storage().remove(token_key); | ||
final _storage = locator<Storage>(); | ||
Future<void> removeToken() { | ||
return _storage.remove(AppplicationConstants.tokenKey); | ||
} | ||
|
||
Future<void> addToken(String token) async { | ||
return await Storage().set(token_key, token); | ||
Future<void> setToken(String token) { | ||
return _storage.set(AppplicationConstants.tokenKey, token); | ||
} | ||
|
||
Future<String> getToken() async { | ||
return await Storage().get(token_key); | ||
Future<String> getToken() { | ||
return _storage.get(AppplicationConstants.tokenKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,53 @@ | ||
import 'package:geolocator/geolocator.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:learning_flutter/app/core/auth.service.dart'; | ||
import 'package:learning_flutter/app/core/helpers/storage.dart'; | ||
import 'package:learning_flutter/app/core/helpers/token.dart'; | ||
import 'package:learning_flutter/app/pages/home/home.bloc.dart'; | ||
import 'package:learning_flutter/app/pages/meals/index.dart'; | ||
import 'package:learning_flutter/app/pages/menus/index.dart'; | ||
import 'package:learning_flutter/app/pages/settings/settings.bloc.dart'; | ||
import 'package:learning_flutter/app/shared/models/portal.model.dart'; | ||
import 'package:learning_flutter/app/shared/services/menus.service.dart'; | ||
import 'package:learning_flutter/app/shared/services/user/user.service.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
|
||
GetIt locator = GetIt(); | ||
|
||
// TODO: Create base class to include the child class in the locator directly | ||
void setupLocator() { | ||
// REVIEW Locator has one critical issue which is cannot know which class depends on another so it should be order depend on that | ||
// TODO: try to make function like `locateMe()` inside each class that should be singelton | ||
locator.registerSingleton(Storage()); | ||
locator.registerSingleton(TokenHelper()); | ||
locator.registerSingleton<UserService>(UserService()); | ||
locator.registerSingleton(Geolocator()); | ||
locator.registerSingleton(LocalAuthenticationService()); | ||
locator.registerSingleton(MenusService()); | ||
locator.registerSingleton(MealsService()); | ||
// FIXME: Bloc's shouldn't be used in get it | ||
locator.registerSingleton(HomeBloc()); | ||
locator.registerSingleton(MealsBloc()); | ||
locator.registerSingleton(SettingsBloc()); | ||
} | ||
|
||
class MockUserService extends Mock implements UserService {} | ||
class MockMealsService extends Mock implements MealsService {} | ||
class MockStorage extends Mock implements Storage {} | ||
class MockMenusService extends Mock implements MenusService {} | ||
|
||
void setupMockLocator() { | ||
// locator.registerSingleton<Storage>(MockStorage()); | ||
// locator.registerSingleton(TokenHelper()); | ||
locator.registerSingleton<UserService>(MockUserService()); | ||
// locator.registerSingleton(Geolocator()); | ||
// locator.registerSingleton(LocalAuthenticationService()); | ||
// locator.registerSingleton<MenusService>(MenusService()); | ||
// locator.registerSingleton<MealsService>(MealsService()); | ||
// FIXME: Bloc's shouldn't be used in get it | ||
// locator.registerSingleton(HomeBloc()); | ||
// locator.registerSingleton(MealsBloc()); | ||
// locator.registerSingleton(SettingsBloc()); | ||
// locator.registerSingleton(HomeBloc()); | ||
// locator.registerSingleton(MealsBloc()); | ||
// locator.registerSingleton(SettingsBloc()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.