MOBILE-3947 behat: Fix gestures
parent
639b4d9cfa
commit
130810ca3e
|
@ -12,6 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { CoreConstants } from '@/core/constants';
|
||||||
import { AfterViewInit, Directive, ElementRef, Input, OnDestroy } from '@angular/core';
|
import { AfterViewInit, Directive, ElementRef, Input, OnDestroy } from '@angular/core';
|
||||||
import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe-navigation-items-manager';
|
import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe-navigation-items-manager';
|
||||||
import { CoreSwipeNavigationTourComponent } from '@components/swipe-navigation-tour/swipe-navigation-tour';
|
import { CoreSwipeNavigationTourComponent } from '@components/swipe-navigation-tour/swipe-navigation-tour';
|
||||||
|
@ -42,6 +43,11 @@ export class CoreSwipeNavigationDirective implements AfterViewInit, OnDestroy {
|
||||||
|
|
||||||
constructor(el: ElementRef) {
|
constructor(el: ElementRef) {
|
||||||
this.element = el.nativeElement;
|
this.element = el.nativeElement;
|
||||||
|
|
||||||
|
if (CoreConstants.enableDevTools()) {
|
||||||
|
this.element['swipeNavigation'] = this;
|
||||||
|
this.element.classList.add('uses-swipe-navigation');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get enabled(): boolean {
|
get enabled(): boolean {
|
||||||
|
|
|
@ -213,7 +213,7 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
const showDevOptionsOnConfig = await CoreConfig.get('showDevOptions', 0);
|
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;
|
this.showDevOptions = this.devOptionsForced || showDevOptionsOnConfig == 1;
|
||||||
|
|
||||||
const publicKey = this.deviceInfo.pushId ?
|
const publicKey = this.deviceInfo.pushId ?
|
||||||
|
|
|
@ -404,17 +404,13 @@ export class TestingBehatRuntimeService {
|
||||||
this.log('Action - pullToRefresh');
|
this.log('Action - pullToRefresh');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 'el' is protected, but there's no other way to trigger refresh programatically.
|
const ionRefresher = this.getElement('ion-refresher');
|
||||||
const ionRefresher = this.getAngularInstance<{ el: HTMLIonRefresherElement }>(
|
|
||||||
'ion-refresher',
|
|
||||||
'IonRefresher',
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!ionRefresher) {
|
if (!ionRefresher) {
|
||||||
return 'ERROR: It\'s not possible to pull to refresh the current page.';
|
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';
|
return 'OK';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -521,20 +517,13 @@ export class TestingBehatRuntimeService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an Angular component instance.
|
* Get element instance.
|
||||||
*
|
*
|
||||||
* @param selector Element selector
|
* @param selector Element selector.
|
||||||
* @param className Constructor class name
|
|
||||||
* @param referenceLocator The locator to the reference element to start looking for. If not specified, document body.
|
* @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>(
|
private getElement<T = Element>(selector: string, referenceLocator?: TestingBehatElementLocator): T | null {
|
||||||
selector: string,
|
|
||||||
className: string,
|
|
||||||
referenceLocator?: TestingBehatElementLocator,
|
|
||||||
): T | null {
|
|
||||||
this.log('Action - Get Angular instance ' + selector + ', ' + className, referenceLocator);
|
|
||||||
|
|
||||||
let startingElement: HTMLElement | undefined = document.body;
|
let startingElement: HTMLElement | undefined = document.body;
|
||||||
let queryPrefix = '';
|
let queryPrefix = '';
|
||||||
|
|
||||||
|
@ -552,15 +541,8 @@ export class TestingBehatRuntimeService {
|
||||||
queryPrefix = '.ion-page:not(.ion-page-hidden) ';
|
queryPrefix = '.ion-page:not(.ion-page-hidden) ';
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
return Array.from(startingElement.querySelectorAll(`${queryPrefix}${selector}`)).pop() as T
|
||||||
const activeElement = Array.from(startingElement.querySelectorAll<any>(`${queryPrefix}${selector}`)).pop() ??
|
?? startingElement.closest(selector) as T;
|
||||||
startingElement.closest(selector);
|
|
||||||
|
|
||||||
if (!activeElement || !activeElement.__ngContext__) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return activeElement.__ngContext__.find(node => node?.constructor?.name === className);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -632,26 +614,26 @@ export class TestingBehatRuntimeService {
|
||||||
|
|
||||||
if (locator) {
|
if (locator) {
|
||||||
// Locator specified, try to find swiper-container first.
|
// Locator specified, try to find swiper-container first.
|
||||||
const instance = this.getAngularInstance<Swiper>('swiper-container', 'Swiper', locator);
|
const swiperContainer = this.getElement<{ swiper: Swiper }>('swiper-container', locator);
|
||||||
if (instance) {
|
|
||||||
direction === 'left' ? instance.slideNext() : instance.slidePrev();
|
if (swiperContainer) {
|
||||||
|
direction === 'left' ? swiperContainer.swiper.slideNext() : swiperContainer.swiper.slidePrev();
|
||||||
|
|
||||||
return 'OK';
|
return 'OK';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No locator specified or swiper-container not found, search swipe navigation now.
|
// No locator specified or swiper-container not found, search swipe navigation now.
|
||||||
const instance = this.getAngularInstance<CoreSwipeNavigationDirective>(
|
const ionContent = this.getElement<{ swipeNavigation: CoreSwipeNavigationDirective }>(
|
||||||
'ion-content',
|
'ion-content.uses-swipe-navigation',
|
||||||
'CoreSwipeNavigationDirective',
|
|
||||||
locator,
|
locator,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!instance) {
|
if (!ionContent) {
|
||||||
return 'ERROR: Element to swipe not found.';
|
return 'ERROR: Element to swipe not found.';
|
||||||
}
|
}
|
||||||
|
|
||||||
direction === 'left' ? instance.swipeLeft() : instance.swipeRight();
|
direction === 'left' ? ionContent.swipeNavigation.swipeLeft() : ionContent.swipeNavigation.swipeRight();
|
||||||
|
|
||||||
return 'OK';
|
return 'OK';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue