From 350d7cd3058030b2b36e96da9a25d382025be6f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 9 Jun 2022 14:54:09 +0200 Subject: [PATCH] MOBILE-4061 data: Import and fix legacy tests from moodlemobileapp --- .../mod/data/tests/behat/entries.feature | 177 ++++++++++++++++++ src/addons/mod/data/tests/behat/sync.feature | 124 ++++++++++++ src/testing/services/behat-dom.ts | 4 +- 3 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 src/addons/mod/data/tests/behat/entries.feature create mode 100644 src/addons/mod/data/tests/behat/sync.feature diff --git a/src/addons/mod/data/tests/behat/entries.feature b/src/addons/mod/data/tests/behat/entries.feature new file mode 100644 index 000000000..50ad2e4f2 --- /dev/null +++ b/src/addons/mod/data/tests/behat/entries.feature @@ -0,0 +1,177 @@ +@mod @mod_data @app @javascript +Feature: Users can manage entries in database activities + In order to populate databases + As a user + I need to add and manage entries to databases + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + And the following "activities" exist: + | activity | name | intro | course | idnumber | + | data | Web links | Useful links | C1 | data1 | + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I add a "Text input" field to "Web links" database and I fill the form with: + | Field name | URL | + | Field description | URL link | + And I add a "Text input" field to "Web links" database and I fill the form with: + | Field name | Description | + | Field description | Link description | + And I log out + + Scenario: Create entry + Given I entered the data activity "Web links" on course "Course 1" as "student1" in the app + And I should find "No entries in database" in the app + When I press "Add entries" in the app + And I set the field "URL" to "https://moodle.org/" in the app + And I set the field "Description" to "Moodle community site" in the app + And I press "Save" near "Web links" in the app + Then I should find "https://moodle.org/" in the app + And I should find "Moodle community site" in the app + + Scenario: Browse entry + Given I entered the data activity "Web links" on course "Course 1" as "student1" in the app + And I press "Add entries" in the app + And I set the field "URL" to "https://moodle.org/" in the app + And I set the field "Description" to "Moodle community site" in the app + And I press "Save" near "Web links" in the app + And I entered the data activity "Web links" on course "Course 1" as "student2" in the app + And I press "Add entries" in the app + And I set the field "URL" to "https://moodlecloud.com/" in the app + And I set the field "Description" to "Moodle Cloud" in the app + And I press "Save" near "Web links" in the app + And I press "More" near "Moodle community site" in the app + Then I should find "Moodle community site" in the app + And I should not find "Next" in the app + And I should find "Previous" in the app + And I press "Previous" in the app + And I should find "Moodle Cloud" in the app + And I should find "Next" in the app + And I should not find "Previous" in the app + And I press "Next" in the app + And I should find "Moodle community site" in the app + And I should not find "Moodle Cloud" in the app + And I press the back button in the app + And I should find "Moodle community site" in the app + And I should find "Moodle Cloud" in the app + + Scenario: Students can not edit or delete other user's entries from list and single view in the app + Given I entered the data activity "Web links" on course "Course 1" as "student1" in the app + And I press "Add entries" in the app + And I set the field "URL" to "https://moodle.org/" in the app + And I set the field "Description" to "Moodle community site" in the app + And I press "Save" near "Web links" in the app + And I entered the course "Course 1" as "student2" in the app + When I press "Web links" near "General" in the app + Then "Edit" "link" should not exist + And "Delete" "link" should not exist + And I press "More" in the app + And "Edit" "link" should not exist + And "Delete" "link" should not exist + + Scenario: Delete entry (student) & Update entry (student) + Given I entered the data activity "Web links" on course "Course 1" as "student1" in the app + And I press "Add entries" in the app + And I set the field "URL" to "https://moodle.org/" in the app + And I set the field "Description" to "Moodle community site" in the app + And I press "Save" near "Web links" in the app + When I press "Edit" in the app + And I set the field "URL" to "https://moodlecloud.com/" in the app + And I set the field "Description" to "Moodle Cloud" in the app + And I press "Save" near "Web links" in the app + Then I should not find "https://moodle.org/" in the app + And I should not find "Moodle community site" in the app + And I should find "https://moodlecloud.com/" in the app + And I should find "Moodle Cloud" in the app + And I press "Delete" in the app + And I should find "Are you sure you want to delete this entry?" in the app + And I press "Cancel" in the app + And I should find "Moodle Cloud" in the app + And I press "Delete" in the app + And I should find "Are you sure you want to delete this entry?" in the app + And I press "Delete" in the app + And I should not find "Moodle Cloud" in the app + And I press "Add entries" in the app + And I set the field "URL" to "https://moodle.org/" in the app + And I set the field "Description" to "Moodle community site" in the app + And I press "Save" near "Web links" in the app + And I press "More" in the app + And I press "Edit" in the app + And I set the field "URL" to "https://moodlecloud.com/" in the app + And I set the field "Description" to "Moodle Cloud" in the app + And I press "Save" near "Web links" in the app + And I should not find "https://moodle.org/" in the app + And I should not find "Moodle community site" in the app + And I should find "https://moodlecloud.com/" in the app + And I should find "Moodle Cloud" in the app + And I press "Delete" in the app + And I should find "Are you sure you want to delete this entry?" in the app + And I press "Cancel" in the app + And I should find "Moodle Cloud" in the app + And I press "Delete" in the app + And I should find "Are you sure you want to delete this entry?" in the app + And I press "Delete" in the app + And I should not find "Moodle Cloud" in the app + And I should find "No entries in database" in the app + + Scenario: Delete entry (teacher) & Update entry (teacher) + Given I entered the data activity "Web links" on course "Course 1" as "student1" in the app + And I press "Add entries" in the app + And I set the field "URL" to "https://moodle.org/" in the app + And I set the field "Description" to "Moodle community site" in the app + And I press "Save" near "Web links" in the app + And I press "Add entries" in the app + And I set the field "URL" to "https://telegram.org/" in the app + And I set the field "Description" to "Telegram" in the app + And I press "Save" near "Web links" in the app + And I entered the course "Course 1" as "teacher1" in the app + When I press "Web links" near "General" in the app + Then I should find "https://moodle.org/" in the app + And I should find "Moodle community site" in the app + And I press "Edit" near "Moodle community site" in the app + And I set the field "URL" to "https://moodlecloud.com/" in the app + And I set the field "Description" to "Moodle Cloud" in the app + And I press "Save" near "Web links" in the app + And I should not find "https://moodle.org/" in the app + And I should not find "Moodle community site" in the app + And I should find "https://moodlecloud.com/" in the app + And I should find "Moodle Cloud" in the app + And I press "Delete" near "Moodle Cloud" in the app + And I should find "Are you sure you want to delete this entry?" in the app + And I press "Cancel" in the app + And I should find "Moodle Cloud" in the app + And I press "Delete" near "Moodle Cloud" in the app + And I should find "Are you sure you want to delete this entry?" in the app + And I press "Delete" in the app + And I should not find "Moodle Cloud" in the app + And I press "More" in the app + And I should find "https://telegram.org/" in the app + And I should find "Telegram" in the app + And I press "Edit" in the app + And I set the field "URL" to "https://moodlecloud.com/" in the app + And I set the field "Description" to "Moodle Cloud" in the app + And I press "Save" near "Web links" in the app + And I should not find "https://telegram.org/" in the app + And I should not find "Telegram" in the app + And I should find "https://moodlecloud.com/" in the app + And I should find "Moodle Cloud" in the app + And I press "Delete" in the app + And I should find "Are you sure you want to delete this entry?" in the app + And I press "Cancel" in the app + And I should find "Moodle Cloud" in the app + And I press "Delete" in the app + And I should find "Are you sure you want to delete this entry?" in the app + And I press "Delete" in the app + And I should not find "Moodle Cloud" in the app diff --git a/src/addons/mod/data/tests/behat/sync.feature b/src/addons/mod/data/tests/behat/sync.feature new file mode 100644 index 000000000..de23b4f87 --- /dev/null +++ b/src/addons/mod/data/tests/behat/sync.feature @@ -0,0 +1,124 @@ +@mod @mod_data @app @javascript +Feature: Users can store entries in database activities when offline and sync when online + In order to populate databases while offline + As a user + I need to add and manage entries to databases and sync then when online + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + And the following "activities" exist: + | activity | name | intro | course | idnumber | + | data | Web links | Useful links | C1 | data1 | + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I add a "Text input" field to "Web links" database and I fill the form with: + | Field name | URL | + | Field description | URL link | + And I add a "Text input" field to "Web links" database and I fill the form with: + | Field name | Description | + | Field description | Link description | + And I log out + + Scenario: Create entry (offline) + Given I entered the data activity "Web links" on course "Course 1" as "student1" in the app + And I switch offline mode to "true" + And I should find "No entries in database" in the app + When I press "Add entries" in the app + And I set the field "URL" to "https://moodle.org/" in the app + And I set the field "Description" to "Moodle community site" in the app + And I press "Save" near "Web links" in the app + Then I should find "https://moodle.org/" in the app + And I should find "Moodle community site" in the app + And I should find "This Database has offline data to be synchronised" in the app + And I press the back button in the app + And I switch offline mode to "false" + And I press "Web links" near "General" in the app + And I should find "https://moodle.org/" in the app + And I should find "Moodle community site" in the app + And I should not find "This Database has offline data to be synchronised" in the app + + Scenario: Update entry (offline) & Delete entry (offline) + Given I entered the data activity "Web links" on course "Course 1" as "student1" in the app + And I should find "No entries in database" in the app + And I press "Add entries" in the app + And I set the field "URL" to "https://moodle.org/" in the app + And I set the field "Description" to "Moodle community site" in the app + And I press "Save" near "Web links" in the app + And I should find "https://moodle.org/" in the app + And I should find "Moodle community site" in the app + And I press "Information" in the app + And I press "Download" in the app + And I wait until the page is ready + And I switch offline mode to "true" + When I press "Edit" in the app + And I set the field "URL" to "https://moodlecloud.com/" in the app + And I set the field "Description" to "Moodle Cloud" in the app + And I press "Save" near "Web links" in the app + Then I should not find "https://moodle.org/" in the app + And I should not find "Moodle community site" in the app + And I should find "https://moodlecloud.com/" in the app + And I should find "Moodle Cloud" in the app + And I should find "This Database has offline data to be synchronised" in the app + And I press the back button in the app + And I switch offline mode to "false" + And I press "Web links" near "General" in the app + And I should not find "https://moodle.org/" in the app + And I should not find "Moodle community site" in the app + And I should find "https://moodlecloud.com/" in the app + And I should find "Moodle Cloud" in the app + And I should not find "This Database has offline data to be synchronised" in the app + And I press "Information" in the app + And I press "Refresh" in the app + And I wait until the page is ready + And I switch offline mode to "true" + And I press "Delete" in the app + And I should find "Are you sure you want to delete this entry?" in the app + And I press "Delete" in the app + And I should find "https://moodlecloud.com/" in the app + And I should find "Moodle Cloud" in the app + And I should find "This Database has offline data to be synchronised" in the app + And I press the back button in the app + And I switch offline mode to "false" + And I press "Web links" near "General" in the app + And I should not find "https://moodlecloud.com/" in the app + And I should not find "Moodle Cloud" in the app + And I should not find "This Database has offline data to be synchronised" in the app + + Scenario: Students can undo deleting entries to a database in the app while offline + Given I entered the data activity "Web links" on course "Course 1" as "student1" in the app + And I should find "No entries in database" in the app + And I press "Add entries" in the app + And I set the field "URL" to "https://moodle.org/" in the app + And I set the field "Description" to "Moodle community site" in the app + And I press "Save" near "Web links" in the app + And I should find "https://moodle.org/" in the app + And I should find "Moodle community site" in the app + And I press "Information" in the app + And I press "Download" in the app + And I wait until the page is ready + When I switch offline mode to "true" + And I press "Delete" in the app + And I should find "Are you sure you want to delete this entry?" in the app + And I press "Delete" in the app + And I should find "https://moodle.org/" in the app + And I should find "Moodle community site" in the app + And I should find "This Database has offline data to be synchronised" in the app + And I press "Restore" in the app + And I press the back button in the app + And I switch offline mode to "false" + And I press "Web links" near "General" in the app + Then I should find "https://moodle.org/" in the app + And I should find "Moodle community site" in the app + And I should not find "This Database has offline data to be synchronised" in the app diff --git a/src/testing/services/behat-dom.ts b/src/testing/services/behat-dom.ts index c04775fbd..a19ce0b42 100644 --- a/src/testing/services/behat-dom.ts +++ b/src/testing/services/behat-dom.ts @@ -104,7 +104,9 @@ export class TestsBehatDomUtils { } if (node instanceof HTMLElement && - (node.getAttribute('aria-hidden') === 'true' || getComputedStyle(node).display === 'none')) { + (node.getAttribute('aria-hidden') === 'true' || + node.getAttribute('aria-disabled') === 'true' || + getComputedStyle(node).display === 'none')) { return NodeFilter.FILTER_REJECT; }