Skip to content

Commit

Permalink
Merge pull request #349 from wakamenod/346-mobile-トランザクション-メモuiテスト追加
Browse files Browse the repository at this point in the history
[Mobile] トランザクション メモUIテスト追加 #346
  • Loading branch information
wakamenod authored Jul 24, 2023
2 parents a036167 + 812ff08 commit 681eabe
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:suito/i18n/translations.g.dart';
import 'package:suito/src/app.dart';
import 'package:suito/src/features/transactions/services/expense/expense_form_controller.dart';
import 'package:suito/src/routing/app_router.dart';

class ExpenseMemoScreen extends ConsumerStatefulWidget {
const ExpenseMemoScreen({super.key});
Expand All @@ -11,7 +13,10 @@ class ExpenseMemoScreen extends ConsumerStatefulWidget {
}

class _ExpenseMemoScreenState extends ConsumerState<ExpenseMemoScreen> {
final TextEditingController _textEditingController = TextEditingController();
late final TextEditingController _textEditingController =
TextEditingController(
text: ref.watch(
expenseFormControllerProvider.select((value) => value.memo)));

@override
void dispose() {
Expand All @@ -25,22 +30,25 @@ class _ExpenseMemoScreenState extends ConsumerState<ExpenseMemoScreen> {
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => context.pop(_textEditingController.text)),
onPressed: () => ref
.read(goRouterProvider(navigatorKey))
.pop(_textEditingController.text)),
title: Text(t.transactions.memo.title),
),
body: Column(
children: [
TextField(
controller: _textEditingController,
maxLines: null,
minLines: 5,
keyboardType: TextInputType.multiline,
decoration: InputDecoration(
border: const OutlineInputBorder(),
hintText: t.transactions.memo.hintText,
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: _textEditingController,
maxLines: null,
minLines: 5,
keyboardType: TextInputType.multiline,
decoration: InputDecoration(
border: const OutlineInputBorder(),
hintText: t.transactions.memo.hintText,
fillColor: Colors.white70,
filled: true,
),
],
),
),
);
}
Expand Down
49 changes: 49 additions & 0 deletions mobile/test/src/features/transactions/memo_robot.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:suito/src/app_theme.dart';
import 'package:suito/src/features/transactions/presentations/expense/expense_memo_screen.dart';
import 'package:suito/src/features/transactions/services/expense/expense_form_controller.dart';
import 'package:suito/src/features/transactions/services/expense/expense_form_value.dart';
import 'package:suito/src/routing/app_router.dart';

class MemoRobot {
MemoRobot(this.tester);
final WidgetTester tester;

Future<void> pumpMemoScreen(ExpenseFormValue value,
{GoRouter? router}) async {
await tester.pumpWidget(
ProviderScope(
overrides: [
expenseFormInitialValueProvider.overrideWith((ref) => value),
if (router != null)
goRouterProvider.overrideWith((ref, arg) => router),
],
child: MaterialApp(
home: const ExpenseMemoScreen(), theme: AppTheme().create()),
),
);
await tester.pumpAndSettle();
}

void expectMemoFieldFound() {
final memoField = find.byType(TextField);
expect(memoField, findsOneWidget);
}

Future<void> enterMemo(String memo) async {
final memoField = find.byType(TextField);
expect(memoField, findsOneWidget);
await tester.enterText(memoField, memo);
await tester.pump();
}

Future<void> tapBackButton() async {
final backButton = find.byIcon(Icons.arrow_back);
expect(backButton, findsOneWidget);
await tester.tap(backButton);
await tester.pump();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:golden_toolkit/golden_toolkit.dart';
import 'package:mocktail/mocktail.dart';
import 'package:suito/src/features/transactions/services/expense/expense_form_value.dart';
import 'package:suito/src/formz/amount.dart';
import 'package:suito/src/formz/title.dart';

import '../../../../../mocks.dart';
import '../../../memo_robot.dart';

void main() {
group('ExpenseMemoScreen Golden test group', () {
testGoldens('Open blank memo screen', (tester) async {
await loadAppFonts();
final r = MemoRobot(tester);
final now = DateTime(2023, 5, 1);
await r.pumpMemoScreen(ExpenseFormValue.newExpense(now));
await screenMatchesGolden(tester, 'blank_memo_screen');
});

testGoldens('Open non blank memo screen', (tester) async {
await loadAppFonts();
final r = MemoRobot(tester);
const memo =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tincidunt facilisis sollicitudin. Vivamus quis convallis ipsum. Nulla malesuada nunc ipsum, lobortis iaculis dolor egestas eu. Quisque aliquam cursus erat ornare tincidunt. Nunc venenatis tellus hendrerit quam viverra, sit amet iaculis dolor lacinia. Quisque ac sapien non nulla sodales facilisis non ac nunc. Sed quis tristique lorem. Suspendisse condimentum ultricies ante, eget faucibus nunc tristique ac. Maecenas turpis elit, iaculis vitae eros ac, ullamcorper placerat velit. Morbi et quam augue. Nunc at nulla nec ligula semper ultricies.";
await r.pumpMemoScreen(const ExpenseFormValue(
memo: memo,
id: 'test_id',
title: Title.pure(),
locationID: '',
categoryID: '',
category: '',
amount: Amount.pure(),
location: '',
isValid: true,
date: ''));
await screenMatchesGolden(tester, 'non_blank_memo_screen');
});
});

group('ExpenseMemoScreen', () {
testWidgets("Open memo, fill in the text form, then pop the screen",
(tester) async {
final r = MemoRobot(tester);
final now = DateTime(2023, 5, 1);
final router = MockGoRouter();
await r.pumpMemoScreen(ExpenseFormValue.newExpense(now), router: router);
r.expectMemoFieldFound();
const testMemo = 'This is a test memo';
await r.enterMemo(testMemo);
await r.tapBackButton();
verify(() => router.pop(testMemo)).called(1);
});
});
}
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.

0 comments on commit 681eabe

Please sign in to comment.