table_test.dart 24.8 KB
Newer Older
Hixie's avatar
Hixie committed
1 2 3 4 5 6 7 8
// Copyright 2015 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/rendering.dart';
import 'package:flutter/widgets.dart';

9
class TestStatefulWidget extends StatefulWidget {
10
  const TestStatefulWidget({ Key key }) : super(key: key);
11 12

  @override
13
  TestStatefulWidgetState createState() => TestStatefulWidgetState();
14 15 16 17
}

class TestStatefulWidgetState extends State<TestStatefulWidget> {
  @override
18
  Widget build(BuildContext context) => Container();
19 20
}

Hixie's avatar
Hixie committed
21
void main() {
22 23
  testWidgets('Table widget - empty', (WidgetTester tester) async {
    await tester.pumpWidget(
24
      Directionality(
25
        textDirection: TextDirection.ltr,
26
        child: Table(),
27 28 29
      ),
    );
  });
30
  testWidgets('Table widget - control test', (WidgetTester tester) async {
31
    Future<void> run(TextDirection textDirection) async {
32
      await tester.pumpWidget(
33
        Directionality(
34
          textDirection: textDirection,
35
          child: Table(
36
            children: const <TableRow>[
37 38 39
              TableRow(
                children: <Widget>[
                  Text('AAAAAA'), Text('B'), Text('C'),
40 41
                ],
              ),
42 43 44
              TableRow(
                children: <Widget>[
                  Text('D'), Text('EEE'), Text('F'),
45 46
                ],
              ),
47 48 49
              TableRow(
                children: <Widget>[
                  Text('G'), Text('H'), Text('III'),
50 51 52
                ],
              ),
            ],
53
          ),
54 55 56 57 58 59 60 61 62 63 64 65
        ),
      );
      final RenderBox boxA = tester.renderObject(find.text('AAAAAA'));
      final RenderBox boxD = tester.renderObject(find.text('D'));
      final RenderBox boxG = tester.renderObject(find.text('G'));
      final RenderBox boxB = tester.renderObject(find.text('B'));
      expect(boxA.size, equals(boxD.size));
      expect(boxA.size, equals(boxG.size));
      expect(boxA.size, equals(boxB.size));
    }

    await run(TextDirection.ltr);
66
    await tester.pumpWidget(Container());
67
    await run(TextDirection.rtl);
Hixie's avatar
Hixie committed
68
  });
69

70 71
  testWidgets('Table widget - column offset (LTR)', (WidgetTester tester) async {
    await tester.pumpWidget(
72
      Directionality(
73
        textDirection: TextDirection.ltr,
74 75
        child: Center(
          child: Table(
76
            columnWidths: const <int, TableColumnWidth> {
77 78 79
              0: FixedColumnWidth(100.0),
              1: FixedColumnWidth(110.0),
              2: FixedColumnWidth(125.0),
80 81
            },
            defaultColumnWidth: const FixedColumnWidth(333.0),
82
            children: const <TableRow>[
83 84 85
              TableRow(
                children: <Widget>[
                  Text('A1'), Text('B1'), Text('C1'),
86 87
                ],
              ),
88 89 90
              TableRow(
                children: <Widget>[
                  Text('A2'), Text('B2'), Text('C2'),
91 92
                ],
              ),
93 94 95
              TableRow(
                children: <Widget>[
                  Text('A3'), Text('B3'), Text('C3'),
96 97 98
                ],
              ),
            ],
99
          ),
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
        ),
      ),
    );

    final Rect table = tester.getRect(find.byType(Table));
    final Rect a1 = tester.getRect(find.text('A1'));
    final Rect a2 = tester.getRect(find.text('A2'));
    final Rect a3 = tester.getRect(find.text('A3'));
    final Rect b1 = tester.getRect(find.text('B1'));
    final Rect b2 = tester.getRect(find.text('B2'));
    final Rect b3 = tester.getRect(find.text('B3'));
    final Rect c1 = tester.getRect(find.text('C1'));
    final Rect c2 = tester.getRect(find.text('C2'));
    final Rect c3 = tester.getRect(find.text('C3'));

    expect(a1.width, equals(100.0));
    expect(a2.width, equals(100.0));
    expect(a3.width, equals(100.0));
    expect(b1.width, equals(110.0));
    expect(b2.width, equals(110.0));
    expect(b3.width, equals(110.0));
    expect(c1.width, equals(125.0));
    expect(c2.width, equals(125.0));
    expect(c3.width, equals(125.0));

    expect(table.width, equals(335.0));

    expect(a1.left, equals(table.left));
    expect(a2.left, equals(a1.left));
    expect(a3.left, equals(a1.left));

    expect(b1.left, equals(table.left + a1.width));
    expect(b2.left, equals(b1.left));
    expect(b3.left, equals(b1.left));

    expect(c1.left, equals(table.left + a1.width + b1.width));
    expect(c2.left, equals(c1.left));
    expect(c3.left, equals(c1.left));
  });

  testWidgets('Table widget - column offset (RTL)', (WidgetTester tester) async {
    await tester.pumpWidget(
142
      Directionality(
143
        textDirection: TextDirection.rtl,
144 145
        child: Center(
          child: Table(
146
            columnWidths: const <int, TableColumnWidth> {
147 148 149
              0: FixedColumnWidth(100.0),
              1: FixedColumnWidth(110.0),
              2: FixedColumnWidth(125.0),
150 151
            },
            defaultColumnWidth: const FixedColumnWidth(333.0),
152
            children: const <TableRow>[
153 154 155
              TableRow(
                children: <Widget>[
                  Text('A1'), Text('B1'), Text('C1'),
156 157
                ],
              ),
158 159 160
              TableRow(
                children: <Widget>[
                  Text('A2'), Text('B2'), Text('C2'),
161 162
                ],
              ),
163 164 165
              TableRow(
                children: <Widget>[
                  Text('A3'), Text('B3'), Text('C3'),
166 167 168
                ],
              ),
            ],
169
          ),
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
        ),
      ),
    );

    final Rect table = tester.getRect(find.byType(Table));
    final Rect a1 = tester.getRect(find.text('A1'));
    final Rect a2 = tester.getRect(find.text('A2'));
    final Rect a3 = tester.getRect(find.text('A3'));
    final Rect b1 = tester.getRect(find.text('B1'));
    final Rect b2 = tester.getRect(find.text('B2'));
    final Rect b3 = tester.getRect(find.text('B3'));
    final Rect c1 = tester.getRect(find.text('C1'));
    final Rect c2 = tester.getRect(find.text('C2'));
    final Rect c3 = tester.getRect(find.text('C3'));

    expect(a1.width, equals(100.0));
    expect(a2.width, equals(100.0));
    expect(a3.width, equals(100.0));
    expect(b1.width, equals(110.0));
    expect(b2.width, equals(110.0));
    expect(b3.width, equals(110.0));
    expect(c1.width, equals(125.0));
    expect(c2.width, equals(125.0));
    expect(c3.width, equals(125.0));

    expect(table.width, equals(335.0));

    expect(a1.right, equals(table.right));
    expect(a2.right, equals(a1.right));
    expect(a3.right, equals(a1.right));

    expect(b1.right, equals(table.right - a1.width));
    expect(b2.right, equals(b1.right));
    expect(b3.right, equals(b1.right));

    expect(c1.right, equals(table.right - a1.width - b1.width));
    expect(c2.right, equals(c1.right));
    expect(c3.right, equals(c1.right));
  });

  testWidgets('Table border - smoke test', (WidgetTester tester) async {
211
    Future<void> run(TextDirection textDirection) async {
212
      await tester.pumpWidget(
213
        Directionality(
214
          textDirection: textDirection,
215 216
          child: Table(
            border: TableBorder.all(),
217
            children: const <TableRow>[
218 219 220
              TableRow(
                children: <Widget>[
                  Text('AAAAAA'), Text('B'), Text('C'),
221 222
                ],
              ),
223 224 225
              TableRow(
                children: <Widget>[
                  Text('D'), Text('EEE'), Text('F'),
226 227
                ],
              ),
228 229 230
              TableRow(
                children: <Widget>[
                  Text('G'), Text('H'), Text('III'),
231 232 233
                ],
              ),
            ],
234
          ),
235 236 237 238 239
        ),
      );
    }

    await run(TextDirection.ltr);
240
    await tester.pumpWidget(Container());
241 242 243 244 245
    await run(TextDirection.rtl);
  });

  testWidgets('Table widget - changing table dimensions', (WidgetTester tester) async {
    await tester.pumpWidget(
246
      Directionality(
247
        textDirection: TextDirection.ltr,
248
        child: Table(
249
          children: const <TableRow>[
250 251 252
            TableRow(
              children: <Widget>[
                Text('A'), Text('B'), Text('C'),
253 254
              ],
            ),
255 256 257
            TableRow(
              children: <Widget>[
                Text('D'), Text('E'), Text('F'),
258 259
              ],
            ),
260 261 262
            TableRow(
              children: <Widget>[
                Text('G'), Text('H'), Text('I'),
263 264 265 266 267 268
              ],
            ),
          ],
        ),
      ),
    );
269 270
    final RenderBox boxA1 = tester.renderObject(find.text('A'));
    final RenderBox boxG1 = tester.renderObject(find.text('G'));
271 272
    expect(boxA1, isNotNull);
    expect(boxG1, isNotNull);
273
    await tester.pumpWidget(
274
      Directionality(
275
        textDirection: TextDirection.ltr,
276
        child: Table(
277
          children: const <TableRow>[
278 279 280
            TableRow(
              children: <Widget>[
                Text('a'), Text('b'), Text('c'), Text('d'),
281 282
              ],
            ),
283 284 285
            TableRow(
              children: <Widget>[
                Text('e'), Text('f'), Text('g'), Text('h'),
286 287 288 289 290 291
              ],
            ),
          ],
        ),
      ),
    );
292 293
    final RenderBox boxA2 = tester.renderObject(find.text('a'));
    final RenderBox boxG2 = tester.renderObject(find.text('g'));
294 295 296 297
    expect(boxA2, isNotNull);
    expect(boxG2, isNotNull);
    expect(boxA1, equals(boxA2));
    expect(boxG1, isNot(equals(boxG2)));
Hixie's avatar
Hixie committed
298
  });
299

300
  testWidgets('Table widget - repump test', (WidgetTester tester) async {
301
    await tester.pumpWidget(
302
      Directionality(
303
        textDirection: TextDirection.ltr,
304
        child: Table(
305
          children: const <TableRow>[
306 307 308
            TableRow(
              children: <Widget>[
                Text('AAAAAA'), Text('B'), Text('C'),
309 310
              ],
            ),
311 312 313
            TableRow(
              children: <Widget>[
                Text('D'), Text('EEE'), Text('F'),
314 315
              ],
            ),
316 317 318
            TableRow(
              children: <Widget>[
                Text('G'), Text('H'), Text('III'),
319 320 321 322 323 324 325
              ],
            ),
          ],
        ),
      ),
    );
    await tester.pumpWidget(
326
      Directionality(
327
        textDirection: TextDirection.ltr,
328
        child: Table(
329
          children: const <TableRow>[
330 331 332
            TableRow(
              children: <Widget>[
                Text('AAA'), Text('B'), Text('C'),
333 334
              ],
            ),
335 336 337
            TableRow(
              children: <Widget>[
                Text('D'), Text('E'), Text('FFFFFF'),
338 339
              ],
            ),
340 341 342
            TableRow(
              children: <Widget>[
                Text('G'), Text('H'), Text('III'),
343 344 345 346 347 348
              ],
            ),
          ],
        ),
      ),
    );
349 350 351 352
    final RenderBox boxA = tester.renderObject(find.text('AAA'));
    final RenderBox boxD = tester.renderObject(find.text('D'));
    final RenderBox boxG = tester.renderObject(find.text('G'));
    final RenderBox boxB = tester.renderObject(find.text('B'));
353 354 355
    expect(boxA.size, equals(boxD.size));
    expect(boxA.size, equals(boxG.size));
    expect(boxA.size, equals(boxB.size));
Hixie's avatar
Hixie committed
356
  });
357

358
  testWidgets('Table widget - intrinsic sizing test', (WidgetTester tester) async {
359
    await tester.pumpWidget(
360
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
361
      textDirection: TextDirection.ltr,
362
        child: Table(
363
          defaultColumnWidth: const IntrinsicColumnWidth(),
364
          children: const <TableRow>[
365 366 367
            TableRow(
              children: <Widget>[
                Text('AAA'), Text('B'), Text('C'),
368 369
              ],
            ),
370 371 372
            TableRow(
              children: <Widget>[
                Text('D'), Text('E'), Text('FFFFFF'),
373 374
              ],
            ),
375 376 377
            TableRow(
              children: <Widget>[
                Text('G'), Text('H'), Text('III'),
378 379 380 381 382 383
              ],
            ),
          ],
        ),
      ),
    );
384 385 386 387
    final RenderBox boxA = tester.renderObject(find.text('AAA'));
    final RenderBox boxD = tester.renderObject(find.text('D'));
    final RenderBox boxG = tester.renderObject(find.text('G'));
    final RenderBox boxB = tester.renderObject(find.text('B'));
388 389 390 391
    expect(boxA.size, equals(boxD.size));
    expect(boxA.size, equals(boxG.size));
    expect(boxA.size.width, greaterThan(boxB.size.width));
    expect(boxA.size.height, equals(boxB.size.height));
Hixie's avatar
Hixie committed
392
  });
