wrap_test.dart 28.4 KB
Newer Older
Adam Barth's avatar
Adam Barth committed
1 2 3 4 5 6 7 8 9 10
// 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';

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

11 12 13
void verify(WidgetTester tester, List<Offset> answerKey) {
  final List<Offset> testAnswers = tester.renderObjectList<RenderBox>(find.byType(SizedBox)).map<Offset>(
    (RenderBox target) => target.localToGlobal(Offset.zero)
Adam Barth's avatar
Adam Barth committed
14 15 16 17 18
  ).toList();
  expect(testAnswers, equals(answerKey));
}

void main() {
19
  testWidgets('Basic Wrap test (LTR)', (WidgetTester tester) async {
Adam Barth's avatar
Adam Barth committed
20 21 22
    await tester.pumpWidget(
      new Wrap(
        alignment: WrapAlignment.start,
23
        textDirection: TextDirection.ltr,
24
        children: const <Widget>[
25 26 27 28
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
Adam Barth's avatar
Adam Barth committed
29 30 31
        ],
      ),
    );
32 33 34 35 36
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      const Offset(300.0, 0.0),
      const Offset(0.0, 100.0),
      const Offset(300.0, 100.0),
Adam Barth's avatar
Adam Barth committed
37 38 39 40 41
    ]);

    await tester.pumpWidget(
      new Wrap(
        alignment: WrapAlignment.center,
42
        textDirection: TextDirection.ltr,
43
        children: const <Widget>[
44 45 46 47
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
Adam Barth's avatar
Adam Barth committed
48 49 50
        ],
      ),
    );
51 52 53 54 55
    verify(tester, <Offset>[
      const Offset(100.0, 0.0),
      const Offset(400.0, 0.0),
      const Offset(100.0, 100.0),
      const Offset(400.0, 100.0),
Adam Barth's avatar
Adam Barth committed
56 57 58 59 60
    ]);

    await tester.pumpWidget(
      new Wrap(
        alignment: WrapAlignment.end,
61
        textDirection: TextDirection.ltr,
62
        children: const <Widget>[
63 64 65 66
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
Adam Barth's avatar
Adam Barth committed
67 68 69
        ],
      ),
    );
70 71 72 73 74
    verify(tester, <Offset>[
      const Offset(200.0, 0.0),
      const Offset(500.0, 0.0),
      const Offset(200.0, 100.0),
      const Offset(500.0, 100.0),
Adam Barth's avatar
Adam Barth committed
75 76 77 78 79 80
    ]);

    await tester.pumpWidget(
      new Wrap(
        alignment: WrapAlignment.start,
        crossAxisAlignment: WrapCrossAlignment.start,
81
        textDirection: TextDirection.ltr,
82
        children: const <Widget>[
83 84 85 86
          SizedBox(width: 300.0, height: 50.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 50.0),
Adam Barth's avatar
Adam Barth committed
87 88 89
        ],
      ),
    );
90 91 92 93 94
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      const Offset(300.0, 0.0),
      const Offset(0.0, 100.0),
      const Offset(300.0, 100.0),
Adam Barth's avatar
Adam Barth committed
95 96 97 98 99 100
    ]);

    await tester.pumpWidget(
      new Wrap(
        alignment: WrapAlignment.start,
        crossAxisAlignment: WrapCrossAlignment.center,
101
        textDirection: TextDirection.ltr,
102
        children: const <Widget>[
103 104 105 106
          SizedBox(width: 300.0, height: 50.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 50.0),
Adam Barth's avatar
Adam Barth committed
107 108 109
        ],
      ),
    );
110 111 112 113 114
    verify(tester, <Offset>[
      const Offset(0.0, 25.0),
      const Offset(300.0, 0.0),
      const Offset(0.0, 100.0),
      const Offset(300.0, 125.0),
Adam Barth's avatar
Adam Barth committed
115 116 117 118 119 120
    ]);

    await tester.pumpWidget(
      new Wrap(
        alignment: WrapAlignment.start,
        crossAxisAlignment: WrapCrossAlignment.end,
121
        textDirection: TextDirection.ltr,
122
        children: const <Widget>[
123 124 125 126
          SizedBox(width: 300.0, height: 50.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 50.0),
Adam Barth's avatar
Adam Barth committed
127 128 129
        ],
      ),
    );
