Skip to content

Commit

Permalink
feat(#64): adiciona testes journey_view_test.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasm1nNasc1mento committed Feb 8, 2025
1 parent 23859f6 commit 6802f99
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 9 deletions.
16 changes: 7 additions & 9 deletions test/ui/journey/view/journey_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import 'package:aranduapp/ui/shared/loading_widget.dart';
import 'package:aranduapp/ui/journey/model/journey_model.dart';
import 'journey_view_test.mocks.dart';

import '../../login/view/login_view_test.mocks.dart';

@GenerateNiceMocks([MockSpec<JourneyViewModel>(), MockSpec<Command1>()])
void main() {
late MockJourneyViewModel mockViewModel;
late MockCommand1<List<JourneyModel>, String> mockGetJourneyCommand;
final testSubject =
SubjectModel(id: '1', name: 'Matemática', shortName: '', description: '');
SubjectModel(id: '1', name: 'Matemática', shortName: 'Mat', description:'Desvende os mistérios da Matemática e expanda seus horizontes intelectuais.');

setUp(() async {
mockViewModel = MockJourneyViewModel();
Expand All @@ -41,7 +40,7 @@ void main() {
);
}

testWidgets('Deve mostrar LoadingWidget inicialmente',
testWidgets('Should show LoadingWidget initially',
(WidgetTester tester) async {
when(mockGetJourneyCommand.running).thenReturn(true);

Expand All @@ -50,7 +49,7 @@ void main() {
expect(find.byType(LoadingWidget), findsOneWidget);
});

testWidgets('Deve mostrar lista de jornadas quando comando for bem sucedido',
testWidgets('Should show journey list when command is successful',
(WidgetTester tester) async {
final testJourneys = [
JourneyModel(id: '1', title: 'Jornada 1', description: 'Descrição 1'),
Expand All @@ -68,7 +67,7 @@ void main() {
expect(find.text('Jornada 2'), findsOneWidget);
});

testWidgets('Deve mostrar erro quando comando falhar',
testWidgets('Should show error when command fails',
(WidgetTester tester) async {
when(mockGetJourneyCommand.isError).thenReturn(true);
when(mockGetJourneyCommand.result)
Expand All @@ -78,19 +77,18 @@ void main() {
await tester.pumpAndSettle();

expect(find.byType(ErrorScreen), findsOneWidget);
expect(find.text('Deslize para baixo \n\n Erro de conexão'), findsOneWidget);

expect(find.text('Deslize para baixo\n\n Erro de conexão'), findsOneWidget);
expect(find.text('Algo deu errado...'), findsOneWidget);
});

testWidgets('Deve chamar o comando execute ao iniciar a tela',
testWidgets('Should call execute command when screen starts',
(WidgetTester tester) async {
await tester.pumpWidget(createJourneyScreen());
verify(mockGetJourneyCommand.execute(testSubject.id)).called(1);
});

testWidgets(
'Deve chamar o comando execute novamente ao realizar o refresh na tela',
testWidgets('Should call execute command again when performing refresh on the screen',
(WidgetTester tester) async {
when(mockGetJourneyCommand.isOk).thenReturn(true);
when(mockGetJourneyCommand.result).thenReturn(Result.value([
Expand Down
113 changes: 113 additions & 0 deletions test/ui/journey/view/journey_view_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ class MockJourneyViewModel extends _i1.Mock implements _i4.JourneyViewModel {
returnValueForMissingStub: null,
);

@override
bool get isReloadingData => (super.noSuchMethod(
Invocation.getter(#isReloadingData),
returnValue: false,
returnValueForMissingStub: false,
) as bool);

@override
bool get hasListeners => (super.noSuchMethod(
Invocation.getter(#hasListeners),
Expand Down Expand Up @@ -147,3 +154,109 @@ class MockJourneyViewModel extends _i1.Mock implements _i4.JourneyViewModel {
);
}

/// A class which mocks [Command1].
///
/// See the documentation for Mockito's code generation for more information.
class MockCommand1<T, A> extends _i1.Mock implements _i2.Command1<T, A> {
@override
_i6.Future<_i3.Result<T>> Function(A) get action => (super.noSuchMethod(
Invocation.getter(#action),
returnValue: (A __p0) =>
_i6.Future<_i3.Result<T>>.value(_FakeResult_1<T>(
this,
Invocation.getter(#action),
)),
returnValueForMissingStub: (A __p0) =>
_i6.Future<_i3.Result<T>>.value(_FakeResult_1<T>(
this,
Invocation.getter(#action),
)),
) as _i6.Future<_i3.Result<T>> Function(A));

@override
bool get isError => (super.noSuchMethod(
Invocation.getter(#isError),
returnValue: false,
returnValueForMissingStub: false,
) as bool);

@override
bool get isOk => (super.noSuchMethod(
Invocation.getter(#isOk),
returnValue: false,
returnValueForMissingStub: false,
) as bool);

@override
bool get running => (super.noSuchMethod(
Invocation.getter(#running),
returnValue: false,
returnValueForMissingStub: false,
) as bool);

@override
bool get hasListeners => (super.noSuchMethod(
Invocation.getter(#hasListeners),
returnValue: false,
returnValueForMissingStub: false,
) as bool);

@override
_i6.Future<_i3.Result<T>> execute(A? arg1) => (super.noSuchMethod(
Invocation.method(
#execute,
[arg1],
),
returnValue: _i6.Future<_i3.Result<T>>.value(_FakeResult_1<T>(
this,
Invocation.method(
#execute,
[arg1],
),
)),
returnValueForMissingStub:
_i6.Future<_i3.Result<T>>.value(_FakeResult_1<T>(
this,
Invocation.method(
#execute,
[arg1],
),
)),
) as _i6.Future<_i3.Result<T>>);

@override
void addListener(_i7.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(
#addListener,
[listener],
),
returnValueForMissingStub: null,
);

@override
void removeListener(_i7.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(
#removeListener,
[listener],
),
returnValueForMissingStub: null,
);

@override
void dispose() => super.noSuchMethod(
Invocation.method(
#dispose,
[],
),
returnValueForMissingStub: null,
);

@override
void notifyListeners() => super.noSuchMethod(
Invocation.method(
#notifyListeners,
[],
),
returnValueForMissingStub: null,
);
}

0 comments on commit 6802f99

Please sign in to comment.