393

394
  testWidgets('Table widget - intrinsic sizing test, resizing', (WidgetTester tester) async {
395
    await tester.pumpWidget(
396
      Directionality(
397
        textDirection: TextDirection.ltr,
398
        child: Table(
399
          defaultColumnWidth: const IntrinsicColumnWidth(),
400
          children: const <TableRow>[
401 402 403
            TableRow(
              children: <Widget>[
                Text('AAAAAA'), Text('B'), Text('C'),
404 405
              ],
            ),
406 407 408
            TableRow(
              children: <Widget>[
                Text('D'), Text('EEE'), Text('F'),
409 410
              ],
            ),
411 412 413
            TableRow(
              children: <Widget>[
                Text('G'), Text('H'), Text('III'),
414 415 416 417 418 419 420
              ],
            ),
          ],
        ),
      ),
    );
    await tester.pumpWidget(
421
      Directionality(
422
        textDirection: TextDirection.ltr,
423
        child: Table(
424
          defaultColumnWidth: const IntrinsicColumnWidth(),
425
          children: const <TableRow>[
426 427 428
            TableRow(
              children: <Widget>[
                Text('A'), Text('B'), Text('C'),
429 430
              ],
            ),
431 432 433
            TableRow(
              children: <Widget>[
                Text('D'), Text('EEE'), Text('F'),
434 435
              ],
            ),
436 437 438
            TableRow(
              children: <Widget>[
                Text('G'), Text('H'), Text('III'),
439 440 441 442 443 444
              ],
            ),
          ],
        ),
      ),
    );
445 446 447 448
    final RenderBox boxA = tester.renderObject(find.text('A'));
    final RenderBox boxD = tester.renderObject(find.text('D'));
    final RenderBox boxG = tester.renderObject(find.text('G'));
    final RenderBox boxB = tester.renderObject(find.text('B'));
449 450 451 452
    expect(boxA.size, equals(boxD.size));
    expect(boxA.size, equals(boxG.size));
    expect(boxA.size.width, lessThan(boxB.size.width));
    expect(boxA.size.height, equals(boxB.size.height));
Hixie's avatar
Hixie committed
453
  });
