Skip to content

Commit

Permalink
App localization test was created for increasing coverage and reliabi…
Browse files Browse the repository at this point in the history
…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
Kushalrock authored Mar 9, 2023
1 parent 1f15ddd commit 10b75aa
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions test/utils/app_localization_test.dart
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,
);
});
});
}

0 comments on commit 10b75aa

Please sign in to comment.