diff --git a/mobile/lib/src/features/transactions/services/income/income.dart b/mobile/lib/src/features/transactions/services/income/income.dart index dbd4cf5..d345870 100644 --- a/mobile/lib/src/features/transactions/services/income/income.dart +++ b/mobile/lib/src/features/transactions/services/income/income.dart @@ -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'; @@ -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, ); diff --git a/mobile/lib/src/features/transactions/services/income/income_form_controller.dart b/mobile/lib/src/features/transactions/services/income/income_form_controller.dart index 5ed5b98..d4cbd76 100644 --- a/mobile/lib/src/features/transactions/services/income/income_form_controller.dart +++ b/mobile/lib/src/features/transactions/services/income/income_form_controller.dart @@ -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'; @@ -13,7 +14,8 @@ part 'income_form_controller.g.dart'; @riverpod Future 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); diff --git a/mobile/test/src/features/transactions/presentations/transaction/income/goldens/new_income_detail.png b/mobile/test/src/features/transactions/presentations/transaction/income/goldens/new_income_detail.png new file mode 100644 index 0000000..e134caf Binary files /dev/null and b/mobile/test/src/features/transactions/presentations/transaction/income/goldens/new_income_detail.png differ diff --git a/mobile/test/src/features/transactions/presentations/transaction/income/goldens/update_income_detail.png b/mobile/test/src/features/transactions/presentations/transaction/income/goldens/update_income_detail.png new file mode 100644 index 0000000..69250e7 Binary files /dev/null and b/mobile/test/src/features/transactions/presentations/transaction/income/goldens/update_income_detail.png differ diff --git a/mobile/test/src/features/transactions/presentations/transaction/income/income_detail_view_test.dart b/mobile/test/src/features/transactions/presentations/transaction/income/income_detail_view_test.dart new file mode 100644 index 0000000..f7062d6 --- /dev/null +++ b/mobile/test/src/features/transactions/presentations/transaction/income/income_detail_view_test.dart @@ -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'); + }); +} diff --git a/mobile/test/src/features/transactions/services/income/income_form_controller_test.dart b/mobile/test/src/features/transactions/services/income/income_form_controller_test.dart index 3ff7a54..5546c5a 100644 --- a/mobile/test/src/features/transactions/services/income/income_form_controller_test.dart +++ b/mobile/test/src/features/transactions/services/income/income_form_controller_test.dart @@ -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'); @@ -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'; diff --git a/mobile/test/src/features/transactions/transactions_robot.dart b/mobile/test/src/features/transactions/transactions_robot.dart index 1d57928..e1f403f 100644 --- a/mobile/test/src/features/transactions/transactions_robot.dart +++ b/mobile/test/src/features/transactions/transactions_robot.dart @@ -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'; @@ -68,6 +70,32 @@ class TransactionsRobot { ); } + Future 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); }