diff --git a/src/core/directives/swipe-navigation.ts b/src/core/directives/swipe-navigation.ts index ffff2497e..927446d40 100644 --- a/src/core/directives/swipe-navigation.ts +++ b/src/core/directives/swipe-navigation.ts @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { CoreConstants } from '@/core/constants'; import { AfterViewInit, Directive, ElementRef, Input, OnDestroy } from '@angular/core'; import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe-navigation-items-manager'; import { CoreSwipeNavigationTourComponent } from '@components/swipe-navigation-tour/swipe-navigation-tour'; @@ -42,6 +43,11 @@ export class CoreSwipeNavigationDirective implements AfterViewInit, OnDestroy { constructor(el: ElementRef) { this.element = el.nativeElement; + + if (CoreConstants.enableDevTools()) { + this.element['swipeNavigation'] = this; + this.element.classList.add('uses-swipe-navigation'); + } } get enabled(): boolean { diff --git a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts index af619378a..4fa595af8 100644 --- a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts +++ b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts @@ -213,7 +213,7 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { } const showDevOptionsOnConfig = await CoreConfig.get('showDevOptions', 0); - this.devOptionsForced = CoreConstants.BUILD.isDevelopment || CoreConstants.BUILD.isTesting; + this.devOptionsForced = CoreConstants.enableDevTools(); this.showDevOptions = this.devOptionsForced || showDevOptionsOnConfig == 1; const publicKey = this.deviceInfo.pushId ? diff --git a/src/testing/services/behat-runtime.ts b/src/testing/services/behat-runtime.ts index 4945a1246..bb0bd4740 100644 --- a/src/testing/services/behat-runtime.ts +++ b/src/testing/services/behat-runtime.ts @@ -404,17 +404,13 @@ export class TestingBehatRuntimeService { this.log('Action - pullToRefresh'); try { - // 'el' is protected, but there's no other way to trigger refresh programatically. - const ionRefresher = this.getAngularInstance<{ el: HTMLIonRefresherElement }>( - 'ion-refresher', - 'IonRefresher', - ); + const ionRefresher = this.getElement('ion-refresher'); if (!ionRefresher) { return 'ERROR: It\'s not possible to pull to refresh the current page.'; } - ionRefresher.el.dispatchEvent(new CustomEvent('ionRefresh')); + ionRefresher.dispatchEvent(new CustomEvent('ionRefresh')); return 'OK'; } catch (error) { @@ -521,20 +517,13 @@ export class TestingBehatRuntimeService { } /** - * Get an Angular component instance. + * Get element instance. * - * @param selector Element selector - * @param className Constructor class name + * @param selector Element selector. * @param referenceLocator The locator to the reference element to start looking for. If not specified, document body. - * @returns Component instance + * @returns Element instance. */ - getAngularInstance( - selector: string, - className: string, - referenceLocator?: TestingBehatElementLocator, - ): T | null { - this.log('Action - Get Angular instance ' + selector + ', ' + className, referenceLocator); - + private getElement(selector: string, referenceLocator?: TestingBehatElementLocator): T | null { let startingElement: HTMLElement | undefined = document.body; let queryPrefix = ''; @@ -552,15 +541,8 @@ export class TestingBehatRuntimeService { queryPrefix = '.ion-page:not(.ion-page-hidden) '; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const activeElement = Array.from(startingElement.querySelectorAll(`${queryPrefix}${selector}`)).pop() ?? - startingElement.closest(selector); - - if (!activeElement || !activeElement.__ngContext__) { - return null; - } - - return activeElement.__ngContext__.find(node => node?.constructor?.name === className); + return Array.from(startingElement.querySelectorAll(`${queryPrefix}${selector}`)).pop() as T + ?? startingElement.closest(selector) as T; } /** @@ -632,26 +614,26 @@ export class TestingBehatRuntimeService { if (locator) { // Locator specified, try to find swiper-container first. - const instance = this.getAngularInstance('swiper-container', 'Swiper', locator); - if (instance) { - direction === 'left' ? instance.slideNext() : instance.slidePrev(); + const swiperContainer = this.getElement<{ swiper: Swiper }>('swiper-container', locator); + + if (swiperContainer) { + direction === 'left' ? swiperContainer.swiper.slideNext() : swiperContainer.swiper.slidePrev(); return 'OK'; } } // No locator specified or swiper-container not found, search swipe navigation now. - const instance = this.getAngularInstance( - 'ion-content', - 'CoreSwipeNavigationDirective', + const ionContent = this.getElement<{ swipeNavigation: CoreSwipeNavigationDirective }>( + 'ion-content.uses-swipe-navigation', locator, ); - if (!instance) { + if (!ionContent) { return 'ERROR: Element to swipe not found.'; } - direction === 'left' ? instance.swipeLeft() : instance.swipeRight(); + direction === 'left' ? ionContent.swipeNavigation.swipeLeft() : ionContent.swipeNavigation.swipeRight(); return 'OK'; }