454

455
  testWidgets('Table widget - intrinsic sizing test, changing column widths', (WidgetTester tester) async {
456
    await tester.pumpWidget(
457
      Directionality(
458
        textDirection: TextDirection.ltr,
459
        child: Table(
460
          children: const <TableRow>[
461 462 463
            TableRow(
              children: <Widget>[
                Text('AAA'), Text('B'), Text('C'),
464 465
              ],
            ),
466 467 468
            TableRow(
              children: <Widget>[
                Text('D'), Text('E'), Text('FFFFFF'),
469 470
              ],
            ),
471 472 473
            TableRow(
              children: <Widget>[
                Text('G'), Text('H'), Text('III'),
474 475 476 477 478 479 480
              ],
            ),
          ],
        ),
      ),
    );
    await tester.pumpWidget(
481
      Directionality(
482
        textDirection: TextDirection.ltr,
483
        child: Table(
484
          defaultColumnWidth: const IntrinsicColumnWidth(),
485
          children: const <TableRow>[
486 487 488
            TableRow(
              children: <Widget>[
                Text('AAA'), Text('B'), Text('C'),
489 490
              ],
            ),
491 492 493
            TableRow(
              children: <Widget>[
                Text('D'), Text('E'), Text('FFFFFF'),
494 495
              ],
            ),
496 497 498
            TableRow(
              children: <Widget>[
                Text('G'), Text('H'), Text('III'),
499 500 501 502 503 504
              ],
            ),
          ],
        )
      ),
    );
505 506 507 508
    final RenderBox boxA = tester.renderObject(find.text('AAA'));
    final RenderBox boxD = tester.renderObject(find.text('D'));
    final RenderBox boxG = tester.renderObject(find.text('G'));
    final RenderBox boxB = tester.renderObject(find.text('B'));
509 510 511 512
    expect(boxA.size, equals(boxD.size));
    expect(boxA.size, equals(boxG.size));
    expect(boxA.size.width, greaterThan(boxB.size.width));
    expect(boxA.size.height, equals(boxB.size.height));
Hixie's avatar
Hixie committed
513
  });
