Skip to content

Commit

Permalink
Merge pull request #444 from openeuropa/OEL-3421
Browse files Browse the repository at this point in the history
OEL-3421: Prerelease bcl.
  • Loading branch information
tibi2303 authored Nov 5, 2024
2 parents e1ec9c1 + ed2b219 commit 6ab0c45
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ services:
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=drupal
selenium:
image: git.fpfis.tech.ec.europa.eu/fpfis/dependency_proxy/containers/selenium/standalone-chrome:4.1.3-20220405
environment:
- DISPLAY=:99
- NODE_MAX_INSTANCES=5
- NODE_MAX_SESSION=5

pipeline:
npm-build:
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ services:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
# ports:
# - 3306:3306
selenium:
image: selenium/standalone-chrome:4.1.3
environment:
- DISPLAY=:99
- VNC_NO_PASSWORD=1
ports:
- '5900:5900'
expose:
- '4444'
shm_size: 2g
node:
image: node:18.12.0
user: "node"
Expand Down
1 change: 1 addition & 0 deletions oe_bootstrap_theme.libraries.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bcl:
js:
assets/js/oe-bcl-default.bundle.min.js: {}
resources/js/accessible_toggle.js: {}
css:
theme:
assets/css/oe-bcl-default.min.css: {}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"production": "npm-run-all build:*"
},
"devDependencies": {
"@openeuropa/bcl-builder": "1.6.0",
"@openeuropa/bcl-theme-default": "1.6.0",
"@openeuropa/bcl-builder": "0.1.202411051450",
"@openeuropa/bcl-theme-default": "0.1.202411051450",
"bootstrap-ie11": "5.0.2",
"chokidar-cli": "^3.0.0",
"copyfiles": "2.4.1",
Expand Down
2 changes: 2 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<env name="SIMPLETEST_IGNORE_DIRECTORIES" value="vendor,node_modules,${drupal.root}"/>
<env name="SIMPLETEST_BASE_URL" value="${drupal.base_url}"/>
<env name="SIMPLETEST_DB" value="mysql://${drupal.database.user}:${drupal.database.password}@${drupal.database.host}:${drupal.database.port}/${drupal.database.name}"/>
<!-- @todo When dropping support for 10.2.x, rename "chromeOptions" to "goog:chromeOptions". -->
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value='["${selenium.browser}", {"browserName":"chrome","chromeOptions":{"w3c": false, "args":["--no-sandbox", "--start-maximized", "--disable-gpu", "--window-size=1280,800", "--disable-dev-shm-usage", "--DNS-prefetch-disable", "--disable-translate", "--ignore-certificate-errors", "--test-type", "--disable-extensions", "--incognito", "--disable-infobars"]}}, "${selenium.host}:${selenium.port}/wd/hub"]'/>
</php>
<testsuites>
<testsuite name="OpenEuropa Bootstrap Theme">
Expand Down
25 changes: 25 additions & 0 deletions resources/js/accessible_toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @file
* Attaches behaviors for accessible Bootstrap components.
*/
(function (bootstrap, Drupal) {

/**
* Attaches the accessible toggle behavior to Bootstrap components.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Initializes AccessibleToggle for specified Bootstrap components.
*/
Drupal.behaviors.accessibleToggle = {
attach: function (context, settings) {
bootstrap.AccessibleToggle.init([
{ selector: '[data-bs-toggle="modal"]', type: 'modal' },
{ selector: '[data-bs-toggle="offcanvas"]', type: 'offcanvas' }
// Additional components like collapse can be added here in the future.
]);
}
};

})(bootstrap, Drupal);
5 changes: 5 additions & 0 deletions runner.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ drupal:
- "vendor"
- "${drupal.root}"

selenium:
host: "http://selenium"
port: "4444"
browser: "chrome"

commands:
drupal:site-setup:
- { task: "run", command: "drupal:symlink-project" }
Expand Down
76 changes: 76 additions & 0 deletions tests/src/FunctionalJavascript/AccessibleToggleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types=1);

namespace Drupal\Tests\oe_bootstrap_theme\FunctionalJavascript;

use Behat\Mink\Element\NodeElement;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;

/**
* Tests the AccessibleToggle behavior for modal and offcanvas.
*/
class AccessibleToggleTest extends WebDriverTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'oe_bootstrap_theme';

/**
* {@inheritdoc}
*/
protected static $modules = [
'oe_bootstrap_theme_helper',
'system',
'ui_patterns',
'ui_patterns_library',
'ui_patterns_settings',
];

/**
* Tests the ARIA attributes for modal and offcanvas triggers.
*/
public function testAccessibleToggleAttributes(): void {
$this->drupalLogin($this->drupalCreateUser([], NULL, TRUE));
$this->drupalGet('/admin/appearance/ui/patterns');

$modalTrigger = $this->getSession()->getPage()->find('css', '[data-bs-toggle="modal"]');
$offcanvasTrigger = $this->getSession()->getPage()->find('css', '[data-bs-toggle="offcanvas"]');

$this->assertAccessibleAttributes($modalTrigger, expanded: FALSE);
$this->assertAccessibleAttributes($offcanvasTrigger, expanded: FALSE);

$modalTrigger->click();
$this->assertAccessibleAttributes($modalTrigger, expanded: TRUE);
$this->assertAccessibleAttributes($offcanvasTrigger, expanded: FALSE);

$this->getSession()->getPage()->find('css', '.modal .btn-close')->click();
$this->assertAccessibleAttributes($modalTrigger, expanded: FALSE);
$this->assertAccessibleAttributes($offcanvasTrigger, expanded: FALSE);

$offcanvasTrigger->click();
$this->assertAccessibleAttributes($modalTrigger, expanded: FALSE);
$this->assertAccessibleAttributes($offcanvasTrigger, expanded: TRUE);

// Close offcanvas and check attribute updates.
$this->getSession()->getPage()->find('css', '.offcanvas-backdrop')->click();
$this->assertAccessibleAttributes($modalTrigger, expanded: FALSE);
$this->assertAccessibleAttributes($offcanvasTrigger, expanded: FALSE);
}

/**
* Asserts the initial ARIA attributes for the triggers.
*
* @param \Behat\Mink\Element\NodeElement|null $trigger
* The trigger element.
* @param bool $expanded
* The expected state of aria-expanded attribute.
*/
protected function assertAccessibleAttributes(?NodeElement $trigger, bool $expanded): void {
$this->assertNotNull($trigger);
$this->assertEquals('true', $trigger->getAttribute('aria-haspopup'));
$this->assertEquals($expanded ? 'true' : 'false', $trigger->getAttribute('aria-expanded'));
}

}

0 comments on commit 6ab0c45

Please sign in to comment.