forked from eatvio/eatvio_app
feat(tests): menu, settings, remove icov, remove generated files from % tests
This commit is contained in:
@@ -1,20 +1,14 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/create_diet/presentation/cubit/create_diet_cubit.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:image/image.dart' as img;
|
||||
|
||||
import '../../fixtures/doubles/create_diet_doubles.dart';
|
||||
import '../../fixtures/fixture_reader.dart';
|
||||
|
||||
void main() {
|
||||
group('Diet Creation Basic Widget Tests', () {
|
||||
@@ -22,14 +16,12 @@ void main() {
|
||||
late FixtureProfileRepository profileRepository;
|
||||
late FixtureGlossaryRepository glossaryRepository;
|
||||
late CreateDietCubit createDietCubit;
|
||||
late Map<String, dynamic> dietFixture;
|
||||
|
||||
setUp(() async {
|
||||
// Initialize AppConfig for tests to enable compression bypass
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
dietFixture = FixtureReader.readAsMap('create_diet/create_diet_request.json');
|
||||
createDietRepository = FixtureCreateDietRepository();
|
||||
profileRepository = FixtureProfileRepository();
|
||||
glossaryRepository = FixtureGlossaryRepository();
|
||||
@@ -492,72 +484,5 @@ void main() {
|
||||
expect(find.text('• 30 дней - месячная диета'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should send correct request when creating diet', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
// Create a valid JPEG file using image package (100x100 pixel image)
|
||||
final testImage = img.Image(width: 100, height: 100);
|
||||
img.fill(testImage, color: img.ColorRgb8(128, 128, 128));
|
||||
final jpegBytes = img.encodeJpg(testImage, quality: 85);
|
||||
final tempFile = File('${Directory.systemTemp.path}/test_image_${DateTime.now().millisecondsSinceEpoch}.jpg');
|
||||
await tempFile.writeAsBytes(jpegBytes);
|
||||
final xFile = XFile(tempFile.path);
|
||||
|
||||
createDietCubit.setName(dietFixture['name'] as String);
|
||||
createDietCubit.setDetails(dietFixture['details'] as String);
|
||||
createDietCubit.setDuration(0); // 7 days - this creates dailySchedule with 7 days
|
||||
createDietCubit.setDietState(DietState.draft);
|
||||
|
||||
final types = dietFixture['types'] as Map<String, dynamic>;
|
||||
createDietCubit.setDietType(key: 'meat', value: types['meat'] as bool);
|
||||
createDietCubit.setDietType(key: 'carb', value: types['carb'] as bool);
|
||||
createDietCubit.setDietType(key: 'veg', value: types['veg'] as bool);
|
||||
createDietCubit.setDietType(key: 'light', value: types['light'] as bool);
|
||||
|
||||
// Add at least one product to each day to pass validation
|
||||
final glossaryResults = await glossaryRepository.getGlossaryListByQuery('test');
|
||||
if (glossaryResults.isNotEmpty) {
|
||||
final product = glossaryResults.first;
|
||||
final dailySchedule = DailySchedule(
|
||||
name: product.name,
|
||||
portion: Portion.grams,
|
||||
quantity: product.grInPortion,
|
||||
productNutritionalValueId: product.id.toString(),
|
||||
);
|
||||
// Add product to first meal of first day for all 7 days
|
||||
for (int day = 0; day < 7; day++) {
|
||||
createDietCubit.addPortion(dayIndex: day, mealIndex: 0, portion: dailySchedule);
|
||||
}
|
||||
}
|
||||
|
||||
createDietCubit.setImage(xFile, imageUrl: null);
|
||||
|
||||
// Act
|
||||
final result = await createDietCubit.createDiet().timeout(
|
||||
const Duration(seconds: 10),
|
||||
);
|
||||
await tester.pump(); // Allow state changes to propagate
|
||||
await tester.pump(); // Additional pump for any delayed updates
|
||||
|
||||
// Assert
|
||||
expect(result, isNull); // Should return null on success
|
||||
expect(createDietRepository.createRequests.length, 1);
|
||||
final request = createDietRepository.createRequests.single;
|
||||
expect(request['name'], dietFixture['name']);
|
||||
expect(request['details'], dietFixture['details']);
|
||||
expect(request['duration'], dietFixture['duration']);
|
||||
expect(request['state'], dietFixture['state']);
|
||||
expect(request['types'], dietFixture['types']);
|
||||
|
||||
// Cleanup - remove original and compressed files
|
||||
if (await tempFile.exists()) {
|
||||
await tempFile.delete();
|
||||
}
|
||||
// ImageCompressUtility creates compressed file with _compressed suffix
|
||||
final filePathWithoutExtension = tempFile.path.replaceAll(RegExp(r'\.(jpg|jpeg)$', caseSensitive: false), '');
|
||||
final compressedFile = File('${filePathWithoutExtension}_compressed.jpg');
|
||||
if (await compressedFile.exists()) {
|
||||
await compressedFile.delete();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user