514

515
  testWidgets('Table widget - moving test', (WidgetTester tester) async {
516
    final List<BuildContext> contexts = <BuildContext>[];
517
    await tester.pumpWidget(
518
      Directionality(
519
        textDirection: TextDirection.ltr,
520
        child: Table(
521
          children: <TableRow>[
522
            TableRow(
523 524
              key: const ValueKey<int>(1),
              children: <Widget>[
525
                StatefulBuilder(
526 527 528 529 530 531 532
                  builder: (BuildContext context, StateSetter setState) {
                    contexts.add(context);
                    return const Text('A');
                  },
                ),
              ],
            ),
533
            const TableRow(
534 535
              children: <Widget>[
                Text('b'),
536 537 538 539 540 541 542
              ],
            ),
          ],
        ),
      ),
    );
    await tester.pumpWidget(
543
      Directionality(
544
        textDirection: TextDirection.ltr,
545
        child: Table(
546
          children: <TableRow>[
547
            const TableRow(
548 549
              children: <Widget>[
                Text('b'),
550 551
              ],
            ),
552
            TableRow(
553 554
              key: const ValueKey<int>(1),
              children: <Widget>[
555
                StatefulBuilder(
556 557 558 559 560 561 562 563 564 565 566
                  builder: (BuildContext context, StateSetter setState) {
                    contexts.add(context);
                    return const Text('A');
                  },
                ),
              ],
            ),
          ],
        ),
      ),
    );
567 568
    expect(contexts.length, equals(2));
    expect(contexts[0], equals(contexts[1]));
Hixie's avatar
Hixie committed
569
  });
