MOBILE-3947 behat: Fix gestures

main
Noel De Martin 2023-12-05 14:03:29 +01:00
parent 639b4d9cfa
commit 130810ca3e
3 changed files with 23 additions and 35 deletions

View File

@ -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 {

View File

@ -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 ?

View File

@ -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<T = unknown>(
selector: string,
className: string,
referenceLocator?: TestingBehatElementLocator,
): T | null {
this.log('Action - Get Angular instance ' + selector + ', ' + className, referenceLocator);
private getElement<T = Element>(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<any>(`${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>('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<CoreSwipeNavigationDirective>(
'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';
}