diff --git a/pubspec.lock b/pubspec.lock index 3d6042592..1320ac51e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1473,4 +1473,4 @@ packages: version: "2.0.3" sdks: dart: ">=3.6.0 <4.0.0" - flutter: ">=3.27.0" + flutter: ">=3.27.0" \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 1172db1e9..f198535ae 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -139,4 +139,4 @@ flutter_launcher_icons: ios: true remove_alpha_ios: true image_path: "assets/icon/ont_logo_square.png" - min_sdk_android: 21 + min_sdk_android: 21 \ No newline at end of file diff --git a/test/unit_test/off_product_dto_test.dart b/test/unit_test/off_product_dto_test.dart new file mode 100644 index 000000000..5f69aa687 --- /dev/null +++ b/test/unit_test/off_product_dto_test.dart @@ -0,0 +1,156 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:opennutritracker/core/utils/supported_language.dart'; +import 'package:opennutritracker/features/add_meal/data/dto/off/off_product_dto.dart'; +import 'package:opennutritracker/features/add_meal/data/dto/off/off_product_nutriments_dto.dart'; + +void main() { + group('OFFProductDTO getLocaleName', () { + test('Case 1: English Language - Valid Name', () { + final product = OFFProductDTO( + code: '123 - testValue', + product_name: 'Name - testValue', + product_name_en: 'English Name - testValue', + product_name_fr: 'Nom Français - testValue', + product_name_de: 'Deutscher Name - testValue', + brands: 'Brand - testValue', + image_front_thumb_url: 'thumb - testValue', + image_front_url: 'front - testValue', + image_ingredients_url: 'ingredients - testValue', + image_nutrition_url: 'nutrition - testValue', + image_url: 'image - testValue', + url: 'url - testValue', + quantity: '100g - testValue', + product_quantity: '100 - testValue', + serving_quantity: '50 - testValue', + serving_size: '50g - testValue', + nutriments: OFFProductNutrimentsDTO( + energy_kcal_100g: 1, + carbohydrates_100g: 1, + fat_100g: 1, + proteins_100g: 1, + sugars_100g: 1, + saturated_fat_100g: 1, + fiber_100g: 1, + ), + ); + + final result = product.getLocaleName(SupportedLanguage.en); + + expect(result, equals('English Name - testValue')); + }); + + test('Case 2: Deutscher Language - Valid Name', () { + final product = OFFProductDTO( + code: '123 - testValue', + product_name: 'Default Name - testValue', + product_name_en: 'English Name - testValue', + product_name_fr: 'Nom Français - testValue', + product_name_de: 'Deutscher Name - testValue', + brands: 'Brand - testValue', + image_front_thumb_url: 'thumb - testValue', + image_front_url: 'front - testValue', + image_ingredients_url: 'ingredients - testValue', + image_nutrition_url: 'nutrition - testValue', + image_url: 'image - testValue', + url: 'url - testValue', + quantity: '100g - testValue', + product_quantity: '100 - testValue', + serving_quantity: '50 - testValue', + serving_size: '50g - testValue', + nutriments: OFFProductNutrimentsDTO( + energy_kcal_100g: 1, + carbohydrates_100g: 1, + fat_100g: 1, + proteins_100g: 1, + sugars_100g: 1, + saturated_fat_100g: 1, + fiber_100g: 1 + ), + ); + + final result = product.getLocaleName(SupportedLanguage.de); + + expect(result, equals('Deutscher Name - testValue')); + }); + + test('Case 3: English Language - Null Name', () { + final product = OFFProductDTO( + code: '123 - testValue', + product_name: 'Default Name - testValue', + product_name_en: null, + product_name_fr: 'Nom Français - testValue', + product_name_de: 'Deutscher Name - testValue', + brands: 'Brand - testValue', + image_front_thumb_url: 'thumb - testValue', + image_front_url: 'front - testValue', + image_ingredients_url: 'ingredients - testValue', + image_nutrition_url: 'nutrition - testValue', + image_url: 'image - testValue', + url: 'url - testValue', + quantity: '100g - testValue', + product_quantity: '100 - testValue', + serving_quantity: '50 - testValue', + serving_size: '50g - testValue', + nutriments: OFFProductNutrimentsDTO( + energy_kcal_100g: 1, + carbohydrates_100g: 1, + fat_100g: 1, + proteins_100g: 1, + sugars_100g: 1, + saturated_fat_100g: 1, + fiber_100g: 1 + ), + ); + + final result = product.getLocaleName(SupportedLanguage.en); + + expect( + result == 'Deutscher Name - testValue' || + result == 'English Name - testValue' || + result == 'Default Name - testValue' || + result == 'Nom Français - testValue', + isTrue, + ); + }); + + test('Case 4: English Language - Empty Name', () { + final product = OFFProductDTO( + code: '123 - testValue', + product_name: 'Default Name - testValue', + product_name_en: '', + product_name_fr: 'Nom Français - testValue', + product_name_de: 'Deutscher Name - testValue', + brands: 'Brand - testValue', + image_front_thumb_url: 'thumb - testValue', + image_front_url: 'front - testValue', + image_ingredients_url: 'ingredients - testValue', + image_nutrition_url: 'nutrition - testValue', + image_url: 'image - testValue', + url: 'url - testValue', + quantity: '100g - testValue', + product_quantity: '100 - testValue', + serving_quantity: '50 - testValue', + serving_size: '50g - testValue', + nutriments: OFFProductNutrimentsDTO( + energy_kcal_100g: 1, + carbohydrates_100g: 1, + fat_100g: 1, + proteins_100g: 1, + sugars_100g: 1, + saturated_fat_100g: 1, + fiber_100g: 1 + ), + ); + + final result = product.getLocaleName(SupportedLanguage.en); + + expect( + result == 'Deutscher Name - testValue' || + result == 'English Name - testValue' || + result == 'Default Name - testValue' || + result == 'Nom Français - testValue', + isTrue, + ); + }); + }); +} \ No newline at end of file