Skip to content

Commit

Permalink
EWPP-3916: Update tasks tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
imanoleguskiza authored and 22Alexandra committed Feb 21, 2024
1 parent c9c2867 commit 52682a4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 33 deletions.
51 changes: 20 additions & 31 deletions tests/src/Kernel/MenuLocalTasksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Drupal\Tests\oe_theme\Kernel;

use Drupal\Core\Url;
use Symfony\Component\DomCrawler\Crawler;
use Drupal\Tests\oe_theme\PatternAssertions\TabsAssert;

/**
* Tests that Drupal local tasks are properly rendered.
Expand Down Expand Up @@ -54,36 +54,25 @@ public function testMenuLocalTasks(): void {
];

$html = $this->renderRoot($render);
$crawler = new Crawler($html);

// Assert wrapper contains ECL class.
$actual = $crawler->filter('nav.ecl-navigation');
$this->assertCount(1, $actual);

// Assert list contains ECL classes.
$actual = $crawler->filter('ul.ecl-navigation.ecl-u-pb-m.ecl-u-pt-m');
$this->assertCount(1, $actual);

// Assert active link contains ECL classes.
$actual = $crawler->filter('li.ecl-navigation__item--active')->text();
$this->assertEquals('Third link - Active', trim($actual));

// Assert regular link contains ECL classes and the links are ordered by
// weight.
$actual = $crawler->filter('li.ecl-navigation__item > a')
->eq(0)
->text();
$this->assertEquals('First link - Inactive', trim($actual));

$actual = $crawler->filter('li.ecl-navigation__item > a')
->eq(1)
->text();
$this->assertEquals('Second link', trim($actual));

$actual = $crawler->filter('li.ecl-navigation__item > a')
->eq(2)
->text();
$this->assertEquals('Third link - Active', trim($actual));
$expected_items = [
'items' => [
[
'label' => 'First link - Inactive',
'path' => 'http://www.inactive.com',
],
[
'label' => 'Second link',
'path' => 'http://www.middlelink.com',
],
[
'label' => 'Third link - Active',
'path' => 'http://www.active.com',
'is_current' => TRUE,
],
],
];
$assert = new TabsAssert();
$assert->assertPattern($expected_items, $html);
}

}
4 changes: 2 additions & 2 deletions tests/src/PatternAssertions/TabsAssert.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace Drupal\Tests\oe_theme\PatternAssertions;

Expand Down Expand Up @@ -42,7 +42,7 @@ protected function assertBaseElements(string $html, string $variant): void {
* The DomCrawler where to check the element.
*/
protected function assertItems(array $expected_items, Crawler $crawler): void {
$item_elements = $crawler->filter('div.ecl-tabs__item');
$item_elements = $crawler->filter('div.ecl-tabs__item:not(.ecl-tabs__item--more)');
self::assertCount(count($expected_items), $item_elements);
foreach ($expected_items as $index => $expected_item) {
$item_element = $item_elements->eq($index);
Expand Down

0 comments on commit 52682a4

Please sign in to comment.