wrap_test.dart 27 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,
Adam Barth's avatar
Adam Barth committed
24
        children: <Widget>[
25 26 27 28
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const 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,
Adam Barth's avatar
Adam Barth committed
43
        children: <Widget>[
44 45 46 47
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const 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,
Adam Barth's avatar
Adam Barth committed
62
        children: <Widget>[
63 64 65 66
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const 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,
Adam Barth's avatar
Adam Barth committed
82
        children: <Widget>[
83 84 85 86
          const SizedBox(width: 300.0, height: 50.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const 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,
Adam Barth's avatar
Adam Barth committed
102
        children: <Widget>[
103 104 105 106
          const SizedBox(width: 300.0, height: 50.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const 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,
Adam Barth's avatar
Adam Barth committed
122
        children: <Widget>[
123 124 125 126
          const SizedBox(width: 300.0, height: 50.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const 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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 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 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
  testWidgets('Basic Wrap test (RTL)', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Wrap(
        alignment: WrapAlignment.start,
        textDirection: TextDirection.rtl,
        children: <Widget>[
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
        ],
      ),
    );
    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,
        children: <Widget>[
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
        ],
      ),
    );
    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,
        children: <Widget>[
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
        ],
      ),
    );
    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,
        children: <Widget>[
          const SizedBox(width: 300.0, height: 50.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 50.0),
        ],
      ),
    );
    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,
        children: <Widget>[
          const SizedBox(width: 300.0, height: 50.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 50.0),
        ],
      ),
    );
    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,
        children: <Widget>[
          const SizedBox(width: 300.0, height: 50.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 100.0),
          const SizedBox(width: 300.0, height: 50.0),
        ],
      ),
    );
    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,
Adam Barth's avatar
Adam Barth committed
272
      children: <Widget>[
273 274 275
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const 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,
Adam Barth's avatar
Adam Barth committed
289
      children: <Widget>[
290 291 292
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const 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,
Adam Barth's avatar
Adam Barth committed
306
      children: <Widget>[
307 308 309
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const 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,
Adam Barth's avatar
Adam Barth committed
323
      children: <Widget>[
324 325 326
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const 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 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
  testWidgets('Wrap alignment (RTL)', (WidgetTester tester) async {
    await tester.pumpWidget(new Wrap(
      alignment: WrapAlignment.center,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
      children: <Widget>[
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const SizedBox(width: 300.0, height: 30.0),
      ],
    ));
    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,
      children: <Widget>[
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const SizedBox(width: 300.0, height: 30.0),
      ],
    ));
    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,
      children: <Widget>[
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const SizedBox(width: 310.0, height: 30.0),
      ],
    ));
    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,
      children: <Widget>[
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const SizedBox(width: 310.0, height: 30.0),
      ],
    ));
    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,
