MOBILE-4021 notifications: Create notification acceptance tests

main
Alfonso Salces 2022-05-30 13:24:36 +02:00
parent ed3d8e333b
commit e430a4266a
3 changed files with 140 additions and 14 deletions

View File

@ -420,30 +420,42 @@ class behat_app extends behat_app_helper {
/**
* Receives push notifications.
*
* @When /^I receive a push notification in the app for:$/
* @When /^I click a push notification in the app for:$/
* @param TableNode $data Table data
*/
public function i_receive_a_push_notification(TableNode $data) {
public function i_click_a_push_notification(TableNode $data) {
global $DB, $CFG;
$data = (object) $data->getColumnsHash()[0];
$module = $DB->get_record('course_modules', ['idnumber' => $data->module]);
$discussion = $DB->get_record('forum_discussions', ['name' => $data->discussion]);
if (isset($data->module, $data->discussion)) {
$module = $DB->get_record('course_modules', ['idnumber' => $data->module]);
$discussion = $DB->get_record('forum_discussions', ['name' => $data->discussion]);
$data->name = 'posts';
$data->component = 'mod_forum';
}
$notification = json_encode([
'site' => md5($CFG->behat_wwwroot . $data->username),
'courseid' => $discussion->course,
'moodlecomponent' => 'mod_forum',
'name' => 'posts',
'subject' => $data->subject ?? null,
'userfrom' => $data->userfrom ?? null,
'userto' => $data->username ?? null,
'message' => $data->message ?? '',
'title' => $data->title ?? '',
'image' => $data->image ?? null,
'courseid' => $discussion->course ?? null,
'moodlecomponent' => $data->component ?? null,
'name' => $data->name ?? null,
'contexturl' => '',
'notif' => 1,
'customdata' => [
'discussionid' => $discussion->id,
'cmid' => $module->id,
'instance' => $discussion->forum,
],
'customdata' => isset($discussion->id, $module->id, $discussion->forum)
? ['discussionid' => $discussion->id, 'cmid' => $module->id, 'instance' => $discussion->forum]
: null,
'additionalData' => isset($data->subject) || isset($data->userfrom)
? ['foreground' => true, 'notId' => 23, 'notif' => 1] : null,
]);
$this->zone_js("pushNotifications.notificationClicked($notification)", true);
$this->evaluate_script("pushNotifications.notificationClicked($notification)", true);
$this->wait_for_pending_js();
}

View File

@ -0,0 +1,114 @@
@app @javascript
Feature: Notifications
Background:
Given the following "users" exist:
| username | firstname | lastname |
| student1 | First | Student |
| student2 | Second | Student |
And the following "notifications" exist:
| subject | userfrom | userto | timecreated | timeread |
| Test 01 | student2 | student1 | 1649766600 | null |
| Test 02 | student2 | student1 | 1649766601 | null |
| Test 03 | student2 | student1 | 1649766602 | 1649766602 |
| Test 04 | student2 | student1 | 1649766603 | 1649766602 |
| Test 05 | student2 | student1 | 1649766604 | null |
| Test 06 | student2 | student1 | 1649766605 | null |
| Test 07 | student2 | student1 | 1649766606 | 1649766602 |
| Test 08 | student2 | student1 | 1649766607 | 1649766602 |
| Test 09 | student2 | student1 | 1649766608 | null |
| Test 10 | student2 | student1 | 1649766609 | 1649766602 |
| Test 11 | student2 | student1 | 1649766610 | 1649766602 |
| Test 12 | student2 | student1 | 1649766611 | 1649766602 |
| Test 13 | student2 | student1 | 1649766612 | 1649766602 |
| Test 14 | student2 | student1 | 1649766613 | 1649766602 |
| Test 15 | student2 | student1 | 1649766614 | 1649766602 |
| Test 16 | student2 | student1 | 1649766615 | 1649766602 |
| Test 17 | student2 | student1 | 1649766616 | 1649766602 |
| Test 18 | student2 | student1 | 1649766617 | 1649766602 |
| Test 19 | student2 | student1 | 1649766618 | 1649766602 |
| Test 20 | student2 | student1 | 1649766619 | 1649766602 |
| Test 21 | student2 | student1 | 1649766620 | null |
| Test 22 | student2 | student1 | 1649766621 | 1649766602 |
| Test 23 | student2 | student1 | 1649766622 | 1649766602 |
| Test 24 | student2 | student1 | 1649766623 | 1649766602 |
| Test 25 | student2 | student1 | 1649766624 | 1649766602 |
| Test 26 | student2 | student1 | 1649766625 | null |
| Test 27 | student2 | student1 | 1649766626 | 1649766602 |
| Test 28 | student2 | student1 | 1649766627 | 1649766602 |
| Test 29 | student2 | student1 | 1649766628 | 1649766602 |
| Test 30 | student2 | student1 | 1649766629 | null |
Scenario: Mobile navigation
Given I enter the app
And I log in as "student1"
And I press "Notifications" in the app
Then I should find "Test 30" in the app
But I should not find "Test 10" in the app
When I load more items in the app
Then I should find "Test 10" in the app
And I should find "Test 01" in the app
# Receive a push notification
And the following "notifications" exist:
| subject | userfrom | userto | timecreated | timeread |
| Test 31 | student2 | student1 | 1649766631 | null |
When I click a push notification in the app for:
| username | message | title | subject | userfrom |
| student1 | Test push | Test 31 | Push 01 | student2 |
Then I should find "Push 01" in the app
# Open notification detail
When I press the back button in the app
And I press "Test 30" in the app
Then I should find "Test 30 description" in the app
# Go back and open other notification
When I press the back button in the app
Then I should find "Test 10" in the app
When I press "Test 10" in the app
Then I should find "Test 10 description" in the app
# Swipe to next notification
When I swipe to the right in the app
Then I should find "Test 11 description" in the app
But I should not find "Test 10 description" in the app
# Swipe to previous notification
When I swipe to the left in the app
Then I should find "Test 10 description" in the app
But I should not find "Test 09 description" in the app
Scenario: Tablet navigation
Given I enter the app
And I change viewport size to "1200x640"
And I log in as "student1"
And I press "Notifications" in the app
Then I should find "Test 30" in the app
But I should not find "Test 10" in the app
# Load more notifications
When I load more items in the app
Then I should find "Test 10" in the app
And I should find "Test 01" in the app
And I should find "Test 30 description" inside the split-view content in the app
And "Test 30" near "Test 29" should be selected in the app
# Open loaded items after load more notifications
When I press "Test 10" in the app
Then I should find "Test 10 description" inside the split-view content in the app
And "Test 10" near "Test 11" should be selected in the app
# Mark as read notification
When I press "Test 01" in the app
Then I should not find "Unread notification: Test 01" in the app
But I should find "Test 01" in the app
And I should find "Unread notification: Test 26" in the app
# Mark all notifications as read
When I press "Mark all as read" in the app
Then I should not find "Unread notification" in the app
# Pull to refresh
When I pull to refresh in the app
Then I should not find "Unread notification" in the app

View File

@ -30,7 +30,7 @@ Feature: It navigates properly using deep links.
And I set the field "Your site" to "$WWWROOT" in the app
And I press "Connect to your site" in the app
And I log in as "student1"
And I receive a push notification in the app for:
And I click a push notification in the app for:
| username | module | discussion |
| student2 | forum | Forum topic |
And I wait the app to restart