forked from eatvio/eatvio_app
feat: implement recipe drafting functionality and refactor MyRecipesTab to be stateless
This commit is contained in:
@@ -10,8 +10,15 @@ import 'package:eatvio_app/features/create_recipe/services/recipe_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
|
||||
class MockCreateRecipeService extends Mock implements CreateRecipeService {}
|
||||
|
||||
final mockHttpResponse = HttpResponse(
|
||||
null,
|
||||
Response(requestOptions: RequestOptions(path: ''), statusCode: 200),
|
||||
);
|
||||
|
||||
void main() {
|
||||
setUpAll(() {
|
||||
registerFallbackValue(FormData());
|
||||
@@ -109,7 +116,7 @@ void main() {
|
||||
test('deleteRecipe - удаляет рецепт', () async {
|
||||
const slug = 'recipe-slug';
|
||||
|
||||
when(() => mockService.deleteRecipe(slug: slug)).thenAnswer((_) async => Future.value());
|
||||
when(() => mockService.deleteRecipe(slug: slug)).thenAnswer((_) async => Future.value(mockHttpResponse));
|
||||
|
||||
await repository.deleteRecipe(slug);
|
||||
|
||||
@@ -188,7 +195,7 @@ void main() {
|
||||
// Мокируем ImageCompressUtility.compressFile
|
||||
// Это сложно, так как это статический метод, но мы можем проверить, что вызывается updateRecipe
|
||||
when(() => mockService.updateRecipe(slug: slug, formData: any(named: 'formData')))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
.thenAnswer((_) async => Future.value(mockHttpResponse));
|
||||
|
||||
// Этот тест может упасть из-за ImageCompressUtility, но мы проверяем логику
|
||||
try {
|
||||
@@ -216,7 +223,7 @@ void main() {
|
||||
);
|
||||
|
||||
when(() => mockService.publishRecipe(formData: any(named: 'formData')))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
.thenAnswer((_) async => Future.value(mockHttpResponse));
|
||||
|
||||
try {
|
||||
await repository.publishRecipe(recipe);
|
||||
@@ -243,7 +250,7 @@ void main() {
|
||||
);
|
||||
|
||||
when(() => mockService.publishRecipe(formData: any(named: 'formData')))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
.thenAnswer((_) async => Future.value(mockHttpResponse));
|
||||
|
||||
try {
|
||||
await repository.publishRecipe(recipe);
|
||||
@@ -270,7 +277,7 @@ void main() {
|
||||
);
|
||||
|
||||
when(() => mockService.publishRecipe(formData: any(named: 'formData')))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
.thenAnswer((_) async => Future.value(mockHttpResponse));
|
||||
|
||||
try {
|
||||
await repository.publishRecipe(recipe);
|
||||
@@ -297,7 +304,7 @@ void main() {
|
||||
);
|
||||
|
||||
when(() => mockService.publishRecipe(formData: any(named: 'formData')))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
.thenAnswer((_) async => Future.value(mockHttpResponse));
|
||||
|
||||
try {
|
||||
await repository.publishRecipe(recipe);
|
||||
@@ -364,7 +371,7 @@ void main() {
|
||||
);
|
||||
|
||||
when(() => mockService.publishRecipe(formData: any(named: 'formData')))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
.thenAnswer((_) async => Future.value(mockHttpResponse));
|
||||
|
||||
try {
|
||||
await repository.publishRecipe(recipe);
|
||||
@@ -399,7 +406,7 @@ void main() {
|
||||
);
|
||||
|
||||
when(() => mockService.publishRecipe(formData: any(named: 'formData')))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
.thenAnswer((_) async => Future.value(mockHttpResponse));
|
||||
|
||||
try {
|
||||
await repository.publishRecipe(recipe);
|
||||
@@ -435,7 +442,7 @@ void main() {
|
||||
);
|
||||
|
||||
when(() => mockService.publishRecipe(formData: any(named: 'formData')))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
.thenAnswer((_) async => Future.value(mockHttpResponse));
|
||||
|
||||
try {
|
||||
await repository.publishRecipe(recipe);
|
||||
@@ -472,7 +479,7 @@ void main() {
|
||||
);
|
||||
|
||||
when(() => mockService.publishRecipe(formData: any(named: 'formData')))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
.thenAnswer((_) async => Future.value(mockHttpResponse));
|
||||
|
||||
try {
|
||||
await repository.publishRecipe(recipe);
|
||||
@@ -499,7 +506,7 @@ void main() {
|
||||
);
|
||||
|
||||
when(() => mockService.publishRecipe(formData: any(named: 'formData')))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
.thenAnswer((_) async => Future.value(mockHttpResponse));
|
||||
|
||||
try {
|
||||
await repository.publishRecipe(recipe);
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('MyRecipesTab smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
Widget wrap() {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
@@ -17,12 +17,17 @@ void main() {
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Scaffold(body: child),
|
||||
home: Material(
|
||||
child: MyRecipesTab(
|
||||
selectedIndex: 0,
|
||||
onTabChanged: (_) {},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders my recipes tab', (tester) async {
|
||||
await tester.pumpWidget(wrap(const MyRecipesTab()));
|
||||
await tester.pumpWidget(wrap());
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(MyRecipesTab), findsOneWidget);
|
||||
|
||||
Reference in New Issue
Block a user