-
-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App localization test was created for increasing coverage and reliabi…
…lity (#1619) * App Localiation test * App Localization delegate should not reload * Added a test to also check changing localization * Custom Linting * Params None * Removed last ///
- Loading branch information
1 parent
1f15ddd
commit 10b75aa
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
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: | ||
/// None | ||
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 and changed properly", () async { | ||
var 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"), "रिकवर कर लेंगे"); | ||
|
||
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 { | ||
expect( | ||
appLocalizationsDelgate.shouldReload(appLocalizationsDelgate), | ||
false, | ||
); | ||
}); | ||
}); | ||
} |