-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from hoangnguyen92dn/release/0.2.0
Release - 0.2.0
- Loading branch information
Showing
77 changed files
with
2,183 additions
and
180 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
Binary file not shown.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
|
||
import '../utils/file_util.dart'; | ||
|
||
class FakeResponseModel extends Equatable { | ||
final int statusCode; | ||
final Map<String, dynamic> json; | ||
|
||
const FakeResponseModel( | ||
this.statusCode, | ||
this.json, | ||
); | ||
|
||
@override | ||
List<Object?> get props => [ | ||
statusCode, | ||
json, | ||
]; | ||
} | ||
|
||
const String keySignIn = 'signIn'; | ||
const String keyUserProfile = 'userProfile'; | ||
|
||
class FakeData { | ||
FakeData._(); | ||
|
||
static final Map<String, FakeResponseModel> _apiAndResponse = {}; | ||
|
||
static Map<String, FakeResponseModel> get apiAndResponse => _apiAndResponse; | ||
|
||
static Future<void> initDefault() async { | ||
_apiAndResponse.addAll({ | ||
keySignIn: FakeResponseModel( | ||
200, | ||
await FileUtil.loadFile( | ||
'integration_test/fake_data/fake_sign_in_response.json'), | ||
), | ||
keyUserProfile: FakeResponseModel( | ||
200, | ||
await FileUtil.loadFile( | ||
'integration_test/fake_data/fake_user_profile_response.json'), | ||
), | ||
}); | ||
} | ||
|
||
static void updateResponse(String key, FakeResponseModel newValue) { | ||
_apiAndResponse.update( | ||
key, | ||
(value) => newValue, | ||
ifAbsent: () => newValue, | ||
); | ||
} | ||
} | ||
|
||
DioError generateDioError(int statusCode) { | ||
return DioError( | ||
response: Response( | ||
statusCode: statusCode, | ||
requestOptions: RequestOptions(path: ''), | ||
), | ||
type: DioErrorType.badResponse, | ||
requestOptions: RequestOptions(path: ''), | ||
); | ||
} |
21 changes: 21 additions & 0 deletions
21
integration_test/fake_data/fake_services/fake_auth_service.dart
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:retrofit/retrofit.dart'; | ||
import 'package:survey_flutter_ic/api/request/sign_in_request.dart'; | ||
import 'package:survey_flutter_ic/api/response/auth_response.dart'; | ||
import 'package:survey_flutter_ic/api/service/auth_service.dart'; | ||
|
||
import '../fake_data.dart'; | ||
|
||
class FakeAuthService extends Fake implements AuthService { | ||
@override | ||
Future<AuthResponse> signIn( | ||
@Body() SignInRequest body, | ||
) async { | ||
await Future.delayed(const Duration(seconds: 5)); | ||
final response = FakeData.apiAndResponse[keySignIn]!; | ||
if (response.statusCode != 200) { | ||
throw generateDioError(response.statusCode); | ||
} | ||
return AuthResponse.fromJson(response.json); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
integration_test/fake_data/fake_services/fake_user_service.dart
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:survey_flutter_ic/api/response/profile_response.dart'; | ||
import 'package:survey_flutter_ic/api/service/user_service.dart'; | ||
|
||
import '../fake_data.dart'; | ||
|
||
class FakeUserService extends Fake implements UserService { | ||
@override | ||
Future<ProfileResponse> getProfile() async { | ||
await Future.delayed(const Duration(seconds: 5)); | ||
final response = FakeData.apiAndResponse[keyUserProfile]!; | ||
if (response.statusCode != 200) { | ||
throw generateDioError(response.statusCode); | ||
} | ||
return ProfileResponse.fromJson(response.json); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
import 'package:survey_flutter_ic/ui/home/home_screen.dart'; | ||
import 'package:survey_flutter_ic/ui/home/home_widget_id.dart'; | ||
|
||
import 'utils/test_util.dart'; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
homeScreenTest(); | ||
} | ||
|
||
void homeScreenTest() { | ||
group('Home Page', () { | ||
late Finder profileAvatar; | ||
|
||
setUpAll(() async { | ||
await TestUtil.setupTestEnvironment(); | ||
}); | ||
|
||
setUp(() { | ||
profileAvatar = find.byKey(HomeWidgetId.profileAvatarImage); | ||
}); | ||
|
||
testWidgets( | ||
"When the home screen shown, it displays the Home screen correctly", | ||
(WidgetTester tester) async { | ||
await tester | ||
.pumpWidget(TestUtil.pumpWidgetWithShellApp(const HomeScreen())); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(profileAvatar, findsOneWidget); | ||
}); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
import 'package:survey_flutter_ic/navigation/route.dart'; | ||
import 'package:survey_flutter_ic/ui/signin/sign_in_widget_id.dart'; | ||
|
||
import 'fake_data/fake_data.dart'; | ||
import 'utils/test_util.dart'; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
signInTest(); | ||
} | ||
|
||
void signInTest() { | ||
group('SignIn Page', () { | ||
late Finder emailField; | ||
late Finder passwordField; | ||
late Finder signInButton; | ||
|
||
setUpAll(() async { | ||
await TestUtil.setupTestEnvironment(); | ||
}); | ||
|
||
setUp(() { | ||
emailField = find.byKey(SignInWidgetId.emailInputField); | ||
passwordField = find.byKey(SignInWidgetId.passwordInputField); | ||
signInButton = find.byKey(SignInWidgetId.signInButton); | ||
}); | ||
|
||
testWidgets( | ||
"When the sign in screen shown, it displays the Sign In screen correctly", | ||
(WidgetTester tester) async { | ||
await tester | ||
.pumpWidget(TestUtil.pumpWidgetWithRoutePath(routePathSignInScreen)); | ||
|
||
expect(emailField, findsOneWidget); | ||
expect(passwordField, findsOneWidget); | ||
expect(signInButton, findsOneWidget); | ||
}); | ||
|
||
testWidgets( | ||
"When sign in with valid email and password, it navigate to Home screen", | ||
(WidgetTester tester) async { | ||
await FakeData.initDefault(); | ||
await tester | ||
.pumpWidget(TestUtil.pumpWidgetWithRoutePath(routePathSignInScreen)); | ||
await tester.enterText(emailField, '[email protected]'); | ||
await tester.enterText(passwordField, '1111111'); | ||
await tester.tap(signInButton); | ||
await tester.pump(const Duration(milliseconds: 200)); | ||
|
||
// TODO: Skip this text, this require refactor to handle the route | ||
// https://guillaume.bernos.dev/testing-go-router/ | ||
// expect(find.byKey(const Key(routePathHomeScreen)), findsOneWidget); | ||
}); | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/services.dart' show rootBundle; | ||
|
||
class FileUtil { | ||
FileUtil._(); | ||
|
||
static Future<Map<String, dynamic>> loadFile(String filePath) { | ||
return rootBundle.loadString(filePath).then((json) => jsonDecode(json)); | ||
} | ||
} |
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,4 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "fastlane" | ||
gem "fastlane", "= 2.210.1" | ||
gem "cocoapods" |
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.