-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
999a990
commit 237f350
Showing
12 changed files
with
148 additions
and
7 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
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
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
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
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
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
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
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
Empty file.
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,79 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:getx_standard/app/data/local/my_shared_pref.dart'; | ||
import 'package:getx_standard/config/translations/localization_service.dart'; | ||
import 'package:getx_standard/config/translations/strings_enum.dart'; | ||
|
||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
main() async { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
setUp(() { | ||
Get.testMode = true; | ||
}); | ||
|
||
// mock initial data | ||
Map<String, Object> values = <String, Object>{}; | ||
SharedPreferences.setMockInitialValues(values); | ||
|
||
await MySharedPref.init(); | ||
|
||
test('check if language is supported', () { | ||
// check if English is supported | ||
bool isEnSupported = LocalizationService.isLanguageSupported('en'); | ||
expect(isEnSupported, true); | ||
|
||
// check if French supported | ||
bool isFrSupported = LocalizationService.isLanguageSupported('fr'); | ||
expect(isFrSupported, false); | ||
}); | ||
|
||
test('Check getting/updating current local', () async { | ||
await LocalizationService.updateLanguage('en'); | ||
Locale currentLocale = LocalizationService.getCurrentLocal(); | ||
expect(currentLocale.languageCode, 'en'); | ||
|
||
await LocalizationService.updateLanguage('ar'); | ||
Locale currentLocaleAfterUpdate = LocalizationService.getCurrentLocal(); | ||
expect(currentLocaleAfterUpdate.languageCode, 'ar'); | ||
}); | ||
|
||
test('Check if current language is English', () async { | ||
await LocalizationService.updateLanguage('en'); | ||
bool isCurrentLangIsEnglish = | ||
LocalizationService.getCurrentLocal().languageCode.contains('en'); | ||
expect(isCurrentLangIsEnglish, true); | ||
|
||
await LocalizationService.updateLanguage('ar'); | ||
bool isCurrentLangEnglishAfterUpdate = | ||
LocalizationService.getCurrentLocal().languageCode.contains('ar'); | ||
expect(isCurrentLangEnglishAfterUpdate, true); | ||
}); | ||
|
||
testWidgets('Check translation', (tester) async { | ||
Get.testMode = false; | ||
await tester.pumpWidget(GetMaterialApp( | ||
locale: MySharedPref.getCurrentLocal(), | ||
translations: LocalizationService.getInstance(), | ||
home: const Scaffold( | ||
body: Center(child: Text('Testing..')), | ||
), | ||
)); | ||
await tester.pumpAndSettle(); | ||
|
||
// make language english and test the word value | ||
await LocalizationService.updateLanguage('en'); | ||
|
||
await tester.pumpAndSettle(); | ||
String helloWord = Strings.hello.tr; | ||
expect(helloWord, 'Hello!'); | ||
|
||
// make language english and test the word value | ||
await LocalizationService.updateLanguage('ar'); | ||
await tester.pumpAndSettle(); | ||
String helloWordAfterChangingLanguage = Strings.hello.tr; | ||
expect(helloWordAfterChangingLanguage, 'مرحباً!'); | ||
}); | ||
} |
Empty file.
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,46 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:getx_standard/app/data/local/my_shared_pref.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
/// test shared pref (read & write) | ||
Future<void> main() async { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
// mock initial data | ||
Map<String, Object> values = <String, Object>{}; | ||
SharedPreferences.setMockInitialValues(values); | ||
|
||
await MySharedPref.init(); | ||
|
||
test('clear all the data from storage', () async { | ||
// set new token in shared pref | ||
await MySharedPref.setFcmToken('token'); | ||
|
||
// check if the token stored | ||
String? token = MySharedPref.getFcmToken(); | ||
|
||
// token must be set correctly | ||
expect(token, isNotNull); | ||
|
||
// clear all data | ||
await MySharedPref.clear(); | ||
|
||
// token must be null now after clearing data | ||
String? tokenAfterClearing = MySharedPref.getFcmToken(); | ||
|
||
// token must be null | ||
expect(tokenAfterClearing, isNull); | ||
}); | ||
|
||
test('test read and write', () async { | ||
// set theme is light to false (write operation) | ||
await MySharedPref.setThemeIsLight(false); | ||
|
||
// get the value and test if the saving went fine (read operation) | ||
bool themeIsLight = MySharedPref.getThemeIsLight(); | ||
|
||
// make sure write and read went fine | ||
expect(themeIsLight, false); | ||
}); | ||
} |