-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(#59): criando teste para login view model
- Loading branch information
1 parent
7c00605
commit ffc129a
Showing
16 changed files
with
466 additions
and
147 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,12 +1,14 @@ | ||
import 'package:aranduapp/ui/login/service/login_service.dart'; | ||
import 'package:aranduapp/ui/login/viewmodel/login_viewmodel.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:local_auth/local_auth.dart'; | ||
|
||
final GetIt locator = GetIt.instance; | ||
|
||
void setupLoginDI() { | ||
|
||
locator.registerLazySingleton(() => LoginService()); | ||
locator.registerLazySingleton(() => LocalAuthentication()); | ||
|
||
locator.registerFactory(() => LoginViewModel()); | ||
} |
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
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,7 +1,9 @@ | ||
import 'package:aranduapp/core/state/command.dart'; | ||
import 'package:aranduapp/ui/login/model/login_request.dart'; | ||
import 'package:aranduapp/ui/login/view/login_view.dart'; | ||
import 'package:aranduapp/ui/login/viewmodel/login_viewmodel.dart'; | ||
import 'package:aranduapp/ui/navbar/view/navbar_view.dart'; | ||
import 'package:aranduapp/ui/shared/command_button.dart'; | ||
import 'package:aranduapp/ui/shared/text_email.dart'; | ||
import 'package:aranduapp/ui/shared/text_password.dart'; | ||
import 'package:async/async.dart'; | ||
|
@@ -11,23 +13,23 @@ import 'package:get_it/get_it.dart'; | |
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
|
||
@GenerateNiceMocks([MockSpec<LoginViewModel>(), MockSpec<Command0>()]) | ||
@GenerateNiceMocks( | ||
[MockSpec<LoginViewModel>(), MockSpec<Command0>(), MockSpec<Command1>()]) | ||
import 'login_view_test.mocks.dart'; | ||
|
||
void main() { | ||
late MockLoginViewModel mockViewModel; | ||
late MockCommand0 mockLoginCommand; | ||
late MockCommand1<void, LoginRequest> mockLoginCommand; | ||
late MockCommand0 mockValidadeTokenCommand; | ||
|
||
setUp(() async { | ||
mockViewModel = MockLoginViewModel(); | ||
when(mockViewModel.formKey).thenReturn(GlobalKey<FormState>()); | ||
when(mockViewModel.emailController).thenReturn(TextEditingController()); | ||
when(mockViewModel.passwordController).thenReturn(TextEditingController()); | ||
|
||
mockLoginCommand = MockCommand0(); | ||
when(mockLoginCommand.execute()) | ||
mockLoginCommand = MockCommand1(); | ||
|
||
when(mockLoginCommand.execute(any)) | ||
.thenAnswer((_) async => Result.value(null)); | ||
|
||
when(mockViewModel.loginCommand).thenReturn(mockLoginCommand); | ||
|
||
mockValidadeTokenCommand = MockCommand0(); | ||
|
@@ -86,6 +88,7 @@ void main() { | |
|
||
expect(find.byType(TextEmail), findsOneWidget); | ||
expect(find.byType(TextPassWord), findsOneWidget); | ||
expect(find.byType(CommandButton), findsOneWidget); | ||
expect(find.text('Entrar'), findsOneWidget); | ||
}); | ||
|
||
|
@@ -102,28 +105,38 @@ void main() { | |
await tester.enterText(find.byType(TextEmail), email); | ||
await tester.enterText(find.byType(TextPassWord), password); | ||
|
||
expect(mockViewModel.emailController.text, email); | ||
expect(mockViewModel.passwordController.text, password); | ||
await tester.tap(find.byKey(const Key('elevated_button_key'))); | ||
|
||
verify(mockLoginCommand.execute(argThat( | ||
predicate<LoginRequest>( | ||
(req) => req.email == email && req.password == password), | ||
))).called(1); | ||
}); | ||
|
||
testWidgets('Login is successful', (WidgetTester tester) async { | ||
when(mockValidadeTokenCommand.isError).thenReturn(true); | ||
when(mockLoginCommand.execute(any)) | ||
.thenAnswer((_) async => Result.value(null)); | ||
|
||
await tester.pumpWidget(createLoginScreen()); | ||
await tester.pumpAndSettle(); | ||
|
||
when(mockLoginCommand.execute()) | ||
.thenAnswer((_) async => Result.value(null)); | ||
const email = '[email protected]'; | ||
const password = 'password123'; | ||
|
||
await tester.tap(find.text('Entrar')); | ||
await tester.enterText(find.byType(TextEmail), email); | ||
await tester.enterText(find.byType(TextPassWord), password); | ||
|
||
await tester.tap(find.byKey(const Key('elevated_button_key'))); | ||
await tester.pumpAndSettle(); | ||
|
||
verify(mockLoginCommand.execute()).called(1); | ||
verify(mockLoginCommand.execute(argThat( | ||
predicate<LoginRequest>( | ||
(req) => req.email == email && req.password == password) | ||
))).called(1); | ||
|
||
//TODO: verify navigation to navbar | ||
// TODO: Verify navigation to navbar | ||
}); | ||
|
||
testWidgets('Displays error when login fails', (WidgetTester tester) async { | ||
//TODO: | ||
}); | ||
|
Oops, something went wrong.