From b52681e2b260a0e09649569ca154fdecf1750bad Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 12 Mar 2024 12:39:27 +0100 Subject: [PATCH] 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);