Skip to content

Commit

Permalink
feat(#64): altera teste join_subject_view_test.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasm1nNasc1mento committed Feb 9, 2025
1 parent abd3d70 commit 32ed559
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions test/ui/join_subjects/view/join_subjects_view_test.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:aranduapp/core/network/auth_api.dart';
import 'package:aranduapp/core/state/command.dart';
import 'package:aranduapp/ui/join_subjects/view/join_subjects_view.dart';
import 'package:aranduapp/ui/join_subjects/viewmodel/join_subjects_viewmodel.dart';
import 'package:aranduapp/ui/journey/view/journey_view.dart';
import 'package:aranduapp/ui/journey/viewmodel/journey_viewmodel.dart';
import 'package:aranduapp/ui/shared/command_button.dart';
import 'package:aranduapp/ui/subjects/model/subject_model.dart';
Expand All @@ -15,27 +13,28 @@ import 'package:mockito/mockito.dart';
import 'join_subjects_view_test.mocks.dart';

@GenerateNiceMocks([MockSpec<JoinSubjectsViewmodel>(), MockSpec<Command1>()])
void main(){
void main() {
late MockJoinSubjectsViewmodel mockJoinSubjectsViewmodel;
late MockCommand1<void, String> mockJoinsubjectsCommand1;

final testSubject =
SubjectModel(id: '1', name: 'calculo1', shortName: '', description: 'derivadas');
final testSubject = SubjectModel(
id: '1', name: 'calculo1', shortName: '', description: 'derivadas');

setUp(() async {
mockJoinSubjectsViewmodel = MockJoinSubjectsViewmodel();
mockJoinsubjectsCommand1 = MockCommand1();

when(mockJoinSubjectsViewmodel.joinsubjectsCommand).thenReturn(mockJoinsubjectsCommand1);
when(mockJoinSubjectsViewmodel.joinsubjectsCommand)
.thenReturn(mockJoinsubjectsCommand1);

when(mockJoinsubjectsCommand1.running).thenReturn(false);
when(mockJoinsubjectsCommand1.isError).thenReturn(false);
when(mockJoinsubjectsCommand1.isOk).thenReturn(false);

await GetIt.instance.reset();
GetIt.I.registerLazySingleton<JoinSubjectsViewmodel>(
() => mockJoinSubjectsViewmodel);
GetIt.I.registerLazySingleton<JourneyViewModel>(() => JourneyViewModel());
() => mockJoinSubjectsViewmodel);
GetIt.I.registerFactory<JourneyViewModel>(() => JourneyViewModel());
});

Widget createScreen() {
Expand All @@ -44,7 +43,7 @@ void main(){
);
}

testWidgets('Join subjects screen display', (WidgetTester tester) async{
testWidgets('Join subjects screen display', (WidgetTester tester) async {
await tester.pumpWidget(createScreen());
await tester.pumpAndSettle();

Expand All @@ -55,23 +54,25 @@ void main(){
expect(find.byType(CommandButton), findsOneWidget);
});

testWidgets('checks if when pressing the button it passes an ID', (WidgetTester tester) async{
testWidgets('checks if when pressing the button it passes an ID',
(WidgetTester tester) async {
await tester.pumpWidget(createScreen());
await tester.pumpAndSettle();

await tester.tap(find.byKey(const Key('elevated_button_key')));
await tester.pumpAndSettle();

verify(mockJoinsubjectsCommand1.execute(testSubject.id)).called(1);

});
testWidgets('navigates to SubjectsView after successful join', (WidgetTester tester) async {

/* testWidgets('navigates to SubjectsView after successful join',
(WidgetTester tester) async {
when(mockJoinsubjectsCommand1.isOk).thenReturn(true);
await tester.pumpWidget(createScreen());
await tester.pumpAndSettle();
expect(find.byType(Journey), findsOneWidget);
});

}
});*/
}

0 comments on commit 32ed559

Please sign in to comment.