MOBILE-3936 reminders: Add reminders test
parent
12c19080f2
commit
6bdf812c81
|
@ -958,4 +958,46 @@ class behat_app extends behat_app_helper {
|
||||||
$this->getSession()->switchToWindow($windowNames[1]);
|
$this->getSession()->switchToWindow($windowNames[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a notification has been triggered and is present.
|
||||||
|
*
|
||||||
|
* @Then /^a notification with title (".+") is( not)? present in the app$/
|
||||||
|
* @param string $title Notification title
|
||||||
|
* @param bool $not Whether assert that the notification was not found
|
||||||
|
*/
|
||||||
|
public function notification_present_in_the_app(string $title, bool $not = false) {
|
||||||
|
$result = $this->runtime_js("notificationIsPresentWithText($title)");
|
||||||
|
|
||||||
|
if ($not && $result === 'YES') {
|
||||||
|
throw new ExpectationException("Notification is present", $this->getSession()->getDriver());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$not && $result === 'NO') {
|
||||||
|
throw new ExpectationException("Notification is not present", $this->getSession()->getDriver());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result !== 'YES' && $result !== 'NO') {
|
||||||
|
throw new DriverException('Error checking notification - ' . $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close a notification present in the app
|
||||||
|
*
|
||||||
|
* @Then /^I close a notification with title (".+") in the app$/
|
||||||
|
* @param string $title Notification title
|
||||||
|
*/
|
||||||
|
public function close_notification_app(string $title) {
|
||||||
|
$result = $this->runtime_js("closeNotification($title)");
|
||||||
|
|
||||||
|
if ($result !== 'OK') {
|
||||||
|
throw new DriverException('Error closing notification - ' . $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
@app @javascript @core_reminders
|
||||||
|
Feature: Set a new reminder on activity
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given the following "users" exist:
|
||||||
|
| username | firstname | lastname | email |
|
||||||
|
| student1 | Student | student | student1@example.com |
|
||||||
|
And the following "courses" exist:
|
||||||
|
| fullname | shortname | category |
|
||||||
|
| Course 1 | C1 | 0 |
|
||||||
|
And the following "course enrolments" exist:
|
||||||
|
| user | course | role |
|
||||||
|
| student1 | C1 | student |
|
||||||
|
And the following "activities" exist:
|
||||||
|
| activity | course | idnumber | name | allowsubmissionsfromdate | duedate |
|
||||||
|
| assign | C1 | assign01 | Assignment 01 | ## yesterday ## | ## now +70 minutes ## |
|
||||||
|
| assign | C1 | assign02 | Assignment 02 | ## yesterday ## | ## 1 January 2050 ## |
|
||||||
|
|
||||||
|
Scenario: Add, delete and update reminder on activity
|
||||||
|
Given I entered the assign activity "Assignment 01" on course "Course 1" as "student1" in the app
|
||||||
|
|
||||||
|
Then I should not find "Set a reminder for \"Assignment 01\" (Opened)" in the app
|
||||||
|
And I should find "Set a reminder for \"Assignment 01\" (Due)" in the app
|
||||||
|
And "Set a reminder for \"Assignment 01\" (Due)" should not be selected in the app
|
||||||
|
|
||||||
|
# Default set
|
||||||
|
When I press "Set a reminder for \"Assignment 01\" (Due)" in the app
|
||||||
|
Then I should find "Reminder set for " in the app
|
||||||
|
And "Set a reminder for \"Assignment 01\" (Due)" should be selected in the app
|
||||||
|
|
||||||
|
# Set from list
|
||||||
|
When I press "Set a reminder for \"Assignment 01\" (Due)" 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
|
||||||
|
And "1 hour before" should not be selected in the app
|
||||||
|
When I press "1 hour before" in the app
|
||||||
|
Then I should find "Reminder set for " in the app
|
||||||
|
And "Set a reminder for \"Assignment 01\" (Due)" should be selected in the app
|
||||||
|
|
||||||
|
# Custom set
|
||||||
|
When I press "Set a reminder for \"Assignment 01\" (Due)" 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
|
||||||
|
And "1 hour before" should be selected in the app
|
||||||
|
When I press "Custom..." in the app
|
||||||
|
Then I should find "Custom reminder" in the app
|
||||||
|
When I set the following fields to these values in the app:
|
||||||
|
| Value | 4 |
|
||||||
|
| Units | minutes |
|
||||||
|
And I press "Set reminder" in the app
|
||||||
|
Then I should find "Reminder set for " in the app
|
||||||
|
And "Set a reminder for \"Assignment 01\" (Due)" should be selected in the app
|
||||||
|
|
||||||
|
# Remove
|
||||||
|
When I press "Set a reminder for \"Assignment 01\" (Due)" in the app
|
||||||
|
Then "4 minutes before" should be selected in the app
|
||||||
|
When I press "Delete reminder" in the app
|
||||||
|
Then I should find "Reminder deleted" in the app
|
||||||
|
And "Set a reminder for \"Assignment 01\" (Due)" should not be selected in the app
|
||||||
|
|
||||||
|
# Set and check reminder
|
||||||
|
When I press "Set a reminder for \"Assignment 01\" (Due)" in the app
|
||||||
|
Then I should find "Reminder set for " in the app
|
||||||
|
When I press "Set a reminder for \"Assignment 01\" (Due)" in the app
|
||||||
|
And I press "Custom..." in the app
|
||||||
|
Then I should find "Custom reminder" in the app
|
||||||
|
When I set the following fields to these values in the app:
|
||||||
|
| Value | 69 |
|
||||||
|
| Units | minutes |
|
||||||
|
And I press "Set reminder" in the app
|
||||||
|
Then I should find "Reminder set for " in the app
|
||||||
|
When I wait "50" seconds
|
||||||
|
Then a notification with title "Due: Assignment 01" is present in the app
|
||||||
|
And I close a notification with title "Due: Assignment 01" in the app
|
||||||
|
|
||||||
|
# Set and check reminder is cancelled
|
||||||
|
When I press "Set a reminder for \"Assignment 01\" (Due)" in the app
|
||||||
|
And I press "Custom..." in the app
|
||||||
|
Then I should find "Custom reminder" in the app
|
||||||
|
When I set the following fields to these values in the app:
|
||||||
|
| Value | 68 |
|
||||||
|
| Units | minutes |
|
||||||
|
And I press "Set reminder" in the app
|
||||||
|
Then I should find "Reminder set for " in the app
|
||||||
|
When I press "Set a reminder for \"Assignment 01\" (Due)" in the app
|
||||||
|
Then I should find "Reminder set for " in the app
|
||||||
|
When I press "Delete reminder" in the app
|
||||||
|
Then I should find "Reminder deleted" in the app
|
||||||
|
When I wait "50" seconds
|
||||||
|
Then a notification with title "Due: Assignment 01" is not present in the app
|
||||||
|
|
||||||
|
Scenario: Check toast is correct
|
||||||
|
Given I entered the assign activity "Assignment 02" on course "Course 1" as "student1" in the app
|
||||||
|
|
||||||
|
When I press "Set a reminder for \"Assignment 02\" (Due)" in the app
|
||||||
|
Then I should find "Reminder set for " in the app
|
||||||
|
|
||||||
|
When I press "Set a reminder for \"Assignment 02\" (Due)" in the app
|
||||||
|
And I press "1 day before" in the app
|
||||||
|
Then I should find "Reminder set for Friday, 31 December 2049, 12:00 AM" in the app
|
|
@ -0,0 +1,56 @@
|
||||||
|
@app @javascript @core_reminders
|
||||||
|
Feature: Set a new reminder on course
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given the following "users" exist:
|
||||||
|
| username | firstname | lastname | email |
|
||||||
|
| student1 | Student | student | student1@example.com |
|
||||||
|
And the following "courses" exist:
|
||||||
|
| fullname | shortname | category | startdate | enddate |
|
||||||
|
| Course 1 | C1 | 0 | ## yesterday ## | ## now +24 hours ## |
|
||||||
|
And the following "course enrolments" exist:
|
||||||
|
| user | course | role |
|
||||||
|
| student1 | C1 | student |
|
||||||
|
|
||||||
|
Scenario: Add, delete and update reminder on course
|
||||||
|
Given I entered the course "Course 1" as "student1" in the app
|
||||||
|
And I press "Course summary" in the app
|
||||||
|
|
||||||
|
Then I should not find "Set a reminder for \"Course 1\" (Course start date)" in the app
|
||||||
|
And I should find "Set a reminder for \"Course 1\" (Course end date)" in the app
|
||||||
|
And "Set a reminder for \"Course 1\" (Course end date)" should not be selected in the app
|
||||||
|
|
||||||
|
# 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 "Set a reminder for \"Course 1\" (Course end date)" should be selected in the app
|
||||||
|
|
||||||
|
# Set from list
|
||||||
|
When 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
|
||||||
|
And "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 "Set a reminder for \"Course 1\" (Course end date)" should be selected in the app
|
||||||
|
|
||||||
|
# Custom set
|
||||||
|
When 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
|
||||||
|
And "12 hours before" should be selected in the app
|
||||||
|
When I press "Custom..." in the app
|
||||||
|
Then I should find "Custom reminder" in the app
|
||||||
|
When I set the following fields to these values in the app:
|
||||||
|
| Value | 2 |
|
||||||
|
| Units | hours |
|
||||||
|
And I press "Set reminder" in the app
|
||||||
|
Then I should find "Reminder set for " in the app
|
||||||
|
And "Set a reminder for \"Course 1\" (Course end date)" should be selected in the app
|
||||||
|
|
||||||
|
# Remove
|
||||||
|
When 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
|
||||||
|
And "Set a reminder for \"Course 1\" (Course end date)" should not be selected in the app
|
|
@ -18,7 +18,7 @@ import { CoreCustomURLSchemes, CoreCustomURLSchemesProvider } from '@services/ur
|
||||||
import { CoreLoginHelperProvider } from '@features/login/services/login-helper';
|
import { CoreLoginHelperProvider } from '@features/login/services/login-helper';
|
||||||
import { CoreConfig } from '@services/config';
|
import { CoreConfig } from '@services/config';
|
||||||
import { EnvironmentConfig } from '@/types/config';
|
import { EnvironmentConfig } from '@/types/config';
|
||||||
import { makeSingleton, NgZone } from '@singletons';
|
import { LocalNotifications, makeSingleton, NgZone } from '@singletons';
|
||||||
import { CoreNetwork, CoreNetworkService } from '@services/network';
|
import { CoreNetwork, CoreNetworkService } from '@services/network';
|
||||||
import { CorePushNotifications, CorePushNotificationsProvider } from '@features/pushnotifications/services/pushnotifications';
|
import { CorePushNotifications, CorePushNotificationsProvider } from '@features/pushnotifications/services/pushnotifications';
|
||||||
import { CoreCronDelegate, CoreCronDelegateService } from '@services/cron';
|
import { CoreCronDelegate, CoreCronDelegateService } from '@services/cron';
|
||||||
|
@ -491,6 +491,49 @@ export class TestingBehatRuntimeService {
|
||||||
console.log('BEHAT: ' + nowFormatted, ...args); // eslint-disable-line no-console
|
console.log('BEHAT: ' + nowFormatted, ...args); // eslint-disable-line no-console
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check a notification is present.
|
||||||
|
*
|
||||||
|
* @param title Title of the notification
|
||||||
|
* @return YES or NO: depending on the result.
|
||||||
|
*/
|
||||||
|
async notificationIsPresentWithText(title: string): Promise<string> {
|
||||||
|
const notifications = await LocalNotifications.getAllTriggered();
|
||||||
|
|
||||||
|
const notification = notifications.find((notification) => notification.title?.includes(title));
|
||||||
|
|
||||||
|
if (!notification) {
|
||||||
|
return 'NO';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!notification.id) {
|
||||||
|
// Cannot check but has been triggered.
|
||||||
|
return 'YES';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (await LocalNotifications.isPresent(notification.id)) ? 'YES' : 'NO';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close notification.
|
||||||
|
*
|
||||||
|
* @param title Title of the notification
|
||||||
|
* @return OK or ERROR
|
||||||
|
*/
|
||||||
|
async closeNotification(title: string): Promise<string> {
|
||||||
|
const notifications = await LocalNotifications.getAllTriggered();
|
||||||
|
|
||||||
|
const notification = notifications.find((notification) => notification.title?.includes(title));
|
||||||
|
|
||||||
|
if (!notification || !notification.id) {
|
||||||
|
return `ERROR: Notification with title ${title} cannot be closed`;
|
||||||
|
}
|
||||||
|
|
||||||
|
await LocalNotifications.clear(notification.id);
|
||||||
|
|
||||||
|
return 'OK';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TestingBehatRuntime = makeSingleton(TestingBehatRuntimeService);
|
export const TestingBehatRuntime = makeSingleton(TestingBehatRuntimeService);
|
||||||
|
|
Loading…
Reference in New Issue