Skip to content

Commit

Permalink
OEL-2166: Fix pager test.
Browse files Browse the repository at this point in the history
  • Loading branch information
drishu committed Jan 19, 2023
1 parent cd49759 commit eb122e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
8 changes: 3 additions & 5 deletions tests/src/Kernel/PagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ public function testViewsMiniPager(array $expected_args, int $page): void {
],
];
$html = $this->renderRoot($element);

$pagination_assert = new PaginationPatternAssert();

$pagination_assert->assertPattern($expected_args, $html);
}

Expand All @@ -266,17 +264,17 @@ public function testViewsMiniPager(array $expected_args, int $page): void {
public function viewsMiniPagerDataProvider(): array {
$scenarios = [
0 => [
['url' => '', 'label' => '1'],
['label' => '1'],
['url' => '/?page=1', 'label' => 'The next'],
],
1 => [
['url' => '/?page=0', 'label' => 'The previous'],
['url' => '', 'label' => '2'],
['label' => '2'],
['url' => '/?page=2', 'label' => 'The next'],
],
7 => [
['url' => '/?page=6', 'label' => 'The previous'],
['url' => '', 'label' => '8'],
['label' => '8'],
],
];
$datasets = [];
Expand Down
17 changes: 11 additions & 6 deletions tests/src/PatternAssertion/PaginationPatternAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,27 @@ protected function assertLinks(array $expected, Crawler $crawler): void {
$this->assertCounts([
// Fail on unexpected additional <li> or <a> anywhere in the html.
'li' => $expected_count,
'a' => $expected_count,
'.page-link' => $expected_count,
// Fail if classes are missing or the structure is wrong.
// The :first-child makes sure that each <li> has exactly one <a>.
'nav > ul > li.page-item > a.page-link:first-child' => $expected_count,
'nav > ul > li.page-item > .page-link:first-child' => $expected_count,
], $crawler);

$icon_pattern_assert = new IconPatternAssert();

$actual_items_selection = $crawler->filter('nav > ul > li');

foreach ($expected as $i => $expected_item) {
$li = $actual_items_selection->eq($i);
$this->assertCount(1, $li);
$link = $li->filter('a');
$this->assertCount(1, $link);
$this->assertSame($expected_item['url'], $link->attr('href'));
$link = $li->filter('.page-link');

if (isset($expected_item['url'])) {
$this->assertCount(1, $link);
$this->assertSame($expected_item['url'], $link->attr('href'));
}
else {
$this->assertNull($link->attr('href'));
}
if (isset($expected_item['icon'])) {
$icon_pattern_assert->assertPattern([
'name' => $expected_item['icon'],
Expand Down

0 comments on commit eb122e7

Please sign in to comment.