Skip to content

Commit b2691e8

Browse files
committed
MOBILE-4616 behat: Correct container visibility and narrow search
1 parent 7b61a83 commit b2691e8

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

src/core/features/dataprivacy/tests/behat/contact_privacy_officer.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ Feature: Contact the privacy officer
2424
Scenario: Contacting the privacy officer when not enabled
2525
When I entered the app as "student1"
2626
And I press the user menu button in the app
27-
Then I should not find ""Data privacy" in the app
27+
Then I should not find "Data privacy" in the app

src/core/features/dataprivacy/tests/behat/my_data_requests.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ Feature: Manage my own data requests
1919
And I set the field "Message" to "Hello DPO!" in the app
2020
And I press "Send" in the app
2121
Then I should find "Your request has been submitted to the privacy officer" in the app
22-
When I press "Cancel" near "Hello DPO!" in the app
22+
When I press "Cancel request" near "Hello DPO!" in the app
2323
And I press "Cancel request" "button" in the app
2424
Then I should find "Cancelled" near "Hello DPO!" in the app

src/core/services/modals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class CoreModalsService {
4848
// eslint-disable-next-line max-len
4949
// See https://github.com/ionic-team/ionic-framework/blob/a9b12a5aa4c150a1f8a80a826dda0df350bc0092/core/src/utils/overlays.ts#L39
5050

51-
const overlays = document.querySelectorAll<HTMLElement>(
51+
const overlays = document.body.querySelectorAll<HTMLElement>(
5252
'ion-action-sheet, ion-alert, ion-loading, ion-modal, ion-picker, ion-popover, ion-toast',
5353
);
5454

src/core/utils/fix-aria-hidden.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ export async function fixOverlayAriaHidden(
4545
]);
4646

4747
if (!overlays.find(overlay => overlay !== undefined)) {
48-
document.querySelector('ion-router-outlet')?.removeAttribute('aria-hidden');
48+
document.body.querySelector('ion-router-outlet')?.removeAttribute('aria-hidden');
4949
}
5050
}

src/testing/services/behat-dom.ts

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,25 @@ export class TestingBehatDomUtilsService {
4444
* @returns Whether the element is visible or not.
4545
*/
4646
isElementVisible(element: HTMLElement, container?: HTMLElement): boolean {
47-
if (element.getAttribute('aria-hidden') === 'true' || getComputedStyle(element).display === 'none') {
47+
if (element.getAttribute('aria-hidden') === 'true') {
48+
if (
49+
element === document.body.querySelector('ion-app > ion-router-outlet') &&
50+
(document.body.querySelector('ion-toast.hydrated:not(.overlay-hidden)') ||
51+
!document.body.querySelector(
52+
'ion-action-sheet.hydrated:not(.overlay-hidden), ion-alert.hydrated:not(.overlay-hidden)\
53+
ion-loading.hydrated:not(.overlay-hidden), ion-modal.hydrated:not(.overlay-hidden),\
54+
ion-picker.hydrated:not(.overlay-hidden), ion-popover.hydrated:not(.overlay-hidden)',
55+
))
56+
) {
57+
// Main ion-router-outlet is aria-hidden when a toast is open but the UI is not blocked...
58+
// It also may be hidden due to an error in Ionic. See fixOverlayAriaHidden function.
59+
return true;
60+
}
61+
62+
return false;
63+
}
64+
65+
if (getComputedStyle(element).display === 'none') {
4866
return false;
4967
}
5068

@@ -371,30 +389,34 @@ export class TestingBehatDomUtilsService {
371389
*/
372390
protected getCurrentTopContainerElements(containerName?: string): HTMLElement[] {
373391
let containers = Array.from(document.body.querySelectorAll<HTMLElement>([
374-
'ion-alert.hydrated',
375-
'ion-popover.hydrated',
376-
'ion-action-sheet.hydrated',
377-
'ion-modal.hydrated',
392+
'ion-alert.hydrated:not(.overlay-hidden)',
393+
'ion-popover.hydrated:not(.overlay-hidden)',
394+
'ion-action-sheet.hydrated:not(.overlay-hidden)',
395+
'ion-modal.hydrated:not(.overlay-hidden)',
378396
'core-user-tours-user-tour.is-active',
379-
'ion-toast.hydrated',
380-
'page-core-mainmenu',
381-
'ion-app',
397+
'ion-toast.hydrated:not(.overlay-hidden)',
398+
'page-core-mainmenu > ion-tabs:not(.tabshidden) > .mainmenu-tabs',
399+
'page-core-mainmenu > .core-network-message',
400+
'.ion-page:not(.ion-page-hidden)',
382401
].join(', ')));
402+
const ionApp = document.querySelector<HTMLElement>('ion-app') ?? undefined;
383403

384404
containers = containers
385405
.filter(container => {
386-
if (!this.isElementVisible(container)) {
387-
// Ignore containers not visible.
388-
return false;
389-
}
390406

391407
if (container.tagName === 'ION-ALERT') {
392408
// For some reason, in Behat sometimes alerts aren't removed from DOM, the close animation doesn't finish.
393409
// Filter alerts with pointer-events none since that style is set before the close animation starts.
394410
return container.style.pointerEvents !== 'none';
395411
}
396412

397-
return true;
413+
// Avoid searching in the whole app.
414+
if (container.tagName === 'ION-APP' || container.tagName === 'PAGE-CORE-MAINMENU') {
415+
return false;
416+
}
417+
418+
// Ignore not visible containers.
419+
return this.isElementVisible(container, ionApp);
398420
})
399421
// Sort them by z-index.
400422
.sort((a, b) => Number(getComputedStyle(b).zIndex) - Number(getComputedStyle(a).zIndex));

0 commit comments

Comments
 (0)