forked from eatvio/eatvio_app
feat(tests): added new tests and updated fixtures
This commit is contained in:
@@ -67,5 +67,39 @@ void main() {
|
||||
|
||||
expect(find.byType(CreateDietScreenContent), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders create diet screen with loading state', (tester) async {
|
||||
final cubit = MockCreateDietCubit();
|
||||
final state = CreateDietState.initial().copyWith(isLoading: true);
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.setInitialData(any)).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
sl.registerLazySingleton<CreateDietCubit>(() => cubit);
|
||||
|
||||
await tester.pumpWidget(wrap(const CreateDietScreenContent(), cubit));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(CreateDietScreenContent), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders create diet screen with diet publishing state', (tester) async {
|
||||
final cubit = MockCreateDietCubit();
|
||||
final state = CreateDietState.initial().copyWith(isDietPublishing: true);
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.setInitialData(any)).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
sl.registerLazySingleton<CreateDietCubit>(() => cubit);
|
||||
|
||||
await tester.pumpWidget(wrap(const CreateDietScreenContent(), cubit));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(CreateDietScreenContent), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:eatvio_app/features/create_diet/repositories/create_diet_reposit
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/glossary/models/glossary_model.dart';
|
||||
import 'package:eatvio_app/features/glossary/repositories/glossary_repository.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||
@@ -236,6 +237,51 @@ void main() {
|
||||
expect(result, null);
|
||||
});
|
||||
|
||||
test('getDietForPreview returns Diet when form is valid', () async {
|
||||
const profile = ProfileModel(
|
||||
id: 1,
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
slug: 'test-user',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: 'https://example.com/photo.jpg',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
when(profileRepository.getMyProfile()).thenAnswer((_) async => profile);
|
||||
|
||||
cubit.setName('Test Diet');
|
||||
cubit.setDetails('Test Description');
|
||||
cubit.setDuration(0);
|
||||
cubit.setDietState(DietState.active);
|
||||
const portion = DailySchedule(
|
||||
name: 'Apple',
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: 1,
|
||||
);
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
cubit.setImage(null, imageUrl: 'https://example.com/cover.jpg');
|
||||
|
||||
final result = await cubit.getDietForPreview();
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.name, 'Test Diet');
|
||||
expect(result.details, 'Test Description');
|
||||
expect(result.duration, 7);
|
||||
expect(result.author.authorName, 'Test User');
|
||||
expect(result.author.authorSlug, 'test-user');
|
||||
verify(profileRepository.getMyProfile()).called(1);
|
||||
});
|
||||
|
||||
test('createDiet returns validation error when form is invalid', () async {
|
||||
final result = await cubit.createDiet();
|
||||
expect(result, 'validation');
|
||||
@@ -257,7 +303,7 @@ void main() {
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
productNutritionalValueId: 1,
|
||||
);
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
// Set image with non-existent file to trigger error in compression
|
||||
@@ -280,7 +326,7 @@ void main() {
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
productNutritionalValueId: 1,
|
||||
);
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
final image = XFile('test_image.jpg');
|
||||
@@ -302,7 +348,7 @@ void main() {
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
productNutritionalValueId: 1,
|
||||
);
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
final image = XFile('test_image.jpg');
|
||||
@@ -321,7 +367,7 @@ void main() {
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
productNutritionalValueId: 1,
|
||||
);
|
||||
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
@@ -336,7 +382,7 @@ void main() {
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
productNutritionalValueId: 1,
|
||||
);
|
||||
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
@@ -405,7 +451,7 @@ void main() {
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
productNutritionalValueId: 1,
|
||||
);
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
final image = XFile('test_image.jpg');
|
||||
@@ -427,7 +473,7 @@ void main() {
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
productNutritionalValueId: 1,
|
||||
);
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
final image = XFile('test_image.jpg');
|
||||
@@ -448,7 +494,7 @@ void main() {
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
productNutritionalValueId: 1,
|
||||
);
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
final image = XFile('test_image.jpg');
|
||||
@@ -469,7 +515,7 @@ void main() {
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
productNutritionalValueId: 1,
|
||||
);
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
final image = XFile('test_image.jpg');
|
||||
@@ -491,7 +537,7 @@ void main() {
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
productNutritionalValueId: 1,
|
||||
);
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
|
||||
@@ -522,7 +568,7 @@ void main() {
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
productNutritionalValueId: 1,
|
||||
);
|
||||
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
@@ -546,7 +592,7 @@ void main() {
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
productNutritionalValueId: 1,
|
||||
);
|
||||
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
|
||||
@@ -63,7 +63,7 @@ void main() {
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
await tester.pumpWidget(wrap(DietPreviewScreen(diet: testDiet)));
|
||||
await tester.pumpWidget(wrap(DietPreviewScreen(diet: testDiet, isImageInBase64: true)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(DietPreviewScreen), findsOneWidget);
|
||||
@@ -103,7 +103,7 @@ void main() {
|
||||
dailyNutrition: [const DailyNutrition(energy: 2000.0, proteins: 100.0, fats: 50.0, carbohydrates: 200.0)],
|
||||
);
|
||||
|
||||
await tester.pumpWidget(wrap(DietPreviewScreen(diet: testDiet)));
|
||||
await tester.pumpWidget(wrap(DietPreviewScreen(diet: testDiet, isImageInBase64: true)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(DietPreviewScreen), findsOneWidget);
|
||||
@@ -131,7 +131,7 @@ void main() {
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
await tester.pumpWidget(wrap(DietPreviewScreen(diet: testDiet)));
|
||||
await tester.pumpWidget(wrap(DietPreviewScreen(diet: testDiet, isImageInBase64: true)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Test Diet Name'), findsOneWidget);
|
||||
|
||||
Reference in New Issue
Block a user