130 131 132 133 134
    verify(tester, <Offset>[
      const Offset(0.0, 50.0),
      const Offset(300.0, 0.0),
      const Offset(0.0, 100.0),
      const Offset(300.0, 150.0),
Adam Barth's avatar
Adam Barth committed
135 136 137 138
    ]);

  });

139 140 141 142 143
  testWidgets('Basic Wrap test (RTL)', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Wrap(
        alignment: WrapAlignment.start,
        textDirection: TextDirection.rtl,
144
        children: const <Widget>[
145 146 147 148
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
149 150 151 152 153 154 155 156 157 158 159 160 161 162
        ],
      ),
    );
    verify(tester, <Offset>[
      const Offset(500.0, 0.0),
      const Offset(200.0, 0.0),
      const Offset(500.0, 100.0),
      const Offset(200.0, 100.0),
    ]);

    await tester.pumpWidget(
      new Wrap(
        alignment: WrapAlignment.center,
        textDirection: TextDirection.rtl,
163
        children: const <Widget>[
164 165 166 167
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
168 169 170 171 172 173 174 175 176 177 178 179 180 181
        ],
      ),
    );
    verify(tester, <Offset>[
      const Offset(400.0, 0.0),
      const Offset(100.0, 0.0),
      const Offset(400.0, 100.0),
      const Offset(100.0, 100.0),
    ]);

    await tester.pumpWidget(
      new Wrap(
        alignment: WrapAlignment.end,
        textDirection: TextDirection.rtl,
182
        children: const <Widget>[
183 184 185 186
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
        ],
      ),
    );
    verify(tester, <Offset>[
      const Offset(300.0, 0.0),
      const Offset(0.0, 0.0),
      const Offset(300.0, 100.0),
      const Offset(0.0, 100.0),
    ]);

    await tester.pumpWidget(
      new Wrap(
        alignment: WrapAlignment.start,
        crossAxisAlignment: WrapCrossAlignment.start,
        textDirection: TextDirection.ltr,
        verticalDirection: VerticalDirection.up,
203
        children: const <Widget>[
204 205 206 207
          SizedBox(width: 300.0, height: 50.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 50.0),
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
        ],
      ),
    );
    verify(tester, <Offset>[
      const Offset(0.0, 550.0),
      const Offset(300.0, 500.0),
      const Offset(0.0, 400.0),
      const Offset(300.0, 450.0),
    ]);

    await tester.pumpWidget(
      new Wrap(
        alignment: WrapAlignment.start,
        crossAxisAlignment: WrapCrossAlignment.center,
        textDirection: TextDirection.ltr,
        verticalDirection: VerticalDirection.up,
224
        children: const <Widget>[
225 226 227 228
          SizedBox(width: 300.0, height: 50.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 50.0),
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
        ],
      ),
    );
    verify(tester, <Offset>[
      const Offset(0.0, 525.0),
      const Offset(300.0, 500.0),
      const Offset(0.0, 400.0),
      const Offset(300.0, 425.0),
    ]);

    await tester.pumpWidget(
      new Wrap(
        alignment: WrapAlignment.start,
        crossAxisAlignment: WrapCrossAlignment.end,
        textDirection: TextDirection.ltr,
        verticalDirection: VerticalDirection.up,
245
        children: const <Widget>[
246 247 248 249
          SizedBox(width: 300.0, height: 50.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 50.0),
250 251 252 253 254 255 256 257 258 259 260 261
        ],
      ),
    );
    verify(tester, <Offset>[
      const Offset(0.0, 500.0),
      const Offset(300.0, 500.0),
      const Offset(0.0, 400.0),
      const Offset(300.0, 400.0),
    ]);

  });

Adam Barth's avatar
Adam Barth committed
262
  testWidgets('Empty wrap', (WidgetTester tester) async {
263
    await tester.pumpWidget(new Center(child: new Wrap(alignment: WrapAlignment.center)));
Adam Barth's avatar
Adam Barth committed
264 265 266
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(Size.zero));
  });