Adam Barth's avatar
Adam Barth committed
412
      children: <Widget>[
413 414 415 416 417
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const SizedBox(width: 300.0, height: 30.0),
        const SizedBox(width: 400.0, height: 40.0),
        const 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,
Adam Barth's avatar
Adam Barth committed
433
      children: <Widget>[
434 435 436 437 438
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const SizedBox(width: 300.0, height: 30.0),
        const SizedBox(width: 400.0, height: 40.0),
        const 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,
Adam Barth's avatar
Adam Barth committed
454
      children: <Widget>[
455 456 457 458 459
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const SizedBox(width: 300.0, height: 30.0),
        const SizedBox(width: 400.0, height: 40.0),
        const 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,
Adam Barth's avatar
Adam Barth committed
475
      children: <Widget>[
476 477 478 479 480
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const SizedBox(width: 300.0, height: 30.0),
        const SizedBox(width: 400.0, height: 40.0),
        const 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 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
  testWidgets('Wrap runAlignment (UP)', (WidgetTester tester) async {
    await tester.pumpWidget(new Wrap(
      runAlignment: WrapAlignment.center,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
      children: <Widget>[
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const SizedBox(width: 300.0, height: 30.0),
        const SizedBox(width: 400.0, height: 40.0),
        const SizedBox(width: 500.0, height: 60.0),
      ],
    ));
    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,
      children: <Widget>[
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const SizedBox(width: 300.0, height: 30.0),
        const SizedBox(width: 400.0, height: 40.0),
        const SizedBox(width: 500.0, height: 60.0),
      ],
    ));
    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,
      children: <Widget>[
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const SizedBox(width: 300.0, height: 30.0),
        const SizedBox(width: 400.0, height: 40.0),
        const SizedBox(width: 500.0, height: 70.0),
      ],
    ));
    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,
      children: <Widget>[
        const SizedBox(width: 100.0, height: 10.0),
        const SizedBox(width: 200.0, height: 20.0),
        const SizedBox(width: 300.0, height: 30.0),
        const SizedBox(width: 400.0, height: 40.0),
        const SizedBox(width: 500.0, height: 60.0),
      ],
    ));
    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 588 589 590 591
  testWidgets('Shrink-wrapping Wrap test', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Align(
        alignment: FractionalOffset.topLeft,
        child: new Wrap(
          alignment: WrapAlignment.end,
          crossAxisAlignment: WrapCrossAlignment.end,
592
          textDirection: TextDirection.ltr,
Adam Barth's avatar
Adam Barth committed
593
          children: <Widget>[
594 595 596 597
            const SizedBox(width: 100.0, height: 10.0),
            const SizedBox(width: 200.0, height: 20.0),
            const SizedBox(width: 300.0, height: 30.0),
            const 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 612 613 614 615
    ]);

    await tester.pumpWidget(
      new Align(
        alignment: FractionalOffset.topLeft,
        child: new Wrap(
          alignment: WrapAlignment.end,
          crossAxisAlignment: WrapCrossAlignment.end,
616
          textDirection: TextDirection.ltr,
Adam Barth's avatar
Adam Barth committed
617
          children: <Widget>[
618 619 620 621
            const SizedBox(width: 400.0, height: 40.0),
            const SizedBox(width: 300.0, height: 30.0),
            const SizedBox(width: 200.0, height: 20.0),
            const 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 638 639 640 641 642
    ]);
  });

  testWidgets('Wrap spacing test', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Align(
        alignment: FractionalOffset.topLeft,
        child: new Wrap(
          runSpacing: 10.0,
          alignment: WrapAlignment.start,
          crossAxisAlignment: WrapCrossAlignment.start,
643
          textDirection: TextDirection.ltr,
Adam Barth's avatar
Adam Barth committed
644
          children: <Widget>[
645 646 647 648
            const SizedBox(width: 500.0, height: 10.0),
            const SizedBox(width: 500.0, height: 20.0),
            const SizedBox(width: 500.0, height: 30.0),
            const 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 665 666 667 668 669 670 671
    ]);
  });

  testWidgets('Vertical Wrap test with spacing', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Align(
        alignment: FractionalOffset.topLeft,
        child: new Wrap(
          direction: Axis.vertical,
          spacing: 10.0,
          runSpacing: 15.0,
          alignment: WrapAlignment.start,
          crossAxisAlignment: WrapCrossAlignment.start,
672
          textDirection: TextDirection.ltr,
Adam Barth's avatar
Adam Barth committed
673
          children: <Widget>[
674 675 676 677 678 679
            const SizedBox(width: 10.0, height: 250.0),
            const SizedBox(width: 20.0, height: 250.0),
            const SizedBox(width: 30.0, height: 250.0),
            const SizedBox(width: 40.0, height: 250.0),
            const SizedBox(width: 50.0, height: 250.0),
            const 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 696 697 698 699 700
    ]);

    await tester.pumpWidget(
      new Align(
        alignment: FractionalOffset.topLeft,
        child: new Wrap(
          direction: Axis.horizontal,
          spacing: 12.0,
          runSpacing: 8.0,
701
          textDirection: TextDirection.ltr,
Adam Barth's avatar
Adam Barth committed
702
          children: <Widget>[
703 704 705 706 707 708
            const SizedBox(width: 10.0, height: 250.0),
            const SizedBox(width: 20.0, height: 250.0),
            const SizedBox(width: 30.0, height: 250.0),
            const SizedBox(width: 40.0, height: 250.0),
            const SizedBox(width: 50.0, height: 250.0),
            const 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, 258.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,
Adam Barth's avatar
Adam Barth committed
727
      children: <Widget>[
728
        const 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,
Adam Barth's avatar
Adam Barth committed
736
      children: <Widget>[
737 738
        const SizedBox(width: 500.0, height: 500.0),
        const 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,
Adam Barth's avatar
Adam Barth committed
793
      children: <Widget>[
794 795 796 797
        const SizedBox(width: 500.0, height: 400.0),
        const SizedBox(width: 500.0, height: 400.0),
        const SizedBox(width: 500.0, height: 400.0),
        const 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,
Adam Barth's avatar
Adam Barth committed
819
              children: <Widget>[
Ian Hickson's avatar
Ian Hickson committed
820
                const Text('X', textDirection: TextDirection.ltr),
Adam Barth's avatar
Adam Barth committed
821 822 823 824 825 826 827 828 829 830
              ],
            ),
          ),
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.text('X')).size, const Size(100.0, 100.0));
    expect(tester.renderObject<RenderBox>(find.byType(Baseline)).size, const Size(100.0, 200.0));
  });
}