Skip to content

Commit

Permalink
[Mobile] [Test] スケジュール一覧UIテスト追加 #356
Browse files Browse the repository at this point in the history
  • Loading branch information
wakamenod committed Jul 24, 2023
1 parent aaf6fbd commit 69159cf
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
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,46 @@
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 '../schedules_robot.dart';

void main() {
group('ScheduleScreen Golden test group', () {
testGoldens('Empty list', (tester) async {
await loadAppFonts();
final r = SchedulesRobot(tester);
final res = ListTransactionSchedulesRes();
final repository = MockSchedulesRepository();
when(() => repository.fetchSchedulesList())
.thenAnswer((_) => Future.value(res));
await r.pumpSchedulesScreen(repository: repository);
await screenMatchesGolden(tester, 'empty_list');
});

testGoldens('Non Empty list', (tester) async {
await loadAppFonts();
final r = SchedulesRobot(tester);
final res = ListTransactionSchedulesRes((r) => r
..incomeSchedules.replace([
TransactionSchedule((t) => t
..id = 'income_schedule_id'
..amount = 400
..title = 'Income Title')
])
..expenseSchedules.replace([
TransactionSchedule((t) => t
..id = 'expense_schedule_id'
..amount = 400
..title = 'Expense Title')
]));
final repository = MockSchedulesRepository();
when(() => repository.fetchSchedulesList())
.thenAnswer((_) => Future.value(res));
await r.pumpSchedulesScreen(repository: repository);
await screenMatchesGolden(tester, 'non_empty_list');
});

});
}
19 changes: 19 additions & 0 deletions mobile/test/src/features/schedules/schedules_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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/schedules/presentations/income/income_schedule_detail_screen.dart';
import 'package:suito/src/features/schedules/presentations/schedule_screen.dart';
import 'package:suito/src/features/schedules/repositories/schedules_repository.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/features/transactions/services/income/income_form_controller.dart';
Expand Down Expand Up @@ -40,4 +42,21 @@ class SchedulesRobot {
);
await tester.pumpAndSettle();
}

Future<void> pumpSchedulesScreen(
{SchedulesRepository? repository,
}) async {
await tester.pumpWidget(
ProviderScope(
overrides: [
if (repository != null)
schedulesRepositoryProvider.overrideWithValue(repository)
],
child: MaterialApp(
home: const ScheduleScreen(), theme: AppTheme().create()),
),
);
await tester.pumpAndSettle();
}

}

0 comments on commit 69159cf

Please sign in to comment.