placeholder_test.dart 2.23 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
// @dart = 2.8

7 8 9 10 11 12 13 14 15
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';

import '../rendering/mock_canvas.dart';

void main() {
  testWidgets('Placeholder', (WidgetTester tester) async {
    await tester.pumpWidget(const Placeholder());
    expect(tester.renderObject<RenderBox>(find.byType(Placeholder)).size, const Size(800.0, 600.0));
16
    await tester.pumpWidget(const Center(child: Placeholder()));
17
    expect(tester.renderObject<RenderBox>(find.byType(Placeholder)).size, const Size(800.0, 600.0));
18
    await tester.pumpWidget(Stack(textDirection: TextDirection.ltr, children: const <Widget>[Positioned(top: 0.0, bottom: 0.0, child: Placeholder())]));
19
    expect(tester.renderObject<RenderBox>(find.byType(Placeholder)).size, const Size(400.0, 600.0));
20
    await tester.pumpWidget(Stack(textDirection: TextDirection.ltr, children: const <Widget>[Positioned(left: 0.0, right: 0.0, child: Placeholder())]));
21
    expect(tester.renderObject<RenderBox>(find.byType(Placeholder)).size, const Size(800.0, 400.0));
22
    await tester.pumpWidget(Stack(textDirection: TextDirection.ltr, children: const <Widget>[Positioned(top: 0.0, child: Placeholder(fallbackWidth: 200.0, fallbackHeight: 300.0))]));
23 24 25 26 27
    expect(tester.renderObject<RenderBox>(find.byType(Placeholder)).size, const Size(200.0, 300.0));
  });

  testWidgets('Placeholder color', (WidgetTester tester) async {
    await tester.pumpWidget(const Placeholder());
28
    expect(tester.renderObject(find.byType(Placeholder)), paints..path(color: const Color(0xFF455A64)));
29
    await tester.pumpWidget(const Placeholder(color: Color(0xFF00FF00)));
30 31
    expect(tester.renderObject(find.byType(Placeholder)), paints..path(color: const Color(0xFF00FF00)));
  });
32 33 34 35 36 37 38

  testWidgets('Placeholder stroke width', (WidgetTester tester) async {
    await tester.pumpWidget(const Placeholder());
    expect(tester.renderObject(find.byType(Placeholder)), paints..path(strokeWidth: 2.0));
    await tester.pumpWidget(const Placeholder(strokeWidth: 10.0));
    expect(tester.renderObject(find.byType(Placeholder)), paints..path(strokeWidth: 10.0));
  });
39
}