From 1ead9612a3df2d52774ff3f4431d0e5e7af43453 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 9 Nov 2021 16:06:13 +0100 Subject: [PATCH] MOBILE-3905 behat: Test swipe navigation --- tests/behat/app_behat_runtime.js | 20 +++++++- tests/behat/behat_app.php | 12 +++++ tests/behat/navigation_gestures.feature | 63 +++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tests/behat/navigation_gestures.feature diff --git a/tests/behat/app_behat_runtime.js b/tests/behat/app_behat_runtime.js index 0584a4eb3..83bd8b945 100644 --- a/tests/behat/app_behat_runtime.js +++ b/tests/behat/app_behat_runtime.js @@ -352,7 +352,7 @@ } } - return [...uniqueElements]; + return Array.from(uniqueElements); }; /** @@ -793,6 +793,23 @@ return 'OK'; }; + /** + * Get an Angular component instance. + * + * @param {string} selector Element selector + * @param {string} className Constructor class name + * @return {object} Component instance + */ + var behatGetComponentInstance = function(selector, className) { + const activeElement = Array.from(document.querySelectorAll(`.ion-page:not(.ion-page-hidden) ${selector}`)).pop(); + + if (!activeElement || !activeElement.__ngContext__) { + return null; + } + + return activeElement.__ngContext__.find(node => node?.constructor?.name === className); + }; + // Make some functions publicly available for Behat to call. window.behat = { pressStandard : behatPressStandard, @@ -802,5 +819,6 @@ press : behatPress, setField : behatSetField, getHeader : behatGetHeader, + getComponentInstance: behatGetComponentInstance, }; })(); diff --git a/tests/behat/behat_app.php b/tests/behat/behat_app.php index ddf4a9ea3..4e1221a9d 100644 --- a/tests/behat/behat_app.php +++ b/tests/behat/behat_app.php @@ -182,6 +182,18 @@ class behat_app extends behat_base { $this->wait_for_pending_js(); } + /** + * Trigger swipe gesture. + * + * @When /^I swipe to the (left|right) in the app$/ + * @param string $direction + */ + public function i_swipe_in_the_app(string $direction) { + $method = 'swipe' . ucwords($direction); + + $this->evaluate_script("behat.getComponentInstance('core-swipe-navigation', 'CoreSwipeNavigationComponent').$method()"); + } + /** * Check if elements are selected in the app. * diff --git a/tests/behat/navigation_gestures.feature b/tests/behat/navigation_gestures.feature new file mode 100644 index 000000000..e51465d27 --- /dev/null +++ b/tests/behat/navigation_gestures.feature @@ -0,0 +1,63 @@ +@app @javascript +Feature: It navigates using gestures. + + Background: + Given the following "users" exist: + | username | firstname | lastname | + | student1 | Student | First | + | teacher1 | Teacher | First | + | student2 | Student | Second | + | teacher2 | Teacher | Second | + | student3 | Student | Third | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "course enrolments" exist: + | user | course | role | + | student1 | C1 | student | + | teacher1 | C1 | teacher | + | student2 | C1 | student | + | teacher2 | C1 | teacher | + | student3 | C1 | student | + + Scenario: Swipe between participants + When I enter the app + And I log in as "student1" + And I press "Course 1" near "Course overview" in the app + And I press "Participants" in the app + And I press "Student First" in the app + And I swipe to the left in the app + Then I should find "Teacher First" in the app + + When I swipe to the left in the app + Then I should find "Student Second" in the app + + When I swipe to the right in the app + Then I should find "Teacher First" in the app + + When I swipe to the right in the app + Then I should find "Student First" in the app + + When I swipe to the right in the app + Then I should find "Student First" in the app + + Scenario: Swipe between filtered participants + When I enter the app + And I log in as "student1" + And I press "Course 1" near "Course overview" in the app + And I press "Participants" in the app + And I press "Search" in the app + And I set the field "Search" to "student" in the app + And I press "Search" "button" near "Clear search" in the app + And I press "Student First" in the app + And I swipe to the left in the app + Then I should find "Student Second" in the app + + When I swipe to the left in the app + Then I should find "Student Third" in the app + + When I swipe to the right in the app + Then I should find "Student Second" in the app + + When I swipe to the right in the app + Then I should find "Student First" in the app