Skip to content

Commit

Permalink
MOBILE-3947 behat: Fix isSelected function
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyserver committed Dec 14, 2023
1 parent d912d9d commit 2335ff8
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/testing/services/behat-dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,33 @@ export class TestingBehatDomUtilsService {
*
* @param element Element.
* @param container Container.
* @param firstCall Whether this is the first call of the function.
* @returns Whether the element is selected or not.
*/
isElementSelected(element: HTMLElement, container: HTMLElement): boolean {
isElementSelected(element: HTMLElement, container: HTMLElement, firstCall = true): boolean {
const ariaCurrent = element.getAttribute('aria-current');
if (
(ariaCurrent && ariaCurrent !== 'false') ||
(element.getAttribute('aria-selected') === 'true') ||
(element.getAttribute('aria-checked') === 'true')
) {
return true;
const ariaSelected = element.getAttribute('aria-selected');
const ariaChecked = element.getAttribute('aria-checked');

if (ariaCurrent || ariaSelected || ariaChecked) {
return (!!ariaCurrent && ariaCurrent !== 'false') ||
(!!ariaSelected && ariaSelected === 'true') ||
(!!ariaChecked && ariaChecked === 'true');
}

if (firstCall) {
const inputElement = element.closest('ion-checkbox, ion-radio, ion-toggle')?.querySelector('input');
if (inputElement) {
return inputElement.value === 'on';
}
}

const parentElement = this.getParentElement(element);
if (!parentElement || parentElement === container) {
return false;
}

return this.isElementSelected(parentElement, container);
return this.isElementSelected(parentElement, container, false);
}

/**
Expand Down

0 comments on commit 2335ff8

Please sign in to comment.