-
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 #326 from wakamenod/325-mobile-test-トランザクション削除-テスト追加
[Mobile] [Test] トランザクション削除 テスト追加 #325
- Loading branch information
Showing
8 changed files
with
267 additions
and
16 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
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
85 changes: 85 additions & 0 deletions
85
...test/src/features/schedules/services/expense/delete_expense_schedule_controller_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,85 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:suito/src/features/schedules/repositories/expense/delete_expense_schedule_repository.dart'; | ||
import 'package:suito/src/features/schedules/services/expense/delete_expense_schedule_controller.dart'; | ||
|
||
import '../../../../mocks.dart'; | ||
|
||
void main() { | ||
ProviderContainer makeProviderContainer( | ||
MockDeleteExpenseScheduleRepository repo) { | ||
final container = ProviderContainer( | ||
overrides: [ | ||
deleteExpenseScheduleRepositoryProvider.overrideWithValue(repo), | ||
], | ||
); | ||
addTearDown(container.dispose); | ||
return container; | ||
} | ||
|
||
setUpAll(() { | ||
registerFallbackValue(const AsyncLoading<int>()); | ||
}); | ||
|
||
group('deleteExpenseScheduleController', () { | ||
test('delete expense schedule, success', () async { | ||
// setup | ||
const scheduleID = 'test_expense_schedule_id'; | ||
final deleteRepo = MockDeleteExpenseScheduleRepository(); | ||
when(() => deleteRepo.deleteExpenseSchedule(scheduleID)).thenAnswer( | ||
(_) => Future.value(null), | ||
); | ||
final container = makeProviderContainer(deleteRepo); | ||
final controller = | ||
container.read(deleteExpenseScheduleControllerProvider.notifier); | ||
final listener = Listener<AsyncValue<void>>(); | ||
container.listen( | ||
deleteExpenseScheduleControllerProvider, | ||
listener, | ||
fireImmediately: true, | ||
); | ||
const data = AsyncData<void>(null); | ||
verify(() => listener(null, data)); | ||
// run | ||
await controller.deleteExpenseSchedule(scheduleID); | ||
// verify | ||
verifyInOrder([ | ||
() => listener(data, any(that: isA<AsyncLoading>())), | ||
() => listener(any(that: isA<AsyncLoading>()), data), | ||
]); | ||
verifyNoMoreInteractions(listener); | ||
verify(() => deleteRepo.deleteExpenseSchedule(scheduleID)).called(1); | ||
}); | ||
|
||
test('delete expense schedule, failure', () async { | ||
// setup | ||
const scheduleID = 'test_expense_schedule_id'; | ||
final deleteRepo = MockDeleteExpenseScheduleRepository(); | ||
when(() => deleteRepo.deleteExpenseSchedule(scheduleID)).thenThrow( | ||
(_) => Exception('Connection failed'), | ||
); | ||
final container = makeProviderContainer(deleteRepo); | ||
final controller = | ||
container.read(deleteExpenseScheduleControllerProvider.notifier); | ||
final listener = Listener<AsyncValue<void>>(); | ||
container.listen( | ||
deleteExpenseScheduleControllerProvider, | ||
listener, | ||
fireImmediately: true, | ||
); | ||
const data = AsyncData<void>(null); | ||
verify(() => listener(null, data)); | ||
// run | ||
await controller.deleteExpenseSchedule(scheduleID); | ||
// verify | ||
verifyInOrder([ | ||
() => listener(data, any(that: isA<AsyncLoading>())), | ||
() => listener( | ||
any(that: isA<AsyncLoading>()), any(that: isA<AsyncError>())), | ||
]); | ||
verifyNoMoreInteractions(listener); | ||
verify(() => deleteRepo.deleteExpenseSchedule(scheduleID)).called(1); | ||
}); | ||
}); | ||
} |
85 changes: 85 additions & 0 deletions
85
...e/test/src/features/schedules/services/income/delete_income_schedule_controller_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,85 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:suito/src/features/schedules/repositories/income/delete_income_schedule_repository.dart'; | ||
import 'package:suito/src/features/schedules/services/income/delete_income_schedule_controller.dart'; | ||
|
||
import '../../../../mocks.dart'; | ||
|
||
void main() { | ||
ProviderContainer makeProviderContainer( | ||
MockDeleteIncomeScheduleRepository repo) { | ||
final container = ProviderContainer( | ||
overrides: [ | ||
deleteIncomeScheduleRepositoryProvider.overrideWithValue(repo), | ||
], | ||
); | ||
addTearDown(container.dispose); | ||
return container; | ||
} | ||
|
||
setUpAll(() { | ||
registerFallbackValue(const AsyncLoading<int>()); | ||
}); | ||
|
||
group('deleteIncomeScheduleController', () { | ||
test('delete income schedule, success', () async { | ||
// setup | ||
const scheduleID = 'test_income_schedule_id'; | ||
final deleteRepo = MockDeleteIncomeScheduleRepository(); | ||
when(() => deleteRepo.deleteIncomeSchedule(scheduleID)).thenAnswer( | ||
(_) => Future.value(null), | ||
); | ||
final container = makeProviderContainer(deleteRepo); | ||
final controller = | ||
container.read(deleteIncomeScheduleControllerProvider.notifier); | ||
final listener = Listener<AsyncValue<void>>(); | ||
container.listen( | ||
deleteIncomeScheduleControllerProvider, | ||
listener, | ||
fireImmediately: true, | ||
); | ||
const data = AsyncData<void>(null); | ||
verify(() => listener(null, data)); | ||
// run | ||
await controller.deleteIncomeSchedule(scheduleID); | ||
// verify | ||
verifyInOrder([ | ||
() => listener(data, any(that: isA<AsyncLoading>())), | ||
() => listener(any(that: isA<AsyncLoading>()), data), | ||
]); | ||
verifyNoMoreInteractions(listener); | ||
verify(() => deleteRepo.deleteIncomeSchedule(scheduleID)).called(1); | ||
}); | ||
|
||
test('delete income schedule, failure', () async { | ||
// setup | ||
const scheduleID = 'test_income_schedule_id'; | ||
final deleteRepo = MockDeleteIncomeScheduleRepository(); | ||
when(() => deleteRepo.deleteIncomeSchedule(scheduleID)).thenThrow( | ||
(_) => Exception('Connection failed'), | ||
); | ||
final container = makeProviderContainer(deleteRepo); | ||
final controller = | ||
container.read(deleteIncomeScheduleControllerProvider.notifier); | ||
final listener = Listener<AsyncValue<void>>(); | ||
container.listen( | ||
deleteIncomeScheduleControllerProvider, | ||
listener, | ||
fireImmediately: true, | ||
); | ||
const data = AsyncData<void>(null); | ||
verify(() => listener(null, data)); | ||
// run | ||
await controller.deleteIncomeSchedule(scheduleID); | ||
// verify | ||
verifyInOrder([ | ||
() => listener(data, any(that: isA<AsyncLoading>())), | ||
() => listener( | ||
any(that: isA<AsyncLoading>()), any(that: isA<AsyncError>())), | ||
]); | ||
verifyNoMoreInteractions(listener); | ||
verify(() => deleteRepo.deleteIncomeSchedule(scheduleID)).called(1); | ||
}); | ||
}); | ||
} |
84 changes: 84 additions & 0 deletions
84
mobile/test/src/features/transactions/services/expense/delete_expense_controller_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,84 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:suito/src/features/transactions/repositories/expense/delete_expense_repository.dart'; | ||
import 'package:suito/src/features/transactions/services/expense/delete_expense_controller.dart'; | ||
|
||
import '../../../../mocks.dart'; | ||
|
||
void main() { | ||
ProviderContainer makeProviderContainer(MockDeleteExpenseRepository repo) { | ||
final container = ProviderContainer( | ||
overrides: [ | ||
deleteExpenseRepositoryProvider.overrideWithValue(repo), | ||
], | ||
); | ||
addTearDown(container.dispose); | ||
return container; | ||
} | ||
|
||
setUpAll(() { | ||
registerFallbackValue(const AsyncLoading<int>()); | ||
}); | ||
|
||
group('deleteExpenseController', () { | ||
test('delete expense, success', () async { | ||
// setup | ||
const expenseID = 'test_expense_id'; | ||
final deleteRepo = MockDeleteExpenseRepository(); | ||
when(() => deleteRepo.deleteExpense(expenseID)).thenAnswer( | ||
(_) => Future.value(null), | ||
); | ||
final container = makeProviderContainer(deleteRepo); | ||
final controller = | ||
container.read(deleteExpenseControllerProvider.notifier); | ||
final listener = Listener<AsyncValue<void>>(); | ||
container.listen( | ||
deleteExpenseControllerProvider, | ||
listener, | ||
fireImmediately: true, | ||
); | ||
const data = AsyncData<void>(null); | ||
verify(() => listener(null, data)); | ||
// run | ||
await controller.deleteExpense(expenseID); | ||
// verify | ||
verifyInOrder([ | ||
() => listener(data, any(that: isA<AsyncLoading>())), | ||
() => listener(any(that: isA<AsyncLoading>()), data), | ||
]); | ||
verifyNoMoreInteractions(listener); | ||
verify(() => deleteRepo.deleteExpense(expenseID)).called(1); | ||
}); | ||
|
||
test('delete expense, failure', () async { | ||
// setup | ||
const expenseID = 'test_expense_id'; | ||
final deleteRepo = MockDeleteExpenseRepository(); | ||
when(() => deleteRepo.deleteExpense(expenseID)).thenThrow( | ||
(_) => Exception('Connection failed'), | ||
); | ||
final container = makeProviderContainer(deleteRepo); | ||
final controller = | ||
container.read(deleteExpenseControllerProvider.notifier); | ||
final listener = Listener<AsyncValue<void>>(); | ||
container.listen( | ||
deleteExpenseControllerProvider, | ||
listener, | ||
fireImmediately: true, | ||
); | ||
const data = AsyncData<void>(null); | ||
verify(() => listener(null, data)); | ||
// run | ||
await controller.deleteExpense(expenseID); | ||
// verify | ||
verifyInOrder([ | ||
() => listener(data, any(that: isA<AsyncLoading>())), | ||
() => listener( | ||
any(that: isA<AsyncLoading>()), any(that: isA<AsyncError>())), | ||
]); | ||
verifyNoMoreInteractions(listener); | ||
verify(() => deleteRepo.deleteExpense(expenseID)).called(1); | ||
}); | ||
}); | ||
} |
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