Add a test to stocks for changing the locale
I had to add a setLocale method to WidgetTester and split the code in FlutterBinding which handled locale changes to allow me to dispatch a locale change w/o actually changing what the c++ code reports as the locale. Also added the test to Travis. @abarth @jason-simmons
This commit is contained in:
parent
bf5ef790fa
commit
09894ec50b
@ -4,3 +4,6 @@ dependencies:
|
||||
path: ../../packages/flutter
|
||||
|
||||
intl: '>=0.12.4+2 <0.13.0'
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
path: ../../packages/flutter_test
|
||||
|
23
examples/stocks/tests/locale_test.dart
Normal file
23
examples/stocks/tests/locale_test.dart
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
import 'package:test/test.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stocks/main.dart' as stocks;
|
||||
import 'package:stocks/stock_data.dart' as stock_data;
|
||||
|
||||
void main() {
|
||||
stock_data.StockDataFetcher.actuallyFetchData = false;
|
||||
|
||||
test("Test changing locale", () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
stocks.main();
|
||||
tester.pump(const Duration(seconds: 1)); // Unclear why duration is required.
|
||||
|
||||
Element<Text> tab = tester.findText('MARKET');
|
||||
expect(tab, isNotNull);
|
||||
tester.setLocale("es", "US");
|
||||
tester.pump();
|
||||
expect(tab.widget.data, equals("MERCADO"));
|
||||
});
|
||||
});
|
||||
}
|
@ -29,7 +29,7 @@ class _PointerState {
|
||||
_pointerCount += 1;
|
||||
_pointer = _pointerCount;
|
||||
}
|
||||
|
||||
|
||||
bool get down => _down;
|
||||
bool _down = false;
|
||||
void setDown() {
|
||||
@ -247,8 +247,12 @@ class FlutterBinding extends HitTestTarget {
|
||||
}
|
||||
|
||||
void _handleLocaleChanged() {
|
||||
dispatchLocaleChanged(ui.window.locale);
|
||||
}
|
||||
|
||||
void dispatchLocaleChanged(ui.Locale locale) {
|
||||
for (BindingObserver observer in _observers)
|
||||
observer.didChangeLocale(ui.window.locale);
|
||||
observer.didChangeLocale(locale);
|
||||
}
|
||||
|
||||
void _handlePersistentFrameCallback(Duration timeStamp) {
|
||||
|
@ -32,6 +32,12 @@ class WidgetTester {
|
||||
pump(duration);
|
||||
}
|
||||
|
||||
void setLocale(String languageCode, String countryCode) {
|
||||
ui.Locale locale = new ui.Locale(languageCode, countryCode);
|
||||
FlutterBinding.instance.dispatchLocaleChanged(locale);
|
||||
async.flushMicrotasks();
|
||||
}
|
||||
|
||||
void pump([ Duration duration ]) {
|
||||
if (duration != null)
|
||||
async.elapse(duration);
|
||||
|
@ -1,11 +1,13 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
export PATH="$PWD/bin:$PATH"
|
||||
|
||||
# analyze all the Dart code in the repo
|
||||
./bin/flutter analyze --flutter-repo --no-current-directory --no-current-package --congratulate
|
||||
flutter analyze --flutter-repo --no-current-directory --no-current-package --congratulate
|
||||
|
||||
# flutter package tests
|
||||
./bin/flutter test --flutter-repo
|
||||
flutter test --flutter-repo
|
||||
|
||||
(cd packages/cassowary; pub run test -j1)
|
||||
# (cd packages/flutter_sprites; ) # No tests to run.
|
||||
@ -15,6 +17,8 @@ set -ex
|
||||
# (cd packages/playfair; ) # No tests to run.
|
||||
# (cd packages/updater; ) # No tests to run.
|
||||
|
||||
(cd examples/stocks; flutter test)
|
||||
|
||||
if [ $TRAVIS_PULL_REQUEST = "false" ]; then
|
||||
if [ $TRAVIS_BRANCH = "master" ]; then
|
||||
(cd packages/flutter; dartdoc)
|
||||
|
Loading…
x
Reference in New Issue
Block a user