570 571

  testWidgets('Table widget - keyed rows', (WidgetTester tester) async {
572
    await tester.pumpWidget(
573
      Directionality(
574
        textDirection: TextDirection.ltr,
575
        child: Table(
576
          children: const <TableRow>[
577 578 579 580 581
            TableRow(
              key: ValueKey<int>(1),
              children: <Widget>[
                TestStatefulWidget(key: ValueKey<int>(11)),
                TestStatefulWidget(key: ValueKey<int>(12)),
582 583
              ],
            ),
584 585 586 587 588
            TableRow(
              key: ValueKey<int>(2),
              children: <Widget>[
                TestStatefulWidget(key: ValueKey<int>(21)),
                TestStatefulWidget(key: ValueKey<int>(22)),
589 590 591 592 593 594
              ],
            ),
          ],
        ),
      ),
    );
595

596 597 598 599
    final TestStatefulWidgetState state11 = tester.state(find.byKey(const ValueKey<int>(11)));
    final TestStatefulWidgetState state12 = tester.state(find.byKey(const ValueKey<int>(12)));
    final TestStatefulWidgetState state21 = tester.state(find.byKey(const ValueKey<int>(21)));
    final TestStatefulWidgetState state22 = tester.state(find.byKey(const ValueKey<int>(22)));
600 601 602 603 604 605

    expect(state11.mounted, isTrue);
    expect(state12.mounted, isTrue);
    expect(state21.mounted, isTrue);
    expect(state22.mounted, isTrue);

606
    await tester.pumpWidget(
607
      Directionality(
608
        textDirection: TextDirection.ltr,
609
        child: Table(
610
          children: const <TableRow>[
611 612 613 614 615
            TableRow(
              key: ValueKey<int>(2),
              children: <Widget>[
                TestStatefulWidget(key: ValueKey<int>(21)),
                TestStatefulWidget(key: ValueKey<int>(22)),
616 617 618 619 620 621
              ],
            ),
          ],
        ),
      ),
    );
622 623 624 625 626 627 628 629

    expect(state11.mounted, isFalse);
    expect(state12.mounted, isFalse);
    expect(state21.mounted, isTrue);
    expect(state22.mounted, isTrue);
  });

  testWidgets('Table widget - global key reparenting', (WidgetTester tester) async {
630 631
    final GlobalKey key = GlobalKey();
    final Key tableKey = UniqueKey();
632 633

    await tester.pumpWidget(
634
      Directionality(
635
        textDirection: TextDirection.ltr,
636
        child: Column(
637
          children: <Widget> [
638
            Expanded(
639
              key: tableKey,
640
              child: Table(
641
                children: <TableRow>[
642
                  TableRow(
643
                    children: <Widget>[
644 645 646
                      Container(key: const ValueKey<int>(1)),
                      TestStatefulWidget(key: key),
                      Container(key: const ValueKey<int>(2)),
647 648 649 650
                    ],
                  ),
                ],
              ),
651
            ),
652 653
          ],
        ),
654 655 656
      ),
    );

657
    final RenderTable table = tester.renderObject(find.byType(Table));
658 659 660
    expect(table.row(0).length, 3);

    await tester.pumpWidget(
661
      Directionality(
662
        textDirection: TextDirection.ltr,
663
        child: Column(
664
          children: <Widget> [
665 666
            Expanded(child: TestStatefulWidget(key: key)),
            Expanded(
667
              key: tableKey,
668
              child: Table(
669
                children: <TableRow>[
670
                  TableRow(
671
                    children: <Widget>[
672 673
                      Container(key: const ValueKey<int>(1)),
                      Container(key: const ValueKey<int>(2)),
674 675 676 677
                    ],
                  ),
                ],
              ),
678
            ),
679 680
          ],
        ),
681 682 683 684 685 686 687
      ),
    );

    expect(tester.renderObject(find.byType(Table)), equals(table));
    expect(table.row(0).length, 2);

    await tester.pumpWidget(
688
      Directionality(
689
        textDirection: TextDirection.ltr,
690
        child: Column(
691
          children: <Widget> [
692
            Expanded(
693
              key: tableKey,
694
              child: Table(
695
                children: <TableRow>[
696
                  TableRow(
697
                    children: <Widget>[
698 699 700
                      Container(key: const ValueKey<int>(1)),
                      TestStatefulWidget(key: key),
                      Container(key: const ValueKey<int>(2)),
701 702 703 704
                    ],
                  ),
                ],
              ),
705
            ),
706 707
          ],
        ),
708 709 710 711 712 713 714
      ),
    );

    expect(tester.renderObject(find.byType(Table)), equals(table));
    expect(table.row(0).length, 3);

    await tester.pumpWidget(
715
      Directionality(
716
        textDirection: TextDirection.ltr,
717
        child: Column(
718
          children: <Widget> [
719
            Expanded(
720
              key: tableKey,
721
              child: Table(
722
                children: <TableRow>[
723
                  TableRow(
724
                    children: <Widget>[
725 726
                      Container(key: const ValueKey<int>(1)),
                      Container(key: const ValueKey<int>(2)),
727 728 729 730
                    ],
                  ),
                ],
              ),
731
            ),
732
            Expanded(child: TestStatefulWidget(key: key)),
733 734
          ],
        ),
735 736 737 738 739 740 741
      ),
    );

    expect(tester.renderObject(find.byType(Table)), equals(table));
    expect(table.row(0).length, 2);
  });

