From 2300ec453af55b2fe92623b1d30f359710145a6c Mon Sep 17 00:00:00 2001 From: Kushal Agrawal Date: Sun, 5 Mar 2023 12:59:27 +0530 Subject: [PATCH 1/6] App Localiation test --- test/utils/app_localization_test.dart | 75 +++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 test/utils/app_localization_test.dart diff --git a/test/utils/app_localization_test.dart b/test/utils/app_localization_test.dart new file mode 100644 index 000000000..e3dd5bc13 --- /dev/null +++ b/test/utils/app_localization_test.dart @@ -0,0 +1,75 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:talawa/utils/app_localization.dart'; + +void main() { + group("Test for App Localization Class", () { + WidgetsFlutterBinding.ensureInitialized(); + + test("Load JSON File for localizations", () async { + final appLocalizations = AppLocalizations(const Locale('en')); + final result = await appLocalizations.load(); + expect(result, true); + }); + + test("test mode working properly", () async { + final appLocalizations = + AppLocalizations(const Locale('hi'), isTest: true); + final result = await appLocalizations.load(); + expect(result, true); + + expect(appLocalizations.strictTranslate("Recover"), "Recover"); + }); + + test("Translate and strict translate", () async { + final appLocalizations = AppLocalizations(const Locale('en')); + final result = await appLocalizations.load(); + expect(result, true); + + // Translate known value + const key = "Please verify URL first"; + const trueData = "Please verify URL first"; + final checkData = appLocalizations.translate(key); + expect(checkData, trueData); + + // Translate unknown value + const key2 = "Lorem ipsum"; + expect(appLocalizations.translate(key2), null); + + // Translate null value + expect(appLocalizations.translate(null), "..."); + + //Strict translate known value + expect(appLocalizations.strictTranslate("Liked by"), "Liked by"); + + // Strict translate unknown value + expect(appLocalizations.strictTranslate(key2), key2); + }); + }); + + group("Test for App Localization Delegate", () { + WidgetsFlutterBinding.ensureInitialized(); + const appLocalizationsDelgate = AppLocalizationsDelegate(); + + test("Language is supported or not", () { + // A supported language + expect(appLocalizationsDelgate.isSupported(const Locale('hi')), true); + + // An unsupported language + expect(appLocalizationsDelgate.isSupported(const Locale('or')), false); + }); + + test("Localization loaded properly", () async { + final testAppLocalization = + await appLocalizationsDelgate.load(const Locale('hi')); + + // In test mode + testAppLocalization.isTest = true; + expect(testAppLocalization.strictTranslate("Recover"), "Recover"); + + // In prod mode + testAppLocalization.isTest = false; + expect(testAppLocalization.strictTranslate("Recover"), "रिकवर कर लेंगे"); + }); + }); +} From bccdf5f3acc020aebd97392254e415711ce1fe7c Mon Sep 17 00:00:00 2001 From: Kushal Agrawal Date: Sun, 5 Mar 2023 17:14:10 +0530 Subject: [PATCH 2/6] App Localization delegate should not reload --- test/utils/app_localization_test.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/utils/app_localization_test.dart b/test/utils/app_localization_test.dart index e3dd5bc13..74b94a912 100644 --- a/test/utils/app_localization_test.dart +++ b/test/utils/app_localization_test.dart @@ -12,7 +12,7 @@ void main() { expect(result, true); }); - test("test mode working properly", () async { + test("Test mode working properly", () async { final appLocalizations = AppLocalizations(const Locale('hi'), isTest: true); final result = await appLocalizations.load(); @@ -71,5 +71,12 @@ void main() { testAppLocalization.isTest = false; expect(testAppLocalization.strictTranslate("Recover"), "रिकवर कर लेंगे"); }); + + test("App Localization Delegate should not reload", () async { + expect( + appLocalizationsDelgate.shouldReload(appLocalizationsDelgate), + false, + ); + }); }); } From 1da93d36f15b286fd77a043349354d267ef46ba8 Mon Sep 17 00:00:00 2001 From: Kushal Agrawal Date: Mon, 6 Mar 2023 14:04:23 +0530 Subject: [PATCH 3/6] Added a test to also check changing localization --- test/utils/app_localization_test.dart | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/utils/app_localization_test.dart b/test/utils/app_localization_test.dart index 74b94a912..29f81f9fe 100644 --- a/test/utils/app_localization_test.dart +++ b/test/utils/app_localization_test.dart @@ -59,8 +59,8 @@ void main() { expect(appLocalizationsDelgate.isSupported(const Locale('or')), false); }); - test("Localization loaded properly", () async { - final testAppLocalization = + test("Localization loaded and changed properly", () async { + var testAppLocalization = await appLocalizationsDelgate.load(const Locale('hi')); // In test mode @@ -70,6 +70,17 @@ void main() { // In prod mode testAppLocalization.isTest = false; expect(testAppLocalization.strictTranslate("Recover"), "रिकवर कर लेंगे"); + + testAppLocalization = + await appLocalizationsDelgate.load(const Locale('fr')); + + // In test mode + testAppLocalization.isTest = true; + expect(testAppLocalization.strictTranslate("Recover"), "Recover"); + + // In prod mode + testAppLocalization.isTest = false; + expect(testAppLocalization.strictTranslate("Recover"), "votre mot"); }); test("App Localization Delegate should not reload", () async { From 082ea01487b9d88699ea8f9dc7b03e874f00ee80 Mon Sep 17 00:00:00 2001 From: Kushal Agrawal Date: Thu, 9 Mar 2023 18:25:54 +0530 Subject: [PATCH 4/6] Custom Linting --- test/utils/app_localization_test.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/utils/app_localization_test.dart b/test/utils/app_localization_test.dart index 29f81f9fe..933bb661a 100644 --- a/test/utils/app_localization_test.dart +++ b/test/utils/app_localization_test.dart @@ -2,6 +2,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:talawa/utils/app_localization.dart'; +/// The entry of the test function. +/// +/// params: +/// void main() { group("Test for App Localization Class", () { WidgetsFlutterBinding.ensureInitialized(); From 38bc2f07dac64108c383b9d77ac21f12f7e0a508 Mon Sep 17 00:00:00 2001 From: Kushal Agrawal Date: Thu, 9 Mar 2023 18:53:17 +0530 Subject: [PATCH 5/6] Params None --- test/utils/app_localization_test.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/test/utils/app_localization_test.dart b/test/utils/app_localization_test.dart index 933bb661a..7524530f0 100644 --- a/test/utils/app_localization_test.dart +++ b/test/utils/app_localization_test.dart @@ -5,6 +5,7 @@ import 'package:talawa/utils/app_localization.dart'; /// The entry of the test function. /// /// params: +/// None /// void main() { group("Test for App Localization Class", () { From 06a53dd1883ea7bd99b2722e45528b1b587c0c51 Mon Sep 17 00:00:00 2001 From: Kushal Agrawal Date: Thu, 9 Mar 2023 18:55:01 +0530 Subject: [PATCH 6/6] Removed last /// --- test/utils/app_localization_test.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/test/utils/app_localization_test.dart b/test/utils/app_localization_test.dart index 7524530f0..99eb8d80f 100644 --- a/test/utils/app_localization_test.dart +++ b/test/utils/app_localization_test.dart @@ -6,7 +6,6 @@ import 'package:talawa/utils/app_localization.dart'; /// /// params: /// None -/// void main() { group("Test for App Localization Class", () { WidgetsFlutterBinding.ensureInitialized();