Skip to content

Commit

Permalink
Merge pull request #260 from dherediat97/feature/unit-testing
Browse files Browse the repository at this point in the history
feature: fix some errors of unit testing
  • Loading branch information
dherediat97 authored Aug 28, 2024
2 parents 8e8e131 + c3cc37c commit cd1f6c3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 184 deletions.
10 changes: 7 additions & 3 deletions test/features/home/widgets/home_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';

import '../../../instruments/media_list_instruments.dart';
import '../../../pump_app.dart';
import 'home_widget_test.mocks.dart';

Expand Down Expand Up @@ -42,6 +43,7 @@ void main() {
when(mediaListBloc.state).thenReturn(
MediaListState.initial().copyWith(
uiState: const UiState.success(),
movieData: MediaListInstruments.movieList,
),
);

Expand Down Expand Up @@ -70,7 +72,9 @@ void main() {
mediaTypeSelected: MediaType.tv,
),
);
when(mediaListBloc.state).thenReturn(MediaListState.initial());
when(mediaListBloc.state).thenReturn(MediaListState.initial().copyWith(
serieData: MediaListInstruments.serieList,
));

await pumpApp(
tester: tester,
Expand All @@ -90,11 +94,11 @@ void main() {
expect(find.byType(SeriesListWidget), findsOneWidget);
});

testWidgets('HomeBloc adds switchCategory event with MediaType.tv',
testWidgets('HomeBloc adds switchCategory event with MediaType.search',
(WidgetTester tester) async {
when(homeBloc.state).thenReturn(
HomeState.initial().copyWith(
mediaTypeSelected: MediaType.movie,
mediaTypeSelected: MediaType.search,
uiState: const UiState.success(),
),
);
Expand Down
7 changes: 0 additions & 7 deletions test/features/media_detail/widgets/media_detail_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:film_flu/app/types/ui_state.dart';
import 'package:film_flu/presentation/features/bottom_app_bar/bloc/home_bloc.dart';
import 'package:film_flu/presentation/features/media_details/bloc/media_detail_bloc.dart';
import 'package:film_flu/presentation/features/media_details/media_detail_controller.dart';
import 'package:film_flu/presentation/features/media_list/bloc/media_list_bloc.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
Expand All @@ -15,17 +14,14 @@ import 'media_detail_test.mocks.dart';
@GenerateNiceMocks([
MockSpec<HomeBloc>(),
MockSpec<MediaDetailBloc>(),
MockSpec<MediaListBloc>(),
])
void main() {
late MockHomeBloc homeBloc;
late MockMediaListBloc mediaListBloc;
late MockMediaDetailBloc mediaDetailBloc;

setUpAll(
() {
homeBloc = MockHomeBloc();
mediaListBloc = MockMediaListBloc();
mediaDetailBloc = MockMediaDetailBloc();
},
);
Expand Down Expand Up @@ -59,9 +55,6 @@ void main() {
BlocProvider<MediaDetailBloc>(
create: (_) => mediaDetailBloc,
),
BlocProvider<MediaListBloc>(
create: (_) => mediaListBloc,
),
],
);
});
Expand Down
200 changes: 26 additions & 174 deletions test/features/media_detail/widgets/media_detail_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
// Do not manually edit this file.

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i5;
import 'dart:async' as _i4;

import 'package:film_flu/presentation/features/bottom_app_bar/bloc/home_bloc.dart'
as _i2;
import 'package:film_flu/presentation/features/media_details/bloc/media_detail_bloc.dart'
as _i3;
import 'package:film_flu/presentation/features/media_list/bloc/media_list_bloc.dart'
as _i4;
import 'package:flutter_bloc/flutter_bloc.dart' as _i6;
import 'package:flutter_bloc/flutter_bloc.dart' as _i5;
import 'package:mockito/mockito.dart' as _i1;

// ignore_for_file: type=lint
Expand Down Expand Up @@ -48,17 +46,6 @@ class _FakeMediaDetailState_1 extends _i1.SmartFake
);
}

class _FakeMediaListState_2 extends _i1.SmartFake
implements _i4.MediaListState {
_FakeMediaListState_2(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}

/// A class which mocks [HomeBloc].
///
/// See the documentation for Mockito's code generation for more information.
Expand All @@ -77,11 +64,11 @@ class MockHomeBloc extends _i1.Mock implements _i2.HomeBloc {
) as _i2.HomeState);

@override
_i5.Stream<_i2.HomeState> get stream => (super.noSuchMethod(
_i4.Stream<_i2.HomeState> get stream => (super.noSuchMethod(
Invocation.getter(#stream),
returnValue: _i5.Stream<_i2.HomeState>.empty(),
returnValueForMissingStub: _i5.Stream<_i2.HomeState>.empty(),
) as _i5.Stream<_i2.HomeState>);
returnValue: _i4.Stream<_i2.HomeState>.empty(),
returnValueForMissingStub: _i4.Stream<_i2.HomeState>.empty(),
) as _i4.Stream<_i2.HomeState>);

@override
bool get isClosed => (super.noSuchMethod(
Expand Down Expand Up @@ -119,8 +106,8 @@ class MockHomeBloc extends _i1.Mock implements _i2.HomeBloc {

@override
void on<E extends _i2.HomeEvent>(
_i6.EventHandler<E, _i2.HomeState>? handler, {
_i6.EventTransformer<E>? transformer,
_i5.EventHandler<E, _i2.HomeState>? handler, {
_i5.EventTransformer<E>? transformer,
}) =>
super.noSuchMethod(
Invocation.method(
Expand All @@ -132,7 +119,7 @@ class MockHomeBloc extends _i1.Mock implements _i2.HomeBloc {
);

@override
void onTransition(_i6.Transition<_i2.HomeEvent, _i2.HomeState>? transition) =>
void onTransition(_i5.Transition<_i2.HomeEvent, _i2.HomeState>? transition) =>
super.noSuchMethod(
Invocation.method(
#onTransition,
Expand All @@ -142,17 +129,17 @@ class MockHomeBloc extends _i1.Mock implements _i2.HomeBloc {
);

@override
_i5.Future<void> close() => (super.noSuchMethod(
_i4.Future<void> close() => (super.noSuchMethod(
Invocation.method(
#close,
[],
),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
) as _i5.Future<void>);
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
) as _i4.Future<void>);

@override
void onChange(_i6.Change<_i2.HomeState>? change) => super.noSuchMethod(
void onChange(_i5.Change<_i2.HomeState>? change) => super.noSuchMethod(
Invocation.method(
#onChange,
[change],
Expand Down Expand Up @@ -211,11 +198,11 @@ class MockMediaDetailBloc extends _i1.Mock implements _i3.MediaDetailBloc {
) as _i3.MediaDetailState);

@override
_i5.Stream<_i3.MediaDetailState> get stream => (super.noSuchMethod(
_i4.Stream<_i3.MediaDetailState> get stream => (super.noSuchMethod(
Invocation.getter(#stream),
returnValue: _i5.Stream<_i3.MediaDetailState>.empty(),
returnValueForMissingStub: _i5.Stream<_i3.MediaDetailState>.empty(),
) as _i5.Stream<_i3.MediaDetailState>);
returnValue: _i4.Stream<_i3.MediaDetailState>.empty(),
returnValueForMissingStub: _i4.Stream<_i3.MediaDetailState>.empty(),
) as _i4.Stream<_i3.MediaDetailState>);

@override
bool get isClosed => (super.noSuchMethod(
Expand Down Expand Up @@ -253,8 +240,8 @@ class MockMediaDetailBloc extends _i1.Mock implements _i3.MediaDetailBloc {

@override
void on<E extends _i3.MediaDetailEvent>(
_i6.EventHandler<E, _i3.MediaDetailState>? handler, {
_i6.EventTransformer<E>? transformer,
_i5.EventHandler<E, _i3.MediaDetailState>? handler, {
_i5.EventTransformer<E>? transformer,
}) =>
super.noSuchMethod(
Invocation.method(
Expand All @@ -267,7 +254,7 @@ class MockMediaDetailBloc extends _i1.Mock implements _i3.MediaDetailBloc {

@override
void onTransition(
_i6.Transition<_i3.MediaDetailEvent, _i3.MediaDetailState>?
_i5.Transition<_i3.MediaDetailEvent, _i3.MediaDetailState>?
transition) =>
super.noSuchMethod(
Invocation.method(
Expand All @@ -278,152 +265,17 @@ class MockMediaDetailBloc extends _i1.Mock implements _i3.MediaDetailBloc {
);

@override
_i5.Future<void> close() => (super.noSuchMethod(
Invocation.method(
#close,
[],
),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
) as _i5.Future<void>);

@override
void onChange(_i6.Change<_i3.MediaDetailState>? change) => super.noSuchMethod(
Invocation.method(
#onChange,
[change],
),
returnValueForMissingStub: null,
);

@override
void addError(
Object? error, [
StackTrace? stackTrace,
]) =>
super.noSuchMethod(
Invocation.method(
#addError,
[
error,
stackTrace,
],
),
returnValueForMissingStub: null,
);

@override
void onError(
Object? error,
StackTrace? stackTrace,
) =>
super.noSuchMethod(
Invocation.method(
#onError,
[
error,
stackTrace,
],
),
returnValueForMissingStub: null,
);
}

/// A class which mocks [MediaListBloc].
///
/// See the documentation for Mockito's code generation for more information.
class MockMediaListBloc extends _i1.Mock implements _i4.MediaListBloc {
@override
_i4.MediaListState get state => (super.noSuchMethod(
Invocation.getter(#state),
returnValue: _FakeMediaListState_2(
this,
Invocation.getter(#state),
),
returnValueForMissingStub: _FakeMediaListState_2(
this,
Invocation.getter(#state),
),
) as _i4.MediaListState);

@override
_i5.Stream<_i4.MediaListState> get stream => (super.noSuchMethod(
Invocation.getter(#stream),
returnValue: _i5.Stream<_i4.MediaListState>.empty(),
returnValueForMissingStub: _i5.Stream<_i4.MediaListState>.empty(),
) as _i5.Stream<_i4.MediaListState>);

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

@override
void add(_i4.MediaListEvent? event) => super.noSuchMethod(
Invocation.method(
#add,
[event],
),
returnValueForMissingStub: null,
);

@override
void onEvent(_i4.MediaListEvent? event) => super.noSuchMethod(
Invocation.method(
#onEvent,
[event],
),
returnValueForMissingStub: null,
);

@override
void emit(_i4.MediaListState? state) => super.noSuchMethod(
Invocation.method(
#emit,
[state],
),
returnValueForMissingStub: null,
);

@override
void on<E extends _i4.MediaListEvent>(
_i6.EventHandler<E, _i4.MediaListState>? handler, {
_i6.EventTransformer<E>? transformer,
}) =>
super.noSuchMethod(
Invocation.method(
#on,
[handler],
{#transformer: transformer},
),
returnValueForMissingStub: null,
);

@override
void onTransition(
_i6.Transition<_i4.MediaListEvent, _i4.MediaListState>? transition) =>
super.noSuchMethod(
Invocation.method(
#onTransition,
[transition],
),
returnValueForMissingStub: null,
);

@override
_i5.Future<void> close() => (super.noSuchMethod(
_i4.Future<void> close() => (super.noSuchMethod(
Invocation.method(
#close,
[],
),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
) as _i5.Future<void>);
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
) as _i4.Future<void>);

@override
void onChange(_i6.Change<_i4.MediaListState>? change) => super.noSuchMethod(
void onChange(_i5.Change<_i3.MediaDetailState>? change) => super.noSuchMethod(
Invocation.method(
#onChange,
[change],
Expand Down
15 changes: 15 additions & 0 deletions test/instruments/media_list_instruments.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:film_flu/domain/models/media_simple_item_entity.dart';

class MediaListInstruments {
static const MediaSimpleItemEntity movieMocked = MediaSimpleItemEntity(
id: 533535,
posterPath: '/9TFSqghEHrlBMRR63yTx80Orxva.jpg',
);

static const Map<int, List<MediaSimpleItemEntity>> movieList = {
28: [movieMocked],
};
static const Map<int, List<MediaSimpleItemEntity>> serieList = {
28: [movieMocked]
};
}

0 comments on commit cd1f6c3

Please sign in to comment.