-
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.
Merge pull request #85 from fga-eps-mds/feat#58/teste_edit_password
test(#58): criando teste para edit profile view
- Loading branch information
Showing
7 changed files
with
377 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:aranduapp/ui/edit_password/service/edit_password_service.dart'; | ||
import 'package:aranduapp/ui/edit_password/viewmodel/edit_password_viewmodel.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
|
||
void setupPasswordDI(){ | ||
|
||
GetIt.instance.registerFactory(() => EditPasswordViewModel()); | ||
GetIt.instance.registerSingleton(() => EditPasswordService()); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import 'package:aranduapp/core/state/command.dart'; | ||
import 'package:aranduapp/ui/edit_password/model/edit_password_request.dart'; | ||
import 'package:aranduapp/ui/edit_password/view/edit_password_view.dart'; | ||
import 'package:aranduapp/ui/edit_password/viewmodel/edit_password_viewmodel.dart'; | ||
import 'package:aranduapp/ui/shared/command_button.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
|
||
import 'edit_password_view_test.mocks.dart'; | ||
|
||
@GenerateNiceMocks([MockSpec<EditPasswordViewModel>(), MockSpec<Command1>()]) | ||
void main() { | ||
late MockEditPasswordViewModel mockEditPasswordViewModel; | ||
late MockCommand1<void, EditPasswordRequest> mockEditPasswordCommand1; | ||
|
||
setUp(() async { | ||
mockEditPasswordViewModel = MockEditPasswordViewModel(); | ||
|
||
mockEditPasswordCommand1 = MockCommand1(); | ||
|
||
when(mockEditPasswordViewModel.editCommand) | ||
.thenReturn(mockEditPasswordCommand1); | ||
|
||
when(mockEditPasswordCommand1.running).thenReturn(false); | ||
when(mockEditPasswordCommand1.isError).thenReturn(false); | ||
when(mockEditPasswordCommand1.isOk).thenReturn(false); | ||
|
||
await GetIt.instance.reset(); | ||
GetIt.I.registerLazySingleton<EditPasswordViewModel>( | ||
() => mockEditPasswordViewModel); | ||
}); | ||
|
||
Widget createScreen() { | ||
return const MaterialApp( | ||
home: EditPassword(), | ||
); | ||
} | ||
|
||
testWidgets('edit password screen displays', (WidgetTester tester) async { | ||
await tester.pumpWidget(createScreen()); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.byType(AppBar), findsOneWidget); | ||
expect(find.byKey(const ValueKey('old_password')), findsOneWidget); | ||
expect(find.byKey(const ValueKey('new_password')), findsOneWidget); | ||
expect(find.byType(CommandButton), findsOneWidget); | ||
}); | ||
|
||
testWidgets('edit password right values', (WidgetTester tester) async { | ||
await tester.pumpWidget(createScreen()); | ||
|
||
const oldPassword = 'test@example.com'; | ||
const newPassword = 'password123'; | ||
|
||
await tester.enterText(find.byKey(const Key('old_password')), oldPassword); | ||
await tester.enterText(find.byKey(const Key('new_password')), newPassword); | ||
|
||
await tester.tap(find.byKey(const Key('elevated_button_key'))); | ||
await tester.pumpAndSettle(); | ||
|
||
verify(mockEditPasswordCommand1.execute(argThat( | ||
predicate<EditPasswordRequest>((req) => | ||
req.oldPassword == oldPassword && | ||
req.newPassword == newPassword)))).called(1); | ||
}); | ||
|
||
testWidgets('edit password wrong values', (WidgetTester tester) async { | ||
await tester.pumpWidget(createScreen()); | ||
|
||
const oldPassword = 'test'; | ||
const newPassword = 'password123'; | ||
|
||
await tester.enterText(find.byKey(const Key('old_password')), oldPassword); | ||
await tester.enterText(find.byKey(const Key('new_password')), newPassword); | ||
|
||
await tester.tap(find.byKey(const Key('elevated_button_key'))); | ||
await tester.pumpAndSettle(); | ||
|
||
verifyNever(mockEditPasswordCommand1.execute(argThat(isNotNull))); | ||
}); | ||
} |
Oops, something went wrong.