locale_test.dart 1.2 KB
Newer Older
1 2 3
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

Devon Carew's avatar
Devon Carew committed
5
import 'package:flutter_test/flutter_test.dart';
6 7 8 9
import 'package:stocks/main.dart' as stocks;
import 'package:stocks/stock_data.dart' as stock_data;

void main() {
10
  stock_data.StockData.actuallyFetchData = false;
11

12
  testWidgets('Changing locale', (WidgetTester tester) async {
13
    stocks.main();
14 15
    await tester.idle(); // see https://github.com/flutter/flutter/issues/1865
    await tester.pump();
16
    // The initial test app's locale is "_", so we're seeing the fallback translation here.
17
    expect(find.text('MARKET'), findsOneWidget);
18
    await tester.binding.setLocale('es', 'US');
19
    await tester.idle();
20 21 22 23 24 25 26 27 28

    // The Localizations widget has been built with the new locale. The
    // new locale's strings are loaded asynchronously, so we're still
    // displaying the previous locale's strings.
    await tester.pump();
    expect(find.text('MARKET'), findsOneWidget);

    // The localized strings have finished loading and dependent
    // widgets have been updated.
29
    await tester.pump();
30
    expect(find.text('MERCADO'), findsOneWidget);
31 32
  });
}