From f0bb57692065a63042f013833880c0c665364c4b Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 7 Mar 2024 16:10:06 +0100 Subject: [PATCH 1/6] MOBILE-3947 ui: Display Cancel/Done buttons in datetime --- src/addons/calendar/pages/edit-event/edit-event.html | 5 +++-- .../fields/date/component/addon-mod-data-field-date.html | 2 +- .../component/addon-user-profile-field-datetime.html | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/addons/calendar/pages/edit-event/edit-event.html b/src/addons/calendar/pages/edit-event/edit-event.html index fde3faec04c..75f3667c6cf 100644 --- a/src/addons/calendar/pages/edit-event/edit-event.html +++ b/src/addons/calendar/pages/edit-event/edit-event.html @@ -32,7 +32,8 @@

{{ title | translate }}

- + {{'core.date' | translate}} @@ -155,7 +156,7 @@

{{ title | translate }}

+ presentation="date-time" [showDefaultButtons]="true"> {{'addon.calendar.durationuntil' | translate}} diff --git a/src/addons/mod/data/fields/date/component/addon-mod-data-field-date.html b/src/addons/mod/data/fields/date/component/addon-mod-data-field-date.html index 9e937812172..b5ac0ad6ee6 100644 --- a/src/addons/mod/data/fields/date/component/addon-mod-data-field-date.html +++ b/src/addons/mod/data/fields/date/component/addon-mod-data-field-date.html @@ -5,7 +5,7 @@ + [disabled]="searchMode && !searchFields['f_'+field.id+'_z']" presentation="date" [showDefaultButtons]="true" /> diff --git a/src/addons/userprofilefield/datetime/component/addon-user-profile-field-datetime.html b/src/addons/userprofilefield/datetime/component/addon-user-profile-field-datetime.html index 43341f2e662..563e186cf05 100644 --- a/src/addons/userprofilefield/datetime/component/addon-user-profile-field-datetime.html +++ b/src/addons/userprofilefield/datetime/component/addon-user-profile-field-datetime.html @@ -22,7 +22,8 @@ - + From abd1a32f63d033b84cd55d41a62dd2f948bddf83 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 8 Mar 2024 12:07:20 +0100 Subject: [PATCH 2/6] MOBILE-3947 datetime: Improve a11y of datetime-button --- src/addons/calendar/pages/edit-event/edit-event.html | 12 ++++++------ .../component/addon-user-profile-field-datetime.html | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/addons/calendar/pages/edit-event/edit-event.html b/src/addons/calendar/pages/edit-event/edit-event.html index 75f3667c6cf..a26e827e99e 100644 --- a/src/addons/calendar/pages/edit-event/edit-event.html +++ b/src/addons/calendar/pages/edit-event/edit-event.html @@ -27,9 +27,9 @@

{{ title | translate }}

-

{{ 'core.date' | translate }}

+
- + {{ title | translate }}
-

{{ 'addon.calendar.durationuntil' | translate }}

+

- + {{ title | translate }} -

{{ 'addon.calendar.durationminutes' | translate }}

+

