Skip to content

Commit

Permalink
Merge pull request #353 from wakamenod/352-mobile-test-支出スケジュール詳細uiテスト追加
Browse files Browse the repository at this point in the history
[Mobile] [Test] 支出スケジュール詳細UIテスト追加 #352
  • Loading branch information
wakamenod authored Jul 24, 2023
2 parents cff3723 + 3765926 commit 91b5c07
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
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:openapi/openapi.dart';
import 'package:suito/src/features/transactions/services/expense/expense_form_value.dart';

import '../../schedules_robot.dart';

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

group('ExpenseScheduleDetail Golden test group', () {
testGoldens('Open ExpenseDetailView as registration for new expense',
(tester) async {
await loadAppFonts();
final r = SchedulesRobot(tester);
final now = DateTime(2023, 5, 1);
final expense = ExpenseFormValue.newExpense(now);
await r.pumpExpenseDetailScreen(expense);
await screenMatchesGolden(tester, 'new_expense_schedule_detail');
});

testGoldens('Open ExpenseScheduleDetailView for updating a registered expense schedule',
(tester) async {
await loadAppFonts();
final r = SchedulesRobot(tester);
const id = 'expense_schedule_id';
final category = ModelExpenseCategory((e) => e
..id = 'expense_category_id'
..name = 'Test Category');
final categoryMap = {category.id: category};
final location = ModelExpenseLocation((e) => e
..id = 'expense_location_id'
..name = 'Test Location');
final locationMap = {location.id: location};
final res =
ExpenseScheduleDetailRes((r) => r.expenseSchedule.replace(ModelExpenseSchedule((b) => b
..id = id
..timezone = 'Asia/Tokyo'
..title = 'registered title'
..memo = 'Some memo'
..amount = 400
..expenseCategoryID = category.id
..expenseLocationID = location.id)));

final expense =
ExpenseFormValue.fromSchedule(res, categoryMap, locationMap);
await r.pumpExpenseDetailScreen(expense);
await screenMatchesGolden(tester, 'update_expense_schedule_detail');
});
});
}
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.
26 changes: 26 additions & 0 deletions mobile/test/src/features/schedules/schedules_robot.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:suito/src/app_theme.dart';
import 'package:suito/src/features/schedules/presentations/expense/expense_schedule_detail_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';

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

Future<void> pumpExpenseDetailScreen(ExpenseFormValue value) async {
await tester.pumpWidget(
ProviderScope(
overrides: [
expenseFormInitialValueProvider.overrideWith((ref) => value),
],
child: MaterialApp(
home: const ExpenseScheduleDetailScreen(),
theme: AppTheme().create()),
),
);
await tester.pumpAndSettle();
}
}

0 comments on commit 91b5c07

Please sign in to comment.