localizations_test.dart 2.63 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
// 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() {
9
  testWidgets('English translations exist for all CupertinoLocalization properties', (WidgetTester tester) async {
10 11 12 13 14
    const CupertinoLocalizations localizations = DefaultCupertinoLocalizations();

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

    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);
33 34

    expect(localizations.modalBarrierDismissLabel, isNotNull);
35
    expect(localizations.searchTextFieldPlaceholderLabel, isNotNull);
36
    expect(localizations.noSpellCheckReplacementsLabel, isNotNull);
37
    expect(localizations.clearButtonLabel, isNotNull);
38
  });
39

40
  testWidgets('CupertinoLocalizations.of throws', (WidgetTester tester) async {
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    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>());
  });
63
}