- diff --git a/src/addons/userprofilefield/datetime/component/addon-user-profile-field-datetime.html b/src/addons/userprofilefield/datetime/component/addon-user-profile-field-datetime.html index 563e186cf05..08e8498a2ce 100644 --- a/src/addons/userprofilefield/datetime/component/addon-user-profile-field-datetime.html +++ b/src/addons/userprofilefield/datetime/component/addon-user-profile-field-datetime.html @@ -13,17 +13,17 @@ - + + - + - + From 69fca2f2698624cb8d3bfe057f5bb257df1b4aee Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 8 Mar 2024 12:09:14 +0100 Subject: [PATCH 3/6] MOBILE-3947 behat: Don't search elements in hidden containers --- src/testing/services/behat-dom.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/testing/services/behat-dom.ts b/src/testing/services/behat-dom.ts index 8d8fff76a17..eda22095302 100644 --- a/src/testing/services/behat-dom.ts +++ b/src/testing/services/behat-dom.ts @@ -376,6 +376,11 @@ export class TestingBehatDomUtilsService { containers = containers .filter(container => { + if (!this.isElementVisible(container)) { + // Ignore containers not visible. + return false; + } + if (container.tagName === 'ION-ALERT') { // For some reason, in Behat sometimes alerts aren't removed from DOM, the close animation doesn't finish. // Filter alerts with pointer-events none since that style is set before the close animation starts. From 864087c52a8ceb1639a950653af5f36ec0071058 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 8 Mar 2024 12:10:43 +0100 Subject: [PATCH 4/6] MOBILE-3947 behat: Fix datetime behat tests --- .../tests/behat/create_events.feature | 3 ++- .../datetime/component/datetime.ts | 2 +- src/testing/services/behat-dom.ts | 24 ++++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/addons/calendar/tests/behat/create_events.feature b/src/addons/calendar/tests/behat/create_events.feature index 88dd502055a..7f05af69b7f 100755 --- a/src/addons/calendar/tests/behat/create_events.feature +++ b/src/addons/calendar/tests/behat/create_events.feature @@ -26,8 +26,9 @@ Feature: Test creation of calendar events in app When I press "More" in the app And I press "Calendar" in the app And I press "New event" in the app + Then I should find "## now ##%b %e, %Y##" in the app # Flaky step, sometimes it fails due to minute change when checking. - Then the field "Date" matches value "## now ##%Y-%m-%dT%H:%M##" in the app + And I should find "## now ##%l:%M %p##" in the app And I should not be able to press "Save" in the app # Check that student can only create User events. diff --git a/src/addons/userprofilefield/datetime/component/datetime.ts b/src/addons/userprofilefield/datetime/component/datetime.ts index 17e28354a56..af78bef7ee2 100644 --- a/src/addons/userprofilefield/datetime/component/datetime.ts +++ b/src/addons/userprofilefield/datetime/component/datetime.ts @@ -86,7 +86,7 @@ export class AddonUserProfileFieldDatetimeComponent extends CoreUserProfileField */ protected createFormControl(field: AuthEmailSignupProfileField): FormControl { const formData = { - value: field.defaultdata != '0' ? field.defaultdata : undefined, + value: field.defaultdata && field.defaultdata !== '0' ? field.defaultdata : undefined, disabled: this.disabled, }; diff --git a/src/testing/services/behat-dom.ts b/src/testing/services/behat-dom.ts index eda22095302..27a97bed378 100644 --- a/src/testing/services/behat-dom.ts +++ b/src/testing/services/behat-dom.ts @@ -458,7 +458,16 @@ export class TestingBehatDomUtilsService { const inputId = label.getAttribute('for'); if (inputId) { - return document.getElementById(inputId) || undefined; + const element = document.getElementById(inputId) || undefined; + if (element?.tagName !== 'ION-DATETIME-BUTTON') { + return element; + } + + // Search the ion-datetime associated with the button. + const datetimeId = ( element).datetime; + const datetime = document.querySelector(`ion-datetime#${datetimeId}`); + + return datetime || undefined; } input = this.getShadowDOMHost(label) || undefined; @@ -482,6 +491,19 @@ export class TestingBehatDomUtilsService { locator: TestingBehatElementLocator, options: TestingBehatFindOptions = {}, ): HTMLElement | undefined { + // Remove extra spaces. + const treatedText = locator.text.trim().replace(/\s\s+/g, ' '); + if (treatedText !== locator.text) { + const element = this.findElementsBasedOnText({ + ...locator, + text: treatedText, + }, options)[0]; + + if (element) { + return element; + } + } + return this.findElementsBasedOnText(locator, options)[0]; } From 7287a9b298f262fb1b4f372e83fb2a7cc54af08b Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 11 Mar 2024 12:56:58 +0100 Subject: [PATCH 5/6] MOBILE-3947 datetime: Display placeholder if datetime value is undefined --- .../component/addon-user-profile-field-datetime.html | 7 ++++++- src/theme/theme.base.scss | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/addons/userprofilefield/datetime/component/addon-user-profile-field-datetime.html b/src/addons/userprofilefield/datetime/component/addon-user-profile-field-datetime.html index 08e8498a2ce..5c4aaaa7014 100644 --- a/src/addons/userprofilefield/datetime/component/addon-user-profile-field-datetime.html +++ b/src/addons/userprofilefield/datetime/component/addon-user-profile-field-datetime.html @@ -19,7 +19,12 @@ - + + + {{ 'core.choosedots' | translate }} + {{ 'core.choosedots' | translate }} + + Date: Tue, 12 Mar 2024 12:39:27 +0100 Subject: [PATCH 6/6] MOBILE-3947 behat: Add step to wait for Toast to dismiss --- local_moodleappbehat/tests/behat/behat_app.php | 9 +++++++++ .../reminders/tests/behat/course_reminders.feature | 12 ++++++------ src/testing/services/behat-runtime.ts | 12 +++++++++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/local_moodleappbehat/tests/behat/behat_app.php b/local_moodleappbehat/tests/behat/behat_app.php index 15e4b0eef44..631f938cf5f 100644 --- a/local_moodleappbehat/tests/behat/behat_app.php +++ b/local_moodleappbehat/tests/behat/behat_app.php @@ -1211,4 +1211,13 @@ public function i_change_viewport_size_in_the_app(int $width, int $height) { $this->resize_app_window($width, $height); } + /** + * Wait until Toast disappears. + * + * @When I wait toast to dismiss in the app + */ + public function i_wait_toast_to_dismiss_in_the_app() { + $this->runtime_js('waitToastDismiss()'); + } + } diff --git a/src/core/features/reminders/tests/behat/course_reminders.feature b/src/core/features/reminders/tests/behat/course_reminders.feature index b14edb89bb5..6c9aeee2de9 100644 --- a/src/core/features/reminders/tests/behat/course_reminders.feature +++ b/src/core/features/reminders/tests/behat/course_reminders.feature @@ -23,19 +23,19 @@ Feature: Set a new reminder on course # Default set When I press "Set a reminder for \"Course 1\" (Course end date)" in the app Then I should find "Reminder set for " in the app - And I should find "Reminder set for" in the app # Set from list - When I press "Set a reminder for \"Course 1\" (Course end date)" in the app + When I wait toast to dismiss in the app + And I press "Set a reminder for \"Course 1\" (Course end date)" in the app Then I should find "Set a reminder" in the app And "At the time of the event" should be selected in the app But "12 hours before" should not be selected in the app When I press "12 hours before" in the app Then I should find "Reminder set for " in the app - And I should find "Reminder set for" in the app # Custom set - When I press "Set a reminder for \"Course 1\" (Course end date)" in the app + When I wait toast to dismiss in the app + And I press "Set a reminder for \"Course 1\" (Course end date)" in the app Then I should find "Set a reminder" in the app And "At the time of the event" should not be selected in the app But "12 hours before" should be selected in the app @@ -46,10 +46,10 @@ Feature: Set a new reminder on course | Units | hours | And I press "Set reminder" in the app Then I should find "Reminder set for " in the app - And I should find "Reminder set for" in the app # Remove - When I press "Set a reminder for \"Course 1\" (Course end date)" in the app + When I wait toast to dismiss in the app + And I press "Set a reminder for \"Course 1\" (Course end date)" in the app Then "2 hours before" should be selected in the app When I press "Delete reminder" in the app Then I should find "Reminder deleted" in the app diff --git a/src/testing/services/behat-runtime.ts b/src/testing/services/behat-runtime.ts index 17078b0afb4..d4a39c5d578 100644 --- a/src/testing/services/behat-runtime.ts +++ b/src/testing/services/behat-runtime.ts @@ -18,7 +18,7 @@ import { CoreCustomURLSchemes, CoreCustomURLSchemesProvider } from '@services/ur import { ONBOARDING_DONE } from '@features/login/constants'; import { CoreConfig } from '@services/config'; import { EnvironmentConfig } from '@/types/config'; -import { LocalNotifications, makeSingleton, NgZone } from '@singletons'; +import { LocalNotifications, makeSingleton, NgZone, ToastController } from '@singletons'; import { CoreNetwork, CoreNetworkService } from '@services/network'; import { CorePushNotifications, CorePushNotificationsProvider } from '@features/pushnotifications/services/pushnotifications'; import { CoreCronDelegate, CoreCronDelegateService } from '@services/cron'; @@ -33,6 +33,7 @@ import { Swiper } from 'swiper'; import { LocalNotificationsMock } from '@features/emulator/services/local-notifications'; import { GetClosureArgs } from '@/core/utils/types'; import { CoreIframeComponent } from '@components/iframe/iframe'; +import { CoreUtils } from '@services/utils/utils'; /** * Behat runtime servive with public API. @@ -745,6 +746,15 @@ export class TestingBehatRuntimeService { return 'OK'; } + /** + * Wait for toast to be dismissed in the app. + * + * @returns Promise resolved when toast has been dismissed. + */ + async waitToastDismiss(): Promise { + await CoreUtils.ignoreErrors(ToastController.dismiss()); + } + } export const TestingBehatRuntime = makeSingleton(TestingBehatRuntimeService);