diff --git a/src/addons/calendar/tests/behat/create_events.feature b/src/addons/calendar/tests/behat/create_events.feature index 88dd50205..7f05af69b 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 17e28354a..af78bef7e 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 eda220953..27a97bed3 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]; }