Commit dda64b6f authored by Damyon Wiese's avatar Damyon Wiese
Browse files

MDL-59548 behat: Helpers for autocomplete

Improve the helpers for autocomplete so that:
a) the set field for an auto complete will automatically close the suggestions list.
b) add a new helper to open the suggestions list
c) move the helper for clicking on an element in the suggestions list from tool_lp to core.
parent 16a68a2f
......@@ -63,16 +63,4 @@ class behat_tool_lp extends behat_base {
$this->execute('behat_general::i_click_on', [$xpathtarget, 'xpath_element']);
}
/**
* Select item from autocomplete list.
*
* @Given /^I click on "([^"]*)" item in the autocomplete list$/
*
* @param string $item
*/
public function i_click_on_item_in_the_autocomplete_list($item) {
$xpathtarget = "//ul[@class='form-autocomplete-suggestions']//li//span//span[contains(.,'" . $item . "')]";
$this->execute('behat_general::i_click_on', [$xpathtarget, 'xpath_element']);
}
}
......@@ -28,7 +28,7 @@ Feature: Manage plearning plan
And I follow "Home"
And I navigate to "Competencies > Learning plan templates" in site administration
And I click on ".template-userplans" "css_element" in the "Science template" "table_row"
And I click on ".form-autocomplete-downarrow" "css_element"
And I open the autocomplete suggestions list
And I click on "Admin" item in the autocomplete list
And I press key "27" in the field "Select users to create learning plans for"
When I click on "Create learning plans" "button"
......
......@@ -28,10 +28,10 @@ Feature: Users can be added to multiple groups at once
And I am on "Course 1" course homepage
And I follow "Participants"
And I click on "Edit groups for \"Student 1\"" "link" in the "student1" "table_row"
And I click on ".form-autocomplete-downarrow" "css_element"
And I click on ".form-autocomplete-suggestions [role=option]" "css_element"
And I click on ".form-autocomplete-downarrow" "css_element"
And I click on ".form-autocomplete-suggestions [role=option]" "css_element"
And I open the autocomplete suggestions list
And I click on "Group 1" item in the autocomplete list
And I open the autocomplete suggestions list
And I click on "Group 2" item in the autocomplete list
And I click on "Save changes" "link"
Then I should see "Group 1, Group 2"
......
......@@ -293,5 +293,4 @@ class behat_field_manager {
return self::get_field_node_type($fieldnode, $session);
}
}
......@@ -54,5 +54,6 @@ class behat_form_autocomplete extends behat_form_text {
$id = $this->field->getAttribute('id');
$js = ' require(["jquery"], function($) { $(document.getElementById("'.$id.'")).trigger("behat:set-value"); }); ';
$this->session->executeScript($js);
$this->key_press(27);
}
}
......@@ -517,4 +517,29 @@ class behat_forms extends behat_base {
}
}
/**
* Select item from autocomplete list.
*
* @Given /^I click on "([^"]*)" item in the autocomplete list$/
*
* @param string $item
*/
public function i_click_on_item_in_the_autocomplete_list($item) {
$xpathtarget = "//ul[@class='form-autocomplete-suggestions']//*[contains(.,'" . $item . "')]";
$this->execute('behat_general::i_click_on', [$xpathtarget, 'xpath_element']);
$this->execute('behat_general::i_press_key_in_element', ['13', 'body', 'xpath_element']);
}
/**
* Open the auto-complete suggestions list (Assuming there is only one on the page.).
*
* @Given /^I open the autocomplete suggestions list$/
*/
public function i_open_the_autocomplete_suggestions_list() {
$csstarget = ".form-autocomplete-downarrow";
$this->execute('behat_general::i_click_on', [$csstarget, 'css_element']);
}
}
......@@ -54,7 +54,7 @@ Feature: Edited book chapters handle tags correctly
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Test book"
And I click on ".form-autocomplete-downarrow" "css_element"
And I open the autocomplete suggestions list
And I should see "OT1" in the ".form-autocomplete-suggestions" "css_element"
And I should see "OT2" in the ".form-autocomplete-suggestions" "css_element"
And I should see "OT3" in the ".form-autocomplete-suggestions" "css_element"
......
......@@ -52,7 +52,7 @@ Feature: Edited forum posts handle tags correctly
And I follow "Test forum"
And I click on "Add a new discussion topic" "button"
And I expand all fieldsets
And I click on ".form-autocomplete-downarrow" "css_element"
And I open the autocomplete suggestions list
And I should see "OT1" in the ".form-autocomplete-suggestions" "css_element"
And I should see "OT2" in the ".form-autocomplete-suggestions" "css_element"
And I should see "OT3" in the ".form-autocomplete-suggestions" "css_element"
......
......@@ -56,7 +56,7 @@ Feature: Edited glossary entries handle tags correctly
And I follow "Test glossary"
And I press "Add a new entry"
And I expand all fieldsets
And I click on ".form-autocomplete-downarrow" "css_element"
And I open the autocomplete suggestions list
And I should see "OT1" in the ".form-autocomplete-suggestions" "css_element"
And I should see "OT2" in the ".form-autocomplete-suggestions" "css_element"
And I should see "OT3" in the ".form-autocomplete-suggestions" "css_element"
......
......@@ -56,7 +56,7 @@ Feature: Edited wiki pages handle tags correctly
And I am on "Course 1" course homepage
And I follow "Test wiki name"
And I press "Create page"
And I click on ".form-autocomplete-downarrow" "css_element"
And I open the autocomplete suggestions list
And I should see "OT1" in the ".form-autocomplete-suggestions" "css_element"
And I should see "OT2" in the ".form-autocomplete-suggestions" "css_element"
And I should see "OT3" in the ".form-autocomplete-suggestions" "css_element"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment