Skip to content

Commit

Permalink
EWPP-2098: Adapt site header selectors in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
22Alexandra committed Jun 2, 2022
1 parent d0eccf9 commit 04ca340
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
10 changes: 5 additions & 5 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ default:
breadcrumb: "nav.ecl-breadcrumb"
dropdown content: ".ecl-unordered-list"
language switcher: ".ecl-language-list"
language switcher link: ".ecl-site-header-core__language-selector, .ecl-site-header-standardised__language-selector"
language switcher link: ".ecl-site-header__language-selector"
language switcher links: ".ecl-language-list--overlay"
list item: ".ecl-content-item"
list item image: ".ecl-content-item__image__before"
logo: "a.ecl-site-header-core__logo-link .ecl-site-header-core__logo-image, a.ecl-site-header-standardised__logo-link .ecl-site-header-standardised__logo-image"
logo: "a.ecl-site-header__logo-link .ecl-site-header__logo-image"
footer logo: "a.ecl-footer-core__logo-link .ecl-footer-core__logo-image-desktop, a.ecl-footer-standardised__logo-link .ecl-footer-standardised__logo-image-desktop"
media container: ".ecl-media-container"
page header: ".ecl-page-header"
priorities dropdown menu: ".ecl-menu__item:nth-child(3) .ecl-menu__mega"
search form: ".ecl-search-form"
navigation menu: ".ecl-menu"
site name: ".ecl-site-header-standardised__site-name"
site name: ".ecl-site-header__site-name"
pages:
content management: "/en/admin/content"
ECL components overview: "/en/components"
Expand Down Expand Up @@ -68,8 +68,8 @@ default:
region_map:
about dropdown menu: ".ecl-menu__item:nth-child(2) .ecl-menu__mega"
footer: "footer.ecl-footer-core, footer.ecl-footer-standardised"
header: ".ecl-site-header-core, .ecl-site-header-standardised"
header with menu: ".ecl-site-header-core[data-ecl-has-menu], .ecl-site-header-standardised[data-ecl-has-menu]"
header: ".ecl-site-header"
header with menu: ".ecl-site-header[data-ecl-has-menu]"
language dialog: ".ecl-dialog"
language switcher: ".ecl-language-list"
navigation: ".ecl-menu"
Expand Down
27 changes: 10 additions & 17 deletions tests/src/Behat/OeThemeTestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ public function assertEuMobileLogo(string $language): void {
];
$lang_code = array_merge($lang_code, $available_non_eu_logos);
$langcode = $lang_code[$language] ?? 'en';
$this->assertSession()->elementExists('css', 'img.ecl-site-header-' . $this->getEclBranding() . '__logo-image-mobile');
$this->assertSession()->elementAttributeContains('css', 'img.ecl-site-header-' . $this->getEclBranding() . '__logo-image-mobile', 'src', 'oe_theme/dist/eu/images/logo/condensed-version/positive/logo-eu--' . $langcode . '.svg');
$this->assertSession()->elementExists('css', 'img.ecl-site-header__logo-image-mobile');
$this->assertSession()->elementAttributeContains('css', 'img.ecl-site-header__logo-image-mobile', 'src', 'oe_theme/dist/eu/images/logo/condensed-version/positive/logo-eu--' . $langcode . '.svg');
}

