MOBILE-3947 behat: Fix isSelected function

main
Pau Ferrer Ocaña 2023-12-13 17:43:28 +01:00
parent d912d9d9af
commit 2335ff8010
1 changed files with 17 additions and 8 deletions

View File

@ -77,16 +77,25 @@ export class TestingBehatDomUtilsService {
* *
* @param element Element. * @param element Element.
* @param container Container. * @param container Container.
* @param firstCall Whether this is the first call of the function.
* @returns Whether the element is selected or not. * @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'); const ariaCurrent = element.getAttribute('aria-current');
if ( const ariaSelected = element.getAttribute('aria-selected');
(ariaCurrent && ariaCurrent !== 'false') || const ariaChecked = element.getAttribute('aria-checked');
(element.getAttribute('aria-selected') === 'true') ||
(element.getAttribute('aria-checked') === 'true') if (ariaCurrent || ariaSelected || ariaChecked) {
) { return (!!ariaCurrent && ariaCurrent !== 'false') ||
return true; (!!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); const parentElement = this.getParentElement(element);
@ -94,7 +103,7 @@ export class TestingBehatDomUtilsService {
return false; return false;
} }
return this.isElementSelected(parentElement, container); return this.isElementSelected(parentElement, container, false);
} }
/** /**