267
  testWidgets('Wrap alignment (LTR)', (WidgetTester tester) async {
Adam Barth's avatar
Adam Barth committed
268 269 270
    await tester.pumpWidget(new Wrap(
      alignment: WrapAlignment.center,
      spacing: 5.0,
271
      textDirection: TextDirection.ltr,
272
      children: const <Widget>[
273 274 275
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
Adam Barth's avatar
Adam Barth committed
276 277 278
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
279 280 281 282
    verify(tester, <Offset>[
      const Offset(95.0, 0.0),
      const Offset(200.0, 0.0),
      const Offset(405.0, 0.0),
Adam Barth's avatar
Adam Barth committed
283 284 285 286 287
    ]);

    await tester.pumpWidget(new Wrap(
      alignment: WrapAlignment.spaceBetween,
      spacing: 5.0,
288
      textDirection: TextDirection.ltr,
289
      children: const <Widget>[
290 291 292
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
Adam Barth's avatar
Adam Barth committed
293 294 295
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
296 297 298 299
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      const Offset(200.0, 0.0),
      const Offset(500.0, 0.0),
Adam Barth's avatar
Adam Barth committed
300 301 302 303 304
    ]);

    await tester.pumpWidget(new Wrap(
      alignment: WrapAlignment.spaceAround,
      spacing: 5.0,
305
      textDirection: TextDirection.ltr,
306
      children: const <Widget>[
307 308 309
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 310.0, height: 30.0),
Adam Barth's avatar
Adam Barth committed
310 311 312
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
313 314 315 316
    verify(tester, <Offset>[
      const Offset(30.0, 0.0),
      const Offset(195.0, 0.0),
      const Offset(460.0, 0.0),
Adam Barth's avatar
Adam Barth committed
317 318 319 320 321
    ]);

    await tester.pumpWidget(new Wrap(
      alignment: WrapAlignment.spaceEvenly,
      spacing: 5.0,
322
      textDirection: TextDirection.ltr,
323
      children: const <Widget>[
324 325 326
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 310.0, height: 30.0),
Adam Barth's avatar
Adam Barth committed
327 328 329
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
330 331 332 333
    verify(tester, <Offset>[
      const Offset(45.0, 0.0),
      const Offset(195.0, 0.0),
      const Offset(445.0, 0.0),
Adam Barth's avatar
Adam Barth committed
334 335 336
    ]);
  });

337 338 339 340 341
  testWidgets('Wrap alignment (RTL)', (WidgetTester tester) async {
    await tester.pumpWidget(new Wrap(
      alignment: WrapAlignment.center,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
342
      children: const <Widget>[
343 344 345
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
346 347 348 349 350 351 352 353 354 355 356 357 358
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(605.0, 0.0),
      const Offset(400.0, 0.0),
      const Offset(95.0, 0.0),
    ]);

    await tester.pumpWidget(new Wrap(
      alignment: WrapAlignment.spaceBetween,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
359
      children: const <Widget>[
360 361 362
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
363 364 365 366 367 368 369 370 371 372 373 374 375
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(700.0, 0.0),
      const Offset(400.0, 0.0),
      const Offset(0.0, 0.0),
    ]);

    await tester.pumpWidget(new Wrap(
      alignment: WrapAlignment.spaceAround,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
376
      children: const <Widget>[
377 378 379
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 310.0, height: 30.0),
380 381 382 383 384 385 386 387 388 389 390 391 392
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(670.0, 0.0),
      const Offset(405.0, 0.0),
      const Offset(30.0, 0.0),
    ]);

    await tester.pumpWidget(new Wrap(
      alignment: WrapAlignment.spaceEvenly,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
393
      children: const <Widget>[
394 395 396
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 310.0, height: 30.0),
397 398 399 400 401 402 403 404 405 406 407
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(655.0, 0.0),
      const Offset(405.0, 0.0),
      const Offset(45.0, 0.0),
    ]);
  });

  testWidgets('Wrap runAlignment (DOWN)', (WidgetTester tester) async {
Adam Barth's avatar
Adam Barth committed
408 409 410
    await tester.pumpWidget(new Wrap(
      runAlignment: WrapAlignment.center,
      runSpacing: 5.0,
411
      textDirection: TextDirection.ltr,
412
      children: const <Widget>[
413 414 415 416 417
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 60.0),
Adam Barth's avatar
Adam Barth committed
418 419 420
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
421 422 423 424 425 426
    verify(tester, <Offset>[
      const Offset(0.0, 230.0),
      const Offset(100.0, 230.0),
      const Offset(300.0, 230.0),
      const Offset(0.0, 265.0),
      const Offset(0.0, 310.0),
Adam Barth's avatar
Adam Barth committed
427 428 429 430 431
    ]);

    await tester.pumpWidget(new Wrap(
      runAlignment: WrapAlignment.spaceBetween,
      runSpacing: 5.0,
432
      textDirection: TextDirection.ltr,
433
      children: const <Widget>[
434 435 436 437 438
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 60.0),
Adam Barth's avatar
Adam Barth committed
439 440 441
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
442 443 444 445 446 447
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      const Offset(100.0, 0.0),
      const Offset(300.0, 0.0),
      const Offset(0.0, 265.0),
      const Offset(0.0, 540.0),
Adam Barth's avatar
Adam Barth committed
448 449 450 451 452
    ]);

    await tester.pumpWidget(new Wrap(
      runAlignment: WrapAlignment.spaceAround,
      runSpacing: 5.0,
453
      textDirection: TextDirection.ltr,
454
      children: const <Widget>[
455 456 457 458 459
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 70.0),
Adam Barth's avatar
Adam Barth committed
460 461 462
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
463 464 465 466 467 468
    verify(tester, <Offset>[
      const Offset(0.0, 75.0),
      const Offset(100.0, 75.0),
      const Offset(300.0, 75.0),
      const Offset(0.0, 260.0),
      const Offset(0.0, 455.0),
Adam Barth's avatar
Adam Barth committed
469 470 471 472 473
    ]);

    await tester.pumpWidget(new Wrap(
      runAlignment: WrapAlignment.spaceEvenly,
      runSpacing: 5.0,
474
      textDirection: TextDirection.ltr,
475
      children: const <Widget>[
476 477 478 479 480
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 60.0),
Adam Barth's avatar
Adam Barth committed
481 482 483
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
484 485 486 487 488 489
    verify(tester, <Offset>[
      const Offset(0.0, 115.0),
      const Offset(100.0, 115.0),
      const Offset(300.0, 115.0),
      const Offset(0.0, 265.0),
      const Offset(0.0, 425.0),
Adam Barth's avatar
Adam Barth committed
490 491 492 493
    ]);

  });

494 495 496 497 498 499
  testWidgets('Wrap runAlignment (UP)', (WidgetTester tester) async {
    await tester.pumpWidget(new Wrap(
      runAlignment: WrapAlignment.center,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
500
      children: const <Widget>[
501 502 503 504 505
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 60.0),
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(0.0, 360.0),
      const Offset(100.0, 350.0),
      const Offset(300.0, 340.0),
      const Offset(0.0, 295.0),
      const Offset(0.0, 230.0),
    ]);

    await tester.pumpWidget(new Wrap(
      runAlignment: WrapAlignment.spaceBetween,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
522
      children: const <Widget>[
523 524 525 526 527
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 60.0),
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(0.0, 590.0),
      const Offset(100.0, 580.0),
      const Offset(300.0, 570.0),
      const Offset(0.0, 295.0),
      const Offset(0.0, 0.0),
    ]);

    await tester.pumpWidget(new Wrap(
      runAlignment: WrapAlignment.spaceAround,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
544
      children: const <Widget>[
545 546 547 548 549
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 70.0),
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(0.0, 515.0),
      const Offset(100.0, 505.0),
      const Offset(300.0, 495.0),
      const Offset(0.0, 300.0),
      const Offset(0.0, 75.0),
    ]);

    await tester.pumpWidget(new Wrap(
      runAlignment: WrapAlignment.spaceEvenly,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
566
      children: const <Widget>[
567 568 569 570 571
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 60.0),
572 573 574 575 576 577 578 579 580 581 582 583 584
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(0.0, 475.0),
      const Offset(100.0, 465.0),
      const Offset(300.0, 455.0),
      const Offset(0.0, 295.0),
      const Offset(0.0, 115.0),
    ]);

  });

Adam Barth's avatar
Adam Barth committed
585 586 587
  testWidgets('Shrink-wrapping Wrap test', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Align(
588
        alignment: Alignment.topLeft,
Adam Barth's avatar
Adam Barth committed
589 590 591
        child: new Wrap(
          alignment: WrapAlignment.end,
          crossAxisAlignment: WrapCrossAlignment.end,
592
          textDirection: TextDirection.ltr,
593
          children: const <Widget>[
594 595 596 597
            SizedBox(width: 100.0, height: 10.0),
            SizedBox(width: 200.0, height: 20.0),
            SizedBox(width: 300.0, height: 30.0),
            SizedBox(width: 400.0, height: 40.0),
Adam Barth's avatar
Adam Barth committed
598 599 600 601 602
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(600.0, 70.0)));
603 604 605 606 607
    verify(tester, <Offset>[
      const Offset(0.0, 20.0),
      const Offset(100.0, 10.0),
      const Offset(300.0, 0.0),
      const Offset(200.0, 30.0),
Adam Barth's avatar
Adam Barth committed
608 609 610 611
    ]);

    await tester.pumpWidget(
      new Align(
612
        alignment: Alignment.topLeft,
Adam Barth's avatar
Adam Barth committed
613 614 615
        child: new Wrap(
          alignment: WrapAlignment.end,
          crossAxisAlignment: WrapCrossAlignment.end,
616
          textDirection: TextDirection.ltr,
617
          children: const <Widget>[
618 619 620 621
            SizedBox(width: 400.0, height: 40.0),
            SizedBox(width: 300.0, height: 30.0),
            SizedBox(width: 200.0, height: 20.0),
            SizedBox(width: 100.0, height: 10.0),
Adam Barth's avatar
Adam Barth committed
622 623 624 625 626
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(700.0, 60.0)));
627 628 629 630 631
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      const Offset(400.0, 10.0),
      const Offset(400.0, 40.0),
      const Offset(600.0, 50.0),
Adam Barth's avatar
Adam Barth committed
632 633 634 635 636 637
    ]);
  });

  testWidgets('Wrap spacing test', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Align(
638
        alignment: Alignment.topLeft,
Adam Barth's avatar
Adam Barth committed
639 640 641 642
        child: new Wrap(
          runSpacing: 10.0,
          alignment: WrapAlignment.start,
          crossAxisAlignment: WrapCrossAlignment.start,
643
          textDirection: TextDirection.ltr,
644
          children: const <Widget>[
645 646 647 648
            SizedBox(width: 500.0, height: 10.0),
            SizedBox(width: 500.0, height: 20.0),
            SizedBox(width: 500.0, height: 30.0),
            SizedBox(width: 500.0, height: 40.0),
Adam Barth's avatar
Adam Barth committed
649 650 651 652 653
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(500.0, 130.0)));
654 655 656 657 658
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      const Offset(0.0, 20.0),
      const Offset(0.0, 50.0),
      const Offset(0.0, 90.0),
Adam Barth's avatar
Adam Barth committed
659 660 661 662 663 664
    ]);
  });

  testWidgets('Vertical Wrap test with spacing', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Align(
665
        alignment: Alignment.topLeft,
Adam Barth's avatar
Adam Barth committed
666 667 668 669 670 671
        child: new Wrap(
          direction: Axis.vertical,
          spacing: 10.0,
          runSpacing: 15.0,
          alignment: WrapAlignment.start,
          crossAxisAlignment: WrapCrossAlignment.start,
672
          textDirection: TextDirection.ltr,
673
          children: const <Widget>[
674 675 676 677 678 679
            SizedBox(width: 10.0, height: 250.0),
            SizedBox(width: 20.0, height: 250.0),
            SizedBox(width: 30.0, height: 250.0),
            SizedBox(width: 40.0, height: 250.0),
            SizedBox(width: 50.0, height: 250.0),
            SizedBox(width: 60.0, height: 250.0),
Adam Barth's avatar
Adam Barth committed
680 681 682 683 684
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(150.0, 510.0)));
685 686 687 688 689 690 691
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      const Offset(0.0, 260.0),
      const Offset(35.0, 0.0),
      const Offset(35.0, 260.0),
      const Offset(90.0, 0.0),
      const Offset(90.0, 260.0),
Adam Barth's avatar
Adam Barth committed
692 693 694 695
    ]);

    await tester.pumpWidget(
      new Align(
696
        alignment: Alignment.topLeft,
Adam Barth's avatar
Adam Barth committed
697 698 699 700
        child: new Wrap(
          direction: Axis.horizontal,
          spacing: 12.0,
          runSpacing: 8.0,
701
          textDirection: TextDirection.ltr,
702
          children: const <Widget>[
703 704 705 706 707 708
            SizedBox(width: 10.0, height: 250.0),
            SizedBox(width: 20.0, height: 250.0),
            SizedBox(width: 30.0, height: 250.0),
            SizedBox(width: 40.0, height: 250.0),
            SizedBox(width: 50.0, height: 250.0),
            SizedBox(width: 60.0, height: 250.0),
Adam Barth's avatar
Adam Barth committed
709 710 711 712
          ],
        ),
      ),
    );
713
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(270.0, 250.0)));
714 715 716 717 718 719 720
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      const Offset(22.0, 0.0),
      const Offset(54.0, 0.0),
      const Offset(96.0, 0.0),
      const Offset(148.0, 0.0),
      const Offset(210.0, 0.0),
Adam Barth's avatar
Adam Barth committed
721 722 723 724 725
    ]);
  });

  testWidgets('Visual overflow generates a clip', (WidgetTester tester) async {
    await tester.pumpWidget(new Wrap(
726
      textDirection: TextDirection.ltr,
727
      children: const <Widget>[
728
        SizedBox(width: 500.0, height: 500.0),
Adam Barth's avatar
Adam Barth committed
729 730 731 732 733 734
      ],
    ));

    expect(tester.renderObject<RenderBox>(find.byType(Wrap)), isNot(paints..clipRect()));

    await tester.pumpWidget(new Wrap(
735
      textDirection: TextDirection.ltr,
736
      children: const <Widget>[
737 738
        SizedBox(width: 500.0, height: 500.0),
        SizedBox(width: 500.0, height: 500.0),
Adam Barth's avatar
Adam Barth committed
739 740 741 742 743 744 745 746 747 748 749 750
      ],
    ));

    expect(tester.renderObject<RenderBox>(find.byType(Wrap)), paints..clipRect());
  });

  testWidgets('Hit test children in wrap', (WidgetTester tester) async {
    final List<String> log = <String>[];

    await tester.pumpWidget(new Wrap(
      spacing: 10.0,
      runSpacing: 15.0,
751
      textDirection: TextDirection.ltr,
Adam Barth's avatar
Adam Barth committed
752
      children: <Widget>[
753 754 755 756
        const SizedBox(width: 200.0, height: 300.0),
        const SizedBox(width: 200.0, height: 300.0),
        const SizedBox(width: 200.0, height: 300.0),
        const SizedBox(width: 200.0, height: 300.0),
Adam Barth's avatar
Adam Barth committed
757 758 759 760 761 762 763 764 765 766 767
        new SizedBox(
          width: 200.0,
          height: 300.0,
          child: new GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () { log.add('hit'); },
          ),
        ),
      ],
    ));

768
    await tester.tapAt(const Offset(209.0, 314.0));
Adam Barth's avatar
Adam Barth committed
769 770
    expect(log, isEmpty);

771
    await tester.tapAt(const Offset(211.0, 314.0));
Adam Barth's avatar
Adam Barth committed
772 773
    expect(log, isEmpty);

774
    await tester.tapAt(const Offset(209.0, 316.0));
Adam Barth's avatar
Adam Barth committed
775 776
    expect(log, isEmpty);

777
    await tester.tapAt(const Offset(211.0, 316.0));
Adam Barth's avatar
Adam Barth committed
778 779 780 781
    expect(log, equals(<String>['hit']));
  });

  testWidgets('RenderWrap toStringShallow control test', (WidgetTester tester) async {
782
    await tester.pumpWidget(new Wrap(alignment: WrapAlignment.center));
Adam Barth's avatar
Adam Barth committed
783 784 785 786 787 788 789 790 791

    final RenderBox wrap = tester.renderObject(find.byType(Wrap));
    expect(wrap.toStringShallow(), hasOneLineDescription);
  });

  testWidgets('RenderWrap toString control test', (WidgetTester tester) async {
    await tester.pumpWidget(new Wrap(
      direction: Axis.vertical,
      runSpacing: 7.0,
792
      textDirection: TextDirection.ltr,
793
      children: const <Widget>[
794 795 796 797
        SizedBox(width: 500.0, height: 400.0),
        SizedBox(width: 500.0, height: 400.0),
        SizedBox(width: 500.0, height: 400.0),
        SizedBox(width: 500.0, height: 400.0),
Adam Barth's avatar
Adam Barth committed
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
      ],
    ));

    final RenderBox wrap = tester.renderObject(find.byType(Wrap));
    final double width = wrap.getMinIntrinsicWidth(600.0);
    expect(width, equals(2021));
  });

  testWidgets('Wrap baseline control test', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Center(
        child: new Baseline(
          baseline: 180.0,
          baselineType: TextBaseline.alphabetic,
          child: new DefaultTextStyle(
            style: const TextStyle(
              fontFamily: 'Ahem',
              fontSize: 100.0,
            ),
            child: new Wrap(
818
              textDirection: TextDirection.ltr,
819
              children: const <Widget>[
820
                Text('X', textDirection: TextDirection.ltr),
Adam Barth's avatar
Adam Barth committed
821 822 823 824 825 826 827
              ],
            ),
          ),
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.text('X')).size, const Size(100.0, 100.0));
828 829
    expect(tester.renderObject<RenderBox>(find.byType(Baseline)).size,
           within<Size>(from: const Size(100.0, 200.0), distance: 0.001));
Adam Barth's avatar
Adam Barth committed
830
  });
831 832 833 834 835 836 837

  testWidgets('Spacing with slight overflow', (WidgetTester tester) async {
    await tester.pumpWidget(new Wrap(
      direction: Axis.horizontal,
      textDirection: TextDirection.ltr,
      spacing: 10.0,
      runSpacing: 10.0,
838
      children: const <Widget>[
839 840 841 842
        SizedBox(width: 200.0, height: 10.0),
        SizedBox(width: 200.0, height: 10.0),
        SizedBox(width: 200.0, height: 10.0),
        SizedBox(width: 171.0, height: 10.0),
843 844 845 846 847 848 849 850 851 852 853
      ],
    ));

    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      const Offset(210.0, 0.0),
      const Offset(420.0, 0.0),
      const Offset(0.0, 20.0)
    ]);
  });
854 855

  testWidgets('Object exactly matches container width', (WidgetTester tester) async {
856 857 858 859 860 861 862 863 864
    await tester.pumpWidget(
      new Column(
        children: <Widget>[
          new Wrap(
            direction: Axis.horizontal,
            textDirection: TextDirection.ltr,
            spacing: 10.0,
            runSpacing: 10.0,
            children: const <Widget>[
865
              SizedBox(width: 800.0, height: 10.0),
866 867 868 869 870
            ],
          ),
        ],
      )
    );
871

872
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 10.0)));
873
    verify(tester, <Offset>[const Offset(0.0, 0.0)]);
874 875 876 877 878 879 880 881 882 883

    await tester.pumpWidget(
      new Column(
        children: <Widget>[
          new Wrap(
            direction: Axis.horizontal,
            textDirection: TextDirection.ltr,
            spacing: 10.0,
            runSpacing: 10.0,
            children: const <Widget>[
884 885
              SizedBox(width: 800.0, height: 10.0),
              SizedBox(width: 800.0, height: 10.0),
886 887 888 889 890 891 892 893 894 895 896
            ],
          ),
        ],
      )
    );

    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 30.0)));
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      const Offset(0.0, 20.0),
    ]);
897
  });
Adam Barth's avatar
Adam Barth committed
898
}