Skip to content

Commit

Permalink
Fix disclosure_navigation_hybrid test, support platform specific key …
Browse files Browse the repository at this point in the history
…conversion to key chord
  • Loading branch information
stalgiag committed Nov 22, 2024
1 parent 25084fd commit ef0f7ba
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
12 changes: 12 additions & 0 deletions test/tests/disclosure_navigation_hybrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ ariaTest(

if (links.length > 0) {
await buttons[b].click();
// Add explicit wait for menu visibility
await t.context.session.wait(
async () => await menus[b].isDisplayed(),
1000,
'Menu should be displayed'
);
// Ensure link is interactive
await t.context.session.wait(
async () => await links[0].isEnabled(),
1000,
'Link should be enabled'
);
await links[0].click();

t.is(
Expand Down
10 changes: 5 additions & 5 deletions test/tests/toolbar_toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const assertAttributeValues = require('../util/assertAttributeValues');
const assertRovingTabindex = require('../util/assertRovingTabindex');
const assertHasFocus = require('../util/assertHasFocus');
const assertAttributeCanBeToggled = require('../util/assertAttributeCanBeToggled');
const getOSPreferredModifierKey = require('../util/getOSPreferredModifierKey');
const translatePlatformKey = require('../util/translatePlatformKey');

const exampleFile = 'content/patterns/toolbar/examples/toolbar.html';

Expand Down Expand Up @@ -1116,8 +1116,8 @@ ariaTest(
'toolbar-button-enter-or-space',
async (t) => {
let textarea = await t.context.session.findElement(By.css('textarea'));
let modifierKey = getOSPreferredModifierKey();
await textarea.sendKeys(Key.chord(modifierKey, 'a'));
let modifierKey = translatePlatformKey(Key.CONTROL);
await textarea.sendKeys(Key.chord(...modifierKey, 'a'));
let originalText = await textarea.getAttribute('value');

const buttons = await t.context.queryElements(
Expand Down Expand Up @@ -1208,8 +1208,8 @@ ariaTest(
'toolbar-button-enter-or-space',
async (t) => {
let textarea = await t.context.session.findElement(By.css('textarea'));
let modifierKey = getOSPreferredModifierKey();
await textarea.sendKeys(Key.chord(modifierKey, 'a'));
let modifierKey = translatePlatformKey(Key.CONTROL);
await textarea.sendKeys(Key.chord(...modifierKey, 'a'));
let originalText = await textarea.getAttribute('value');

const buttons = await t.context.queryElements(
Expand Down
6 changes: 0 additions & 6 deletions test/util/getOSPreferredModifierKey.js

This file was deleted.

5 changes: 5 additions & 0 deletions test/util/isMacOS.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Returns true if the current platform is macOS
*
* @returns {boolean}
*/
module.exports = function isMacOS() {
return process.platform === 'darwin';
};
26 changes: 26 additions & 0 deletions test/util/translatePlatformKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { Key } = require('selenium-webdriver');
const isMacOS = require('./isMacOS');

const MAC_KEY_MAPPINGS = {
[Key.CONTROL]: Key.META,
};

/**
* Translates a key or key combination for the current OS
*
* @param {string|string[]} keys - The key(s) to translate
* @returns {string[]} - The translated key(s) as a flat array ready for spreading
*/
function translatePlatformKey(keys) {
const keyArray = Array.isArray(keys) ? keys : [keys];
if (!isMacOS()) {
return keyArray;
}

return keyArray.reduce((acc, key) => {
const mappedKey = MAC_KEY_MAPPINGS[key] || key;
return acc.concat(mappedKey);
}, []);
}

module.exports = translatePlatformKey;

0 comments on commit ef0f7ba

Please sign in to comment.