localizations_test.dart 2.45 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('English translations exist for all CupertinoLocalization properties', (WidgetTester tester) async {
    const CupertinoLocalizations localizations = DefaultCupertinoLocalizations();

    expect(localizations.datePickerYear(2018), isNotNull);
    expect(localizations.datePickerMonth(1), isNotNull);
    expect(localizations.datePickerDayOfMonth(1), isNotNull);
    expect(localizations.datePickerHour(0), isNotNull);
16
    expect(localizations.datePickerHourSemanticsLabel(0), isNotNull);
17
    expect(localizations.datePickerMinute(0), isNotNull);
18
    expect(localizations.datePickerMinuteSemanticsLabel(0), isNotNull);
19 20
    expect(localizations.datePickerMediumDate(DateTime.now()), isNotNull);
    expect(localizations.datePickerDateOrder, isNotNull);
21
    expect(localizations.datePickerDateTimeOrder, isNotNull);
22 23 24 25 26 27 28 29 30 31

    expect(localizations.anteMeridiemAbbreviation, isNotNull);
    expect(localizations.postMeridiemAbbreviation, isNotNull);

    expect(localizations.timerPickerHour(0), isNotNull);
    expect(localizations.timerPickerMinute(0), isNotNull);
    expect(localizations.timerPickerSecond(0), isNotNull);
    expect(localizations.timerPickerHourLabel(0), isNotNull);
    expect(localizations.timerPickerMinuteLabel(0), isNotNull);
    expect(localizations.timerPickerSecondLabel(0), isNotNull);
32 33

    expect(localizations.modalBarrierDismissLabel, isNotNull);
34
    expect(localizations.searchTextFieldPlaceholderLabel, isNotNull);
35
  });
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

  testWidgets('CupertinoLocalizations.of throws', (WidgetTester tester) async {
    final GlobalKey noLocalizationsAvailable = GlobalKey();
    final GlobalKey localizationsAvailable = GlobalKey();

    await tester.pumpWidget(
      Container(
        key: noLocalizationsAvailable,
        child: CupertinoApp(
          home: Container(
            key: localizationsAvailable,
          ),
        ),
      ),
    );

    expect(() => CupertinoLocalizations.of(noLocalizationsAvailable.currentContext!), throwsA(isAssertionError.having(
      (AssertionError e) => e.message,
      'message',
      contains('No CupertinoLocalizations found'),
    )));

    expect(CupertinoLocalizations.of(localizationsAvailable.currentContext!), isA<CupertinoLocalizations>());
  });
60
}