|
1 | 1 | """Tests for position property.""" |
2 | 2 |
|
| 3 | +import pytest |
| 4 | + |
3 | 5 | from ..testing_utils import assert_no_logs, render_pages |
4 | 6 |
|
5 | 7 |
|
@@ -445,3 +447,96 @@ def test_fixed_positioning_regression_2(): |
445 | 447 | assert (article.position_x, article.position_y) == (15, 20) |
446 | 448 | header, = article.children |
447 | 449 | assert (header.position_x, header.position_y) == (5, 10) |
| 450 | + |
| 451 | + |
| 452 | +@assert_no_logs |
| 453 | +def test_flex_relative_positioning(): |
| 454 | + page, = render_pages(''' |
| 455 | + <style> |
| 456 | + @page { size: 100px 100px } |
| 457 | + article { display: flex } |
| 458 | + .box { width: 20px; height: 20px } |
| 459 | + .relative { position: relative; top: 10px; left: 10px } |
| 460 | + </style> |
| 461 | + <article> |
| 462 | + <div class="box"></div> |
| 463 | + <div class="box relative"></div> |
| 464 | + </article> |
| 465 | + ''') |
| 466 | + html, = page.children |
| 467 | + body, = html.children |
| 468 | + article, = body.children |
| 469 | + div1, div2 = article.children |
| 470 | + |
| 471 | + assert (div2.position_x, div2.position_y) == (30, 10) |
| 472 | + |
| 473 | + |
| 474 | +@assert_no_logs |
| 475 | +def test_grid_relative_positioning(): |
| 476 | + page, = render_pages(''' |
| 477 | + <style> |
| 478 | + @page { size: 100px 100px } |
| 479 | + article { display: grid; grid-template-columns: 20px 20px } |
| 480 | + .box { width: 20px; height: 20px } |
| 481 | + .relative { position: relative; top: 10px; left: 10px } |
| 482 | + </style> |
| 483 | + <article> |
| 484 | + <div class="box"></div> |
| 485 | + <div class="box relative"></div> |
| 486 | + </article> |
| 487 | + ''') |
| 488 | + html, = page.children |
| 489 | + body, = html.children |
| 490 | + article, = body.children |
| 491 | + div1, div2 = article.children |
| 492 | + |
| 493 | + assert (div2.position_x, div2.position_y) == (30, 10) |
| 494 | + |
| 495 | + |
| 496 | +@assert_no_logs |
| 497 | +@pytest.mark.xfail |
| 498 | +def test_flex_absolute_positioning(): |
| 499 | + """TODO: Order is not kept when out-of-flow and in-flow children are mixed.""" |
| 500 | + page, = render_pages(''' |
| 501 | + <style> |
| 502 | + @page { size: 100px 100px } |
| 503 | + article { display: flex; position: relative } |
| 504 | + .box { width: 20px; height: 20px } |
| 505 | + .absolute { position: absolute; top: 10px; left: 10px } |
| 506 | + </style> |
| 507 | + <article> |
| 508 | + <div class="box"></div> |
| 509 | + <div class="box absolute"></div> |
| 510 | + </article> |
| 511 | + ''') |
| 512 | + html, = page.children |
| 513 | + body, = html.children |
| 514 | + article, = body.children |
| 515 | + # That’s currently div2, div1 |
| 516 | + div1, div2 = article.children |
| 517 | + |
| 518 | + assert (div2.position_x, div2.position_y) == (10, 10) |
| 519 | + |
| 520 | + |
| 521 | +@assert_no_logs |
| 522 | +@pytest.mark.xfail |
| 523 | +def test_grid_absolute_positioning(): |
| 524 | + """TODO: Absolutely positioned grid items are not replaced by placeholders .""" |
| 525 | + page, = render_pages(''' |
| 526 | + <style> |
| 527 | + @page { size: 100px 100px } |
| 528 | + article { display: grid; grid-template-columns: 20px 20px; position: relative } |
| 529 | + .box { width: 20px; height: 20px } |
| 530 | + .absolute { position: absolute; top: 10px; left: 10px } |
| 531 | + </style> |
| 532 | + <article> |
| 533 | + <div class="box"></div> |
| 534 | + <div class="box absolute"></div> |
| 535 | + </article> |
| 536 | + ''') |
| 537 | + html, = page.children |
| 538 | + body, = html.children |
| 539 | + article, = body.children |
| 540 | + div1, div2 = article.children |
| 541 | + |
| 542 | + assert (div1.position_x, div1.position_y) == (10, 10) |
0 commit comments