/**
Expand All @@ -407,7 +407,7 @@ public function assertHeaderLogoAccessibility(string $language): void {
$component_library = \Drupal::config($theme_name . '.settings')->get('component_library');
$eu_official_languages = $this->getEuLanguages();

$link_selector = '.ecl-site-header-' . $this->getEclBranding() . '__logo-link';
$link_selector = '.ecl-site-header__logo-link';
$link = $this->getSession()->getPage()->find('css', $link_selector);
if ($component_library === 'ec') {
$href = !empty($eu_official_languages[$language]) ? 'https://ec.europa.eu/info/index_' . $eu_official_languages[$language] : 'https://ec.europa.eu/info';
Expand Down Expand Up @@ -437,25 +437,18 @@ public function assertHeaderLogoAccessibility(string $language): void {
* @Then I should see the :ecl_branding site header
*/
public function iShouldSeeTheSiteHeader(string $ecl_branding): void {
$brandings = [
'Core' => 'core',
'Standardised' => 'standardised',
];

if (empty($brandings[$ecl_branding])) {
throw new \Exception("Theme do not support '$ecl_branding' ECL branding.");
if (!in_array($ecl_branding, ['Core', 'Standardised'])) {
throw new \Exception("Theme does not support '$ecl_branding' ECL branding. The only supported brandings and 'Core' and 'Standardised'");
}

$ecl_branding_code = $brandings[$ecl_branding];

$this->assertSession()->elementExists('css', 'a.ecl-site-header-' . $ecl_branding_code . '__logo-link .ecl-site-header-' . $ecl_branding_code . '__logo-image');
$this->assertSession()->elementExists('css', '.ecl-site-header-' . $ecl_branding_code . '__top .ecl-site-header-' . $ecl_branding_code . '__action .ecl-site-header-' . $ecl_branding_code . '__language-selector');
$this->assertSession()->elementExists('css', '.ecl-site-header-' . $ecl_branding_code . '__top .ecl-site-header-' . $ecl_branding_code . '__action .ecl-site-header-' . $ecl_branding_code . '__search-container');
$this->assertSession()->elementExists('css', 'a.ecl-site-header__logo-link .ecl-site-header__logo-image');
$this->assertSession()->elementExists('css', '.ecl-site-header__top .ecl-site-header__action .ecl-site-header__language-selector');
$this->assertSession()->elementExists('css', '.ecl-site-header__top .ecl-site-header__action .ecl-site-header__search-container');
$site_name_method = 'elementExists';
if ($ecl_branding_code == 'core') {
if ($ecl_branding == 'Core') {
$site_name_method = 'elementNotExists';
}
$this->assertSession()->{$site_name_method}('css', '.ecl-site-header-' . $ecl_branding_code . '__banner');
$this->assertSession()->{$site_name_method}('css', '.ecl-site-header__banner');

}

Expand Down
12 changes: 6 additions & 6 deletions tests/src/Functional/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ public function testChangeEclBranding(): void {
$this->drupalGet('<front>');

// Make sure that classes for Core template is present.
$assert_session->elementExists('css', 'header.ecl-site-header-core div.ecl-site-header-core__top');
$assert_session->elementExists('css', 'header.ecl-site-header-core div.ecl-site-header-core__top div.ecl-site-header-core__action');
$assert_session->elementExists('css', 'header.ecl-site-header div.ecl-site-header__top');
$assert_session->elementExists('css', 'header.ecl-site-header div.ecl-site-header__top div.ecl-site-header__action');

// Make sure that 'Site name' banner is not present in the site header
// for Core template.
$assert_session->elementNotExists('css', 'header.ecl-site-header-core .ecl-site-header-standardised__banner .ecl-container');
$assert_session->elementNotExists('css', 'header.ecl-site-header .ecl-site-header__banner .ecl-container');

// Visit theme administration page.
$this->drupalGet('/admin/appearance/settings/' . $active_theme);
Expand All @@ -202,11 +202,11 @@ public function testChangeEclBranding(): void {
$this->drupalGet('<front>');

// Make sure that classes for Standardised branding is present.
$assert_session->elementExists('css', 'header.ecl-site-header-standardised .ecl-site-header-standardised__header div.ecl-site-header-standardised__top');
$assert_session->elementExists('css', 'header.ecl-site-header-standardised .ecl-site-header-standardised__header div.ecl-site-header-standardised__top div.ecl-site-header-standardised__action');
$assert_session->elementExists('css', 'header.ecl-site-header .ecl-site-header__header div.ecl-site-header__top');
$assert_session->elementExists('css', 'header.ecl-site-header .ecl-site-header__header div.ecl-site-header__top div.ecl-site-header__action');
// Make sure that 'Site name' banner is present in the site header
// for Standardised template.
$assert_session->elementExists('css', 'header.ecl-site-header-standardised .ecl-site-header-standardised__banner .ecl-container');
$assert_session->elementExists('css', 'header.ecl-site-header .ecl-site-header__banner .ecl-container');
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/LanguageSwitcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function testLanguageSwitcherRendering(string $langcode, string $lang_pre
$actual = $crawler->filter('a[data-ecl-language-selector]')->text();
$this->assertStringContainsString($language_name, $actual);

$actual = $crawler->filter('a[data-ecl-language-selector] .ecl-site-header-core__language-code')->text();
$actual = $crawler->filter('a[data-ecl-language-selector] .ecl-site-header__language-code')->text();
$this->assertEquals($lang_prefix, $actual);

// Make sure that the actual language link is set as active.
Expand Down

0 comments on commit 04ca340

Please sign in to comment.