Skip to content

Commit

Permalink
Merge pull request #214 from dherediat97/feature/unit-test
Browse files Browse the repository at this point in the history
Feature/unit test
  • Loading branch information
dherediat97 committed Jul 22, 2024
2 parents 7e39b69 + 9cc8f6d commit fe721dd
Show file tree
Hide file tree
Showing 16 changed files with 1,022 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies:
get_it: ^7.2.0
lottie: ^3.1.2
envied: ^0.5.3
http: ^1.2.1
http: ^1.2.2
package_info_plus: ^4.2.0
flutter_svg: ^2.0.7
responsive_framework: ^1.1.0
Expand Down Expand Up @@ -82,6 +82,7 @@ dev_dependencies:
# https://pub.dev/packages/bloc_test
bloc_test: ^9.1.7
flutter_launcher_icons: ^0.13.1
test: ^1.25.2

flutter:
generate: true
Expand Down
5 changes: 2 additions & 3 deletions runCoverage.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash
# Generate `coverage/lcov.info` file
flutter test --coverage
# Generate HTML report
genhtml coverage/lcov.info -o coverage/html
/c/ProgramData/chocolatey/lib/lcov/tools/bin/genhtml coverage/lcov.info -o coverage/html
# Open the report
open coverage/html/index.html
start coverage/html/index.html
52 changes: 52 additions & 0 deletions test/features/home/bloc/home_bloc_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:bloc_test/bloc_test.dart';
import 'package:film_flu/domain/models/media_data_entity.dart';
import 'package:film_flu/presentation/features/media_list/bloc/media_list_bloc.dart';
import 'package:mockito/annotations.dart';
import 'package:test/scaffolding.dart';

import 'home_bloc_test.mocks.dart';

@GenerateNiceMocks([MockSpec<MediaListBloc>()])
void main() {
late MockMediaListBloc mockBlock;

setUp(
() {
mockBlock = MockMediaListBloc();
},
);

group(
'Testing Home Screen Bloc',
() {
blocTest(
'Given Home Screen Bloc when load the bloc then return the empty expected result',
build: () => mockBlock,
expect: () => [],
);

blocTest(
'Given HomeScreenBloc when load the bloc then return the expected result',
build: () => mockBlock,
act: (bloc) => bloc.add(const MediaListEvent.getMediaData()),
expect: () => [
MediaListState.initial().copyWith(
mediaData: const MediaDataEntity(
fictionMovies: [],
dramasMovies: [],
actionMovies: [],
romanceMovies: [],
comedyMovies: [],
suspenseMovies: [],
animeSeries: [],
animationSeries: [],
tvShowsSeries: [],
documentalSeries: [],
),
mediaList: List.empty(),
),
],
);
},
);
}
170 changes: 170 additions & 0 deletions test/features/home/bloc/home_bloc_test.mocks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// Mocks generated by Mockito 5.4.4 from annotations
// in film_flu/test/features/home/bloc/home_bloc_test.dart.
// Do not manually edit this file.

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i3;

import 'package:film_flu/presentation/features/media_list/bloc/media_list_bloc.dart'
as _i2;
import 'package:flutter_bloc/flutter_bloc.dart' as _i4;
import 'package:mockito/mockito.dart' as _i1;

// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
// ignore_for_file: comment_references
// ignore_for_file: deprecated_member_use
// ignore_for_file: deprecated_member_use_from_same_package
// ignore_for_file: implementation_imports
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class

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

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

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

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

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

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

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

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

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

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

@override
void onChange(_i4.Change<_i2.MediaListState>? 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,
);
}
13 changes: 13 additions & 0 deletions test/features/home/widgets/home_widget_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:film_flu/presentation/features/home/home_screen.dart';
import 'package:flutter_test/flutter_test.dart';

import '../../../instruments/pump_app.dart';

void main() {
testWidgets('Testing Home Screen', (WidgetTester tester) async {
await pumpApp(
tester,
const HomeScreen(),
);
});
}
56 changes: 56 additions & 0 deletions test/features/media_detail/bloc/media_detail_bloc_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:bloc_test/bloc_test.dart';
import 'package:film_flu/app/types/ui_state.dart';
import 'package:film_flu/presentation/features/media_details/bloc/media_detail_bloc.dart';
import 'package:test/test.dart';
import 'package:mockito/annotations.dart';

import 'media_detail_bloc_test.mocks.dart';

@GenerateNiceMocks([MockSpec<MediaDetailBloc>()])
void main() {
late MockMediaDetailBloc mockBlock;

setUp(
() {
mockBlock = MockMediaDetailBloc();
},
);

group(
'Testing Media Detail Screen Bloc',
() {
blocTest(
'Given MediaDetailBloc when load the bloc then return the empty expected result',
build: () => mockBlock,
expect: () => [],
);

blocTest(
'Given MediaDetailBloc when load the bloc then return the expected result',
build: () => mockBlock,
act: (bloc) =>
bloc.add(const MediaDetailEvent.getMediaDetails('movie', '11111')),
expect: () => [
MediaDetailState.initial().copyWith(
credits: null,
isCastSelected: true,
isTrailerOpened: false,
mediaItem: null,
movieName: '',
trailerId: '',
uiState: const UiState.loading(),
),
MediaDetailState.initial().copyWith(
credits: null,
isCastSelected: true,
isTrailerOpened: false,
mediaItem: null,
movieName: '',
trailerId: '',
uiState: const UiState.success(),
),
],
);
},
);
}
Loading

0 comments on commit fe721dd

Please sign in to comment.