Skip to content

Commit a7e5a95

Browse files
committed
feat: restored WidgetTester.idle() in test
Was needed for test to pass, everything is working as intended. iddle is probably need be cause de loading is slightly longer
1 parent abd38f8 commit a7e5a95

File tree

3 files changed

+71
-136
lines changed

3 files changed

+71
-136
lines changed

lib/src/asset_loader.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class RootBundleAssetLoader extends AssetLoader {
3737
Future<Map<String, dynamic>> _getLinkedTranslationFileDataFromBaseJson(
3838
String basePath, Locale locale, Map<String, dynamic> baseJson,
3939
{List<String> fileLoaded = const []}) async {
40-
Map<String, dynamic> fullJson = {};
40+
Map<String, dynamic> fullJson = Map<String, dynamic>.from(baseJson);
4141

4242
for (var entry in baseJson.entries) {
4343
var key = entry.key;
@@ -57,10 +57,7 @@ class RootBundleAssetLoader extends AssetLoader {
5757
if (value is Map<String, dynamic>) {
5858
fullJson[key] =
5959
await _getLinkedTranslationFileDataFromBaseJson(basePath, locale, value, fileLoaded: fileLoaded);
60-
continue;
6160
}
62-
63-
fullJson[key] = value;
6461
}
6562

6663
return fullJson;
@@ -72,6 +69,6 @@ class RootBundleAssetLoader extends AssetLoader {
7269
EasyLocalization.logger.debug('Load asset from $path');
7370

7471
Map<String, dynamic> baseJson = json.decode(await rootBundle.loadString(localePath));
75-
return _getLinkedTranslationFileDataFromBaseJson(path, locale, baseJson);
72+
return await _getLinkedTranslationFileDataFromBaseJson(path, locale, baseJson);
7673
}
7774
}

test/easy_localization_context_test.dart

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ void main() async {
8787
saveLocale: false,
8888
useOnlyLangCode: true,
8989
// fallbackLocale:Locale('en') ,
90-
supportedLocales: const [
91-
Locale('ar')
92-
], // Locale('en', 'US'), Locale('ar','DZ')
90+
supportedLocales: const [Locale('ar')], // Locale('en', 'US'), Locale('ar','DZ')
9391
child: const MyApp(),
9492
));
9593
// await tester.idle();
@@ -117,10 +115,7 @@ void main() async {
117115
await tester.pumpWidget(EasyLocalization(
118116
path: '../../i18n',
119117
// fallbackLocale:Locale('en') ,
120-
supportedLocales: const [
121-
Locale('en', 'US'),
122-
Locale('ar', 'DZ')
123-
], // Locale('en', 'US'), Locale('ar','DZ')
118+
supportedLocales: const [Locale('en', 'US'), Locale('ar', 'DZ')], // Locale('en', 'US'), Locale('ar','DZ')
124119
child: const MyApp(),
125120
));
126121
// await tester.idle();
@@ -140,13 +135,10 @@ void main() async {
140135
await tester.pumpWidget(EasyLocalization(
141136
path: '../../i18n',
142137
// fallbackLocale:Locale('en') ,
143-
supportedLocales: const [
144-
Locale('en', 'US'),
145-
Locale('ar', 'DZ')
146-
], // Locale('en', 'US'), Locale('ar','DZ')
138+
supportedLocales: const [Locale('en', 'US'), Locale('ar', 'DZ')], // Locale('en', 'US'), Locale('ar','DZ')
147139
child: const MyApp(),
148140
));
149-
// await tester.idle();
141+
await tester.idle();
150142
// The async delegator load will require build on the next frame. Thus, pump
151143
await tester.pump();
152144

@@ -161,13 +153,10 @@ void main() async {
161153
await tester.runAsync(() async {
162154
await tester.pumpWidget(EasyLocalization(
163155
path: '../../i18n',
164-
supportedLocales: const [
165-
Locale('en', 'US'),
166-
Locale('ar', 'DZ')
167-
], // Locale('en', 'US'), Locale('ar','DZ')
156+
supportedLocales: const [Locale('en', 'US'), Locale('ar', 'DZ')], // Locale('en', 'US'), Locale('ar','DZ')
168157
child: const MyApp(),
169158
));
170-
// await tester.idle();
159+
await tester.idle();
171160
// The async delegator load will require build on the next frame. Thus, pump
172161
await tester.pump();
173162

@@ -182,10 +171,7 @@ void main() async {
182171
await tester.runAsync(() async {
183172
await tester.pumpWidget(EasyLocalization(
184173
path: '../../i18n',
185-
supportedLocales: const [
186-
Locale('en', 'US'),
187-
Locale('ar', 'DZ')
188-
], // Locale('en', 'US'), Locale('ar','DZ')
174+
supportedLocales: const [Locale('en', 'US'), Locale('ar', 'DZ')], // Locale('en', 'US'), Locale('ar','DZ')
189175
startLocale: const Locale('ar', 'DZ'),
190176
child: const MyApp(),
191177
));
@@ -208,10 +194,7 @@ void main() async {
208194
await tester.runAsync(() async {
209195
await tester.pumpWidget(EasyLocalization(
210196
path: '../../i18n',
211-
supportedLocales: const [
212-
Locale('en', 'US'),
213-
Locale('ar', 'DZ')
214-
], // Locale('en', 'US'), Locale('ar','DZ')
197+
supportedLocales: const [Locale('en', 'US'), Locale('ar', 'DZ')], // Locale('en', 'US'), Locale('ar','DZ')
215198
child: const MyApp(),
216199
));
217200
await tester.idle();
@@ -229,10 +212,7 @@ void main() async {
229212
await tester.runAsync(() async {
230213
await tester.pumpWidget(EasyLocalization(
231214
path: '../../i18n',
232-
supportedLocales: const [
233-
Locale('en', 'US'),
234-
Locale('ar', 'DZ')
235-
], // Locale('en', 'US'), Locale('ar','DZ')
215+
supportedLocales: const [Locale('en', 'US'), Locale('ar', 'DZ')], // Locale('en', 'US'), Locale('ar','DZ')
236216
startLocale: const Locale('ar', 'DZ'),
237217
child: const MyApp(),
238218
));

0 commit comments

Comments
 (0)