Skip to content

Commit

Permalink
MOBILE-3947 behat: Add step to wait for Toast to dismiss
Browse files Browse the repository at this point in the history
  • Loading branch information
dpalou committed Mar 12, 2024
1 parent 7287a9b commit b52681e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
9 changes: 9 additions & 0 deletions local_moodleappbehat/tests/behat/behat_app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()');
}

}
12 changes: 6 additions & 6 deletions src/core/features/reminders/tests/behat/course_reminders.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/testing/services/behat-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
Expand Down Expand Up @@ -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<void> {
await CoreUtils.ignoreErrors(ToastController.dismiss());
}

}

export const TestingBehatRuntime = makeSingleton(TestingBehatRuntimeService);
Expand Down

0 comments on commit b52681e

Please sign in to comment.