742 743
  testWidgets('Table widget diagnostics', (WidgetTester tester) async {
    GlobalKey key0;
744
    final Widget table = Directionality(
Ian Hickson's avatar
Ian Hickson committed
745
      textDirection: TextDirection.ltr,
746 747
      child: Table(
        key: key0 = GlobalKey(),
748
        defaultColumnWidth: const IntrinsicColumnWidth(),
749
        children: const <TableRow>[
750 751 752
          TableRow(
            children: <Widget>[
              Text('A'), Text('B'), Text('C'),
Ian Hickson's avatar
Ian Hickson committed
753
            ],
754
          ),
755 756 757
          TableRow(
            children: <Widget>[
              Text('D'), Text('EEE'), Text('F'),
Ian Hickson's avatar
Ian Hickson committed
758
            ],
759
          ),
760 761 762
          TableRow(
            children: <Widget>[
              Text('G'), Text('H'), Text('III'),
Ian Hickson's avatar
Ian Hickson committed
763
            ],
764
          ),
Ian Hickson's avatar
Ian Hickson committed
765 766 767
        ],
      ),
    );
768 769
    await tester.pumpWidget(table);
    final RenderObjectElement element = key0.currentContext;
770 771
    expect(element, hasAGoodToStringDeep);
    expect(
772
      element.toStringDeep(minLevel: DiagnosticLevel.info),
773
      equalsIgnoringHashCodes(
774
        'Table-[GlobalKey#00000](renderObject: RenderTable#00000)\n'
775
        '├Text("A")\n'
776
        '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "A", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
777
        '├Text("B")\n'
778
        '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "B", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
779
        '├Text("C")\n'
780
        '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "C", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
781
        '├Text("D")\n'
782
        '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "D", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
783
        '├Text("EEE")\n'
784
        '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "EEE", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
785
        '├Text("F")\n'
786
        '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "F", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
787
        '├Text("G")\n'
788
        '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "G", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
789
        '├Text("H")\n'
790
        '│└RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "H", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
791
        '└Text("III")\n'
792
        ' └RichText(softWrap: wrapping at box width, maxLines: unlimited, text: "III", renderObject: RenderParagraph#00000 relayoutBoundary=up1)\n'
793 794
      ),
    );
795 796
  });

Hixie's avatar
Hixie committed
797 798
  // TODO(ianh): Test handling of TableCell object
}