Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
156 changes: 156 additions & 0 deletions test/unit_test/off_product_dto_test.dart
Original file line number Diff line number Diff line change
@@ -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,
);
});
});
}