-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #349 from wakamenod/346-mobile-トランザクション-メモuiテスト追加
[Mobile] トランザクション メモUIテスト追加 #346
- Loading branch information
Showing
5 changed files
with
127 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...src/features/transactions/presentations/transaction/expense/expense_memo_screen_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
} |
Binary file added
BIN
+50.3 KB
...es/transactions/presentations/transaction/expense/goldens/blank_memo_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+265 KB
...ransactions/presentations/transaction/expense/goldens/non_blank_memo_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.