Skip to content

Commit

Permalink
Merge pull request #342 from wakamenod/339-mobile-test-収入詳細uiテスト追加
Browse files Browse the repository at this point in the history
[Mobile] [Test] 収入詳細UIテスト追加 #339
  • Loading branch information
wakamenod authored Jul 22, 2023
2 parents acde1bf + 788114b commit cf9b03e
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:openapi/openapi.dart';
import 'package:suito/src/formz/amount.dart';
import 'package:suito/src/formz/title.dart';
import 'package:suito/src/utils/datetime_utils.dart';

part 'income.freezed.dart';

Expand All @@ -21,12 +22,12 @@ class Income with _$Income {

bool get isNew => id == '';

static Income init() => const Income(
static Income init(DateTime now) => Income(
id: '',
incomeTypeID: '',
title: Title.pure(),
amount: Amount.pure(),
date: '',
title: const Title.pure(),
amount: const Amount.pure(),
date: now.toRfc3339(),
memo: '',
isValid: false,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:suito/src/features/transactions/repositories/income/income_detai
import 'package:suito/src/features/transactions/repositories/income/income_types_repository.dart';
import 'package:suito/src/formz/amount.dart';
import 'package:suito/src/formz/title.dart' as formz_title;
import 'package:suito/src/utils/datetime_utils.dart';

import 'income.dart';

Expand All @@ -13,7 +14,8 @@ part 'income_form_controller.g.dart';
@riverpod
Future<Income> incomeFuture(IncomeFutureRef ref, {String? id}) async {
if (id == null) {
return Income.init();
final now = ref.watch(currentTimeProvider);
return Income.init(now);
}

final incomeTypeMap = await ref.read(incomeTypeMapFutureProvider.future);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:golden_toolkit/golden_toolkit.dart';
import 'package:mocktail/mocktail.dart';
import 'package:openapi/openapi.dart';

import '../../../../../mocks.dart';
import '../../../transactions_robot.dart';

void main() {
// TODO エラー時の表示テスト追加

group('IncomeDetailView Golden test group', () {
testGoldens('Open IncomeDetailView as registration for new income',
(tester) async {
await loadAppFonts();
final r = TransactionsRobot(tester);
final now = DateTime(2023, 5, 1);
await r.pumpIncomeDetailScreen(id: null, now: now);
await screenMatchesGolden(tester, 'new_income_detail');
});
});

testGoldens('Open IncomeDetailView for updating a registered income',
(tester) async {
await loadAppFonts();
final r = TransactionsRobot(tester);
final now = DateTime(2023, 5, 1);
final repository = MockIncomeDetailRepository();
final incomeTypeRepo = MockIncomeTypesRepository();
const id = 'income_id';
final incomeType = ModelIncomeType((e) => e
..id = 'income_type_id'
..name = 'Test Income Type');
final res = IncomeDetailRes((r) => r.income.replace(ModelIncome((b) => b
..id = id
..localDate = '2023-05-03'
..memo = 'some memo'
..amount = 400
..incomeTypeId = incomeType.id)));
when(() => repository.fetchIncomeDetail(id))
.thenAnswer((invocation) => Future.value(res));
when(() => incomeTypeRepo.fetchIncomeTypesList())
.thenAnswer((invocation) => Future.value([incomeType]));
await r.pumpIncomeDetailScreen(
incomeRepo: repository,
incomeTypeRepo: incomeTypeRepo,
id: id,
now: now);
await screenMatchesGolden(tester, 'update_income_detail');
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void main() {
group('incomeFormController', () {
test('register new income - validation valid', () async {
final container = makeProviderContainer();
final exp = Income.init();
final exp = Income.init(DateTime.now());
final controller =
container.read(incomeFormControllerProvider(exp).notifier);
final incomeType = AttributeEntry('income_type_id', 'Income Title');
Expand All @@ -58,7 +58,7 @@ void main() {

test('register new income - validation invalid', () async {
final container = makeProviderContainer();
final exp = Income.init();
final exp = Income.init(DateTime.now());
final controller =
container.read(incomeFormControllerProvider(exp).notifier);
const memo = 'Memo';
Expand Down
28 changes: 28 additions & 0 deletions mobile/test/src/features/transactions/transactions_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:suito/src/features/transactions/presentations/transactions_scree
import 'package:suito/src/features/transactions/repositories/expense/expense_categories_repository.dart';
import 'package:suito/src/features/transactions/repositories/expense/expense_detail_repository.dart';
import 'package:suito/src/features/transactions/repositories/expense/expense_locations_repository.dart';
import 'package:suito/src/features/transactions/repositories/income/income_detail_repository.dart';
import 'package:suito/src/features/transactions/repositories/income/income_types_repository.dart';
import 'package:suito/src/features/transactions/repositories/transaction/transaction_months_repository.dart';
import 'package:suito/src/features/transactions/repositories/transaction/transactions_repository.dart';
import 'package:suito/src/features/transactions/services/transaction/transaction_service.dart';
Expand Down Expand Up @@ -68,6 +70,32 @@ class TransactionsRobot {
);
}

Future<void> pumpIncomeDetailScreen(
{IncomeDetailRepository? incomeRepo,
IncomeTypesRepository? incomeTypeRepo,
required String? id,
required DateTime now}) async {
await tester.pumpWidget(
ProviderScope(
overrides: [
currentTimeProvider.overrideWithValue(now),
if (incomeRepo != null)
incomeDetailRepositoryProvider.overrideWithValue(incomeRepo),
if (incomeTypeRepo != null)
incomeTypesRepositoryProvider.overrideWithValue(
incomeTypeRepo,
)
],
child: MaterialApp(
home: TransactionDetailScreen(
id: id,
type: TransactionType.income.value,
),
theme: AppTheme().create()),
),
);
}

void expectEmptyLabelFound() {
expect(find.byType(TransactionsListEmptyLabel), findsOneWidget);
}
Expand Down

0 comments on commit cf9b03e

Please sign in to comment.