localized_fonts_test.dart 5.29 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6 7
// This file is run as part of a reduced test set in CI on Mac and Windows
// machines.
@Tags(<String>['reduced-test-set'])
8
library;
9

10 11 12 13 14 15 16 17 18 19 20 21
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

// TODO(hansmuller): when https://github.com/flutter/flutter/issues/17700
// is fixed, these tests should be updated to use a real font (not Ahem).

void main() {
  testWidgets(
    'RichText TextSpan styles with different locales',
    (WidgetTester tester) async {

      await tester.pumpWidget(
22
        MaterialApp(
23
          supportedLocales: const <Locale>[
24 25 26
            Locale('en', 'US'),
            Locale('ja'),
            Locale('zh'),
27
          ],
28
          home: Builder(
29 30
            builder: (BuildContext context) {
              const String character = '骨';
31
              final TextStyle style = Theme.of(context).textTheme.displayMedium!;
32 33
              return Scaffold(
                body: Container(
34 35
                  padding: const EdgeInsets.all(48.0),
                  alignment: Alignment.center,
36
                  child: RepaintBoundary(
37 38
                    // Expected result can be seen here:
                    // https://user-images.githubusercontent.com/1377460/40503473-faad6f34-5f42-11e8-972b-d83b727c9d0e.png
39 40
                    child: RichText(
                      text: TextSpan(
41
                        children: <TextSpan>[
42 43
                          TextSpan(text: character, style: style.copyWith(locale: const Locale('ja'))),
                          TextSpan(text: character, style: style.copyWith(locale: const Locale('zh'))),
44 45 46 47 48 49 50 51
                        ],
                      ),
                    ),
                  ),
                ),
              );
            },
          ),
52
        ),
53 54 55 56
      );

      await expectLater(
        find.byType(RichText),
57
        matchesGoldenFile('localized_fonts.rich_text.styled_text_span.png'),
58
      );
59 60
    },
  );
61 62 63 64 65

  testWidgets(
    'Text with locale-specific glyphs, ambient locale',
    (WidgetTester tester) async {
      await tester.pumpWidget(
66
        MaterialApp(
67
          supportedLocales: const <Locale>[
68 69 70
            Locale('en', 'US'),
            Locale('ja'),
            Locale('zh'),
71
          ],
72
          home: Builder(
73 74
            builder: (BuildContext context) {
              const String character = '骨';
75
              final TextStyle style = Theme.of(context).textTheme.displayMedium!;
76 77
              return Scaffold(
                body: Container(
78 79
                  padding: const EdgeInsets.all(48.0),
                  alignment: Alignment.center,
80
                  child: RepaintBoundary(
81 82
                    // Expected result can be seen here:
                    // https://user-images.githubusercontent.com/1377460/40503473-faad6f34-5f42-11e8-972b-d83b727c9d0e.png
83
                    child: Row(
84 85
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
86
                        Localizations.override(
87 88
                          context: context,
                          locale: const Locale('ja'),
89
                          child: Text(character, style: style),
90
                        ),
91
                        Localizations.override(
92 93
                          context: context,
                          locale: const Locale('zh'),
94
                          child: Text(character, style: style),
95 96 97 98 99 100 101 102
                        ),
                      ],
                    ),
                  ),
                ),
              );
            },
          ),
103
        ),
104 105 106 107
      );

      await expectLater(
        find.byType(Row),
108
        matchesGoldenFile('localized_fonts.text_ambient_locale.chars.png'),
109
      );
110 111
    },
  );
112 113 114 115 116

  testWidgets(
    'Text with locale-specific glyphs, explicit locale',
    (WidgetTester tester) async {
      await tester.pumpWidget(
117
        MaterialApp(
118
          supportedLocales: const <Locale>[
119 120 121
            Locale('en', 'US'),
            Locale('ja'),
            Locale('zh'),
122
          ],
123
          home: Builder(
124 125
            builder: (BuildContext context) {
              const String character = '骨';
126
              final TextStyle style = Theme.of(context).textTheme.displayMedium!;
127 128
              return Scaffold(
                body: Container(
129 130
                  padding: const EdgeInsets.all(48.0),
                  alignment: Alignment.center,
131
                  child: RepaintBoundary(
132 133
                    // Expected result can be seen here:
                    // https://user-images.githubusercontent.com/1377460/40503473-faad6f34-5f42-11e8-972b-d83b727c9d0e.png
134
                    child: Row(
135 136
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
137
                        Text(character, style: style, locale: const Locale('ja')),
138
                        Text(character, style: style, locale: const Locale('zh')),
139 140 141 142 143 144 145
                      ],
                    ),
                  ),
                ),
              );
            },
          ),
146
        ),
147 148 149 150
      );

      await expectLater(
        find.byType(Row),
151
        matchesGoldenFile('localized_fonts.text_explicit_locale.chars.png'),
152
      );
153 154
    },
  );
155 156

}