Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add missing tests #22

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cf39c31
refactor: update helper layer in tests
BBarisKilic Oct 15, 2023
b8b5bf3
refactor: extend DataState class from Equatable
BBarisKilic Oct 15, 2023
c0a8ab9
test: add missing tests of NumberRepositoryImpl
BBarisKilic Oct 15, 2023
145a444
test: add missing tests of GetNumberUsecase
BBarisKilic Oct 16, 2023
bf70a3e
test: add missing tests of GetRandomNumberUseCase
BBarisKilic Oct 16, 2023
e3eeec8
refactor: make MockNumberRepository class final
BBarisKilic Oct 16, 2023
634b82e
refactor: rename NumberRepository as NumbersRepository
BBarisKilic Oct 16, 2023
bfac960
test: add tests for NumberDto
BBarisKilic Oct 16, 2023
420ba17
refactor: extend ErrorDetails class from Equatable
BBarisKilic Oct 16, 2023
60f9952
test: add tests for DataState
BBarisKilic Oct 16, 2023
0b89668
test: add tests for ErrorDetails
BBarisKilic Oct 16, 2023
6a88334
test: update tests of DataState
BBarisKilic Oct 16, 2023
4f1b0de
test: update tests of NumberDto
BBarisKilic Oct 16, 2023
d96162a
test: add tests for GetThemeParams
BBarisKilic Oct 16, 2023
d2d2ed3
refactor: update file name of GetNumberParams class
BBarisKilic Oct 16, 2023
1895885
refactor: update params
BBarisKilic Oct 16, 2023
c50b234
test: add tests for GetNumberParams
BBarisKilic Oct 16, 2023
f2d2419
test: add tests for SaveThemeParams
BBarisKilic Oct 16, 2023
e65c785
test: add tests for Number
BBarisKilic Oct 16, 2023
8677536
test: update tests of GetNumberParams
BBarisKilic Oct 16, 2023
b1939cd
test: update tests of GetThemeParams
BBarisKilic Oct 16, 2023
b49d808
test: update tests of SaveThemeParams
BBarisKilic Oct 16, 2023
b89df24
test: update tests of DataState
BBarisKilic Oct 16, 2023
ebb1503
test: add tests for NumbersServiceException
BBarisKilic Oct 16, 2023
0579a70
test: update tests of GetNumberException
BBarisKilic Oct 16, 2023
49027a9
feat: create MockDio helper class for tests
BBarisKilic Oct 16, 2023
d2ae9d3
test: add tests for DioNumbersService
BBarisKilic Oct 16, 2023
5e91b96
feat: create base mixins of usecases for testability
BBarisKilic Oct 17, 2023
7d46bfc
feat: create MockGetNumberUseCase helper class for tests
BBarisKilic Oct 17, 2023
4118f15
feat: create MockGetRandomNumberUseCase helper class for tests
BBarisKilic Oct 17, 2023
444e351
test: add tests for NumberCubit
BBarisKilic Oct 17, 2023
d424112
refactor: rename usecase file names as use_case
BBarisKilic Oct 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ Future<void> setup() async {
..registerLazySingleton<ThemeRepository>(
() => ThemeRepositoryImpl(service: getIt()),
)
..registerLazySingleton<NumberRepository>(
() => NumberRepositoryImpl(service: getIt()),
..registerLazySingleton<NumbersRepository>(
() => NumbersRepositoryImpl(service: getIt()),
)
..registerLazySingleton<GetThemeUseCase>(
() => GetThemeUseCase(repository: getIt()),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/app/domain/domain.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export 'repositories/repositories.dart';
export 'usecases/usecases.dart';
export 'use_cases/use_cases.dart';
2 changes: 2 additions & 0 deletions lib/src/app/domain/use_cases/use_cases.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'get_theme_use_case.dart';
export 'save_theme_use_case.dart';
2 changes: 0 additions & 2 deletions lib/src/app/domain/usecases/usecases.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/src/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export 'extensions/extensions.dart';
export 'l10n/l10n.dart';
export 'params/params.dart';
export 'resources/resources.dart';
export 'usecases/usecase.dart';
export 'use_case/use_case.dart';
2 changes: 1 addition & 1 deletion lib/src/core/params/params.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/foundation.dart';

export 'get_number_params.dart';
export 'get_theme_params.dart';
export 'number_request_params.dart';
export 'save_theme_params.dart';

@immutable
Expand Down
8 changes: 5 additions & 3 deletions lib/src/core/resources/data_state.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:equatable/equatable.dart';
import 'package:numbers/src/core/core.dart';

@immutable
sealed class DataState<T> {
sealed class DataState<T> extends Equatable {
const DataState({this.data, this.details});

final T? data;
final ErrorDetails? details;

@override
List<Object?> get props => [data, details];
}

final class DataSuccess<T> extends DataState<T> {
Expand Down
7 changes: 6 additions & 1 deletion lib/src/core/resources/error_details.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
final class ErrorDetails {
import 'package:equatable/equatable.dart';

final class ErrorDetails extends Equatable {
const ErrorDetails({
required this.error,
required this.message,
Expand All @@ -8,4 +10,7 @@ final class ErrorDetails {
final String error;
final String message;
final String stackTrace;

@override
List<Object?> get props => [error, message, stackTrace];
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:numbers/src/core/core.dart';
import 'package:numbers/src/features/number/number.dart';

final class NumberRepositoryImpl implements NumberRepository {
const NumberRepositoryImpl({
final class NumbersRepositoryImpl implements NumbersRepository {
const NumbersRepositoryImpl({
required NumbersService service,
}) : _numbersService = service;

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export 'number_repository_impl.dart';
export 'numbers_repository_impl.dart';
2 changes: 1 addition & 1 deletion lib/src/features/number/domain/domain.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export 'entities/entities.dart';
export 'repositories/repositories.dart';
export 'usecases/usecases.dart';
export 'use_cases/use_cases.dart';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:numbers/src/core/core.dart';
import 'package:numbers/src/features/number/number.dart';

abstract interface class NumberRepository {
abstract interface class NumbersRepository {
Future<DataState<Number>> getNumber(GetNumberParams params);
Future<DataState<Number>> getRandomNumber();
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export 'number_repository.dart';
export 'numbers_repository.dart';
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import 'package:flutter/foundation.dart';
import 'package:numbers/src/core/core.dart';
import 'package:numbers/src/features/number/number.dart';

final class GetNumberUseCase
implements UseCase<DataState<Number>, GetNumberParams> {
const GetNumberUseCase({
required NumberRepository repository,
}) : _numberRepository = repository;
required NumbersRepository repository,
}) : _numbersRepository = repository;

final NumberRepository _numberRepository;
final NumbersRepository _numbersRepository;

@override
Future<DataState<Number>> call({required GetNumberParams params}) =>
_numberRepository.getNumber(params);
_numbersRepository.getNumber(params);
}

@visibleForTesting
base mixin MockGetNumberUseCaseMixin implements GetNumberUseCase {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:flutter/foundation.dart';
import 'package:numbers/src/core/core.dart';
import 'package:numbers/src/features/number/number.dart';

final class GetRandomNumberUseCase
implements UseCase<DataState<Number>, Params> {
const GetRandomNumberUseCase({
required NumbersRepository repository,
}) : _numbersRepository = repository;

final NumbersRepository _numbersRepository;

@override
Future<DataState<Number>> call({Params params = const Params()}) =>
_numbersRepository.getRandomNumber();
}

@visibleForTesting
base mixin MockGetRandomNumberUseCaseMixin implements GetRandomNumberUseCase {}
2 changes: 2 additions & 0 deletions lib/src/features/number/domain/use_cases/use_cases.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'get_number_use_case.dart' show GetNumberUseCase;
export 'get_random_number_use_case.dart' show GetRandomNumberUseCase;

This file was deleted.

2 changes: 0 additions & 2 deletions lib/src/features/number/domain/usecases/usecases.dart

This file was deleted.

1 change: 1 addition & 0 deletions test/helpers/extensions/extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'widget_tester_ext.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:numbers/src/core/l10n/l10n.dart';

extension PumpApp on WidgetTester {
extension WidgetTesterExt on WidgetTester {
Future<void> pumpApp(Widget widget) {
return pumpWidget(
MaterialApp(
Expand Down
3 changes: 2 additions & 1 deletion test/helpers/helpers.dart
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export 'pump_app.dart';
export 'extensions/extensions.dart';
export 'mocks/mocks.dart';
4 changes: 4 additions & 0 deletions test/helpers/mocks/mock_dio.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import 'package:dio/dio.dart';
import 'package:mocktail/mocktail.dart';

final class MockDio extends Mock implements Dio {}
4 changes: 4 additions & 0 deletions test/helpers/mocks/mock_get_number_use_case.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import 'package:mocktail/mocktail.dart';
import 'package:numbers/src/features/number/domain/use_cases/get_number_use_case.dart';

final class MockGetNumberUseCase extends Mock with MockGetNumberUseCaseMixin {}
5 changes: 5 additions & 0 deletions test/helpers/mocks/mock_get_random_number_use_case.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:mocktail/mocktail.dart';
import 'package:numbers/src/features/number/domain/use_cases/get_random_number_use_case.dart';

final class MockGetRandomNumberUseCase extends Mock
with MockGetRandomNumberUseCaseMixin {}
4 changes: 4 additions & 0 deletions test/helpers/mocks/mock_numbers_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import 'package:mocktail/mocktail.dart';
import 'package:numbers/src/features/number/number.dart';

final class MockNumbersRepository extends Mock implements NumbersRepository {}
4 changes: 4 additions & 0 deletions test/helpers/mocks/mock_numbers_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import 'package:mocktail/mocktail.dart';
import 'package:numbers/src/features/number/number.dart';

final class MockNumbersService extends Mock implements NumbersService {}
5 changes: 5 additions & 0 deletions test/helpers/mocks/mocks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export 'mock_dio.dart';
export 'mock_get_number_use_case.dart';
export 'mock_get_random_number_use_case.dart';
export 'mock_numbers_repository.dart';
export 'mock_numbers_service.dart';
13 changes: 13 additions & 0 deletions test/src/core/params/get_number_params_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:numbers/src/core/core.dart';

void main() {
group('GetNumberParams', () {
test('extends from Params', () {
expect(
const GetNumberParams(number: 0),
isA<Params>(),
);
});
});
}
13 changes: 13 additions & 0 deletions test/src/core/params/get_theme_params_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:numbers/src/core/core.dart';

void main() {
group('GetThemeParams', () {
test('extends from Params', () {
expect(
const GetThemeParams(key: 'test'),
isA<Params>(),
);
});
});
}
13 changes: 13 additions & 0 deletions test/src/core/params/save_theme_params_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:numbers/src/core/core.dart';

void main() {
group('SaveThemeParams', () {
test('extends from Params', () {
expect(
const SaveThemeParams(key: 'key', value: 'value'),
isA<Params>(),
);
});
});
}
58 changes: 58 additions & 0 deletions test/src/core/resources/data_state_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// ignore_for_file: prefer_const_constructors

import 'package:flutter_test/flutter_test.dart';
import 'package:numbers/src/core/core.dart';

void main() {
group('DataSuccess', () {
test('extends from DataState', () {
expect(
DataSuccess<String>('test'),
isA<DataState<String>>(),
);
});

test('supports value comparisons', () {
expect(
DataSuccess<String>('test'),
equals(DataSuccess<String>('test')),
);
});
});

group('DataFailure', () {
test('extends from DataState', () {
expect(
DataFailure<String>(
ErrorDetails(
error: 'error',
message: 'message',
stackTrace: 'stackTrace',
),
),
isA<DataState<String>>(),
);
});

test('supports value comparisons', () {
expect(
DataFailure<String>(
ErrorDetails(
error: 'error',
message: 'message',
stackTrace: 'stackTrace',
),
),
equals(
DataFailure<String>(
ErrorDetails(
error: 'error',
message: 'message',
stackTrace: 'stackTrace',
),
),
),
);
});
});
}
25 changes: 25 additions & 0 deletions test/src/core/resources/error_details_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ignore_for_file: prefer_const_constructors

import 'package:flutter_test/flutter_test.dart';
import 'package:numbers/src/core/core.dart';

void main() {
group('ErrorDetails', () {
test('supports value comparisons', () {
expect(
ErrorDetails(
error: 'error',
message: 'message',
stackTrace: 'stackTrace',
),
equals(
ErrorDetails(
error: 'error',
message: 'message',
stackTrace: 'stackTrace',
),
),
);
});
});
}
Loading
Loading