rtl_test.dart 3.34 KB
Newer Older
1 2 3 4 5 6 7 8 9
// 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.

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

void main() {
  testWidgets('Padding RTL', (WidgetTester tester) async {
10
    const Widget child = const Padding(
11 12
      padding: const EdgeInsetsDirectional.only(start: 10.0),
      child: const Placeholder(),
13
    );
14
    await tester.pumpWidget(const Directionality(
15 16 17 18
      textDirection: TextDirection.ltr,
      child: child,
    ));
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(10.0, 0.0));
19
    await tester.pumpWidget(const Directionality(
20 21 22 23
      textDirection: TextDirection.rtl,
      child: child,
    ));
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(0.0, 0.0));
Ian Hickson's avatar
Ian Hickson committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

    await tester.pumpWidget(
      const Padding(
        key: const GlobalObjectKey<Null>(null),
        padding: const EdgeInsets.only(left: 1.0),
      ),
    );
    await tester.pumpWidget(const Directionality(
      textDirection: TextDirection.rtl,
      child: const Padding(
        key: const GlobalObjectKey<Null>(null),
        padding: const EdgeInsetsDirectional.only(start: 1.0),
      ),
    ));
    await tester.pumpWidget(
      const Padding(
        key: const GlobalObjectKey<Null>(null),
        padding: const EdgeInsets.only(left: 1.0),
      ),
    );
44 45 46 47
  });

  testWidgets('Container padding/margin RTL', (WidgetTester tester) async {
    final Widget child = new Container(
48 49 50
      padding: const EdgeInsetsDirectional.only(start: 6.0),
      margin: const EdgeInsetsDirectional.only(end: 20.0, start: 4.0),
      child: const Placeholder(),
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
    );
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
      child: child,
    ));
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(10.0, 0.0));
    expect(tester.getTopRight(find.byType(Placeholder)), const Offset(780.0, 0.0));
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.rtl,
      child: child,
    ));
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(20.0, 0.0));
    expect(tester.getTopRight(find.byType(Placeholder)), const Offset(790.0, 0.0));
  });

  testWidgets('Container padding/margin mixed RTL/absolute', (WidgetTester tester) async {
    final Widget child = new Container(
68 69 70
      padding: const EdgeInsets.only(left: 6.0),
      margin: const EdgeInsetsDirectional.only(end: 20.0, start: 4.0),
      child: const Placeholder(),
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    );
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
      child: child,
    ));
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(10.0, 0.0));
    expect(tester.getTopRight(find.byType(Placeholder)), const Offset(780.0, 0.0));
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.rtl,
      child: child,
    ));
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(26.0, 0.0));
    expect(tester.getTopRight(find.byType(Placeholder)), const Offset(796.0, 0.0));
  });

  testWidgets('EdgeInsetsDirectional without Directionality', (WidgetTester tester) async {
87
    await tester.pumpWidget(const Padding(padding: const EdgeInsetsDirectional.only()));
88 89 90
    expect(tester.takeException(), isAssertionError);
  });
}