MDL-85374 report_competency: Create custom step for setting autocomplete
The autocompletes used in the competency report have been bastardised to redirect on selection. Unfortunately this also applies when when making null-op changes like deleting the initial "Please select a value" option. The autocomplete code removes all current options before creating an option, and because of this redirect the browser is redirecting before the new value can be entered, but we retain a reference to the field as `$this->field`, which is now stale.
This commit is contained in:
@@ -46,11 +46,11 @@ Feature: See the competencies for an activity on the course competencies page.
|
||||
When I follow "Competencies"
|
||||
Then I should see "Test-Comp1"
|
||||
And I should see "Test-Comp2"
|
||||
And I set the field "Filter competencies by resource or activity" to "PageName1"
|
||||
And I set the competency filter "Filter competencies by resource or activity" to "PageName1"
|
||||
And I press the enter key
|
||||
And I should see "Test-Comp1"
|
||||
And I should not see "Test-Comp2"
|
||||
And I set the field "Filter competencies by resource or activity" to "PageName2"
|
||||
And I set the competency filter "Filter competencies by resource or activity" to "PageName2"
|
||||
And I press the enter key
|
||||
And I should not see "Test-Comp1"
|
||||
And I should not see "Test-Comp2"
|
||||
|
||||
@@ -72,7 +72,6 @@ class behat_field_manager {
|
||||
* @return behat_form_field
|
||||
*/
|
||||
public static function get_form_field(NodeElement $fieldnode, Session $session) {
|
||||
|
||||
// Get the field type if is part of a moodleform.
|
||||
if (self::is_moodleform_field($fieldnode)) {
|
||||
$type = self::get_field_node_type($fieldnode, $session);
|
||||
|
||||
@@ -326,4 +326,13 @@ class behat_form_field implements behat_session_interface {
|
||||
|
||||
return $this->fieldlocator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field node.
|
||||
*
|
||||
* @return NodeElement
|
||||
*/
|
||||
public function get_node(): NodeElement {
|
||||
return $this->field;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,4 +76,52 @@ class behat_report_competency extends behat_base {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a competency filter.
|
||||
*
|
||||
* @When /^I set the competency filter "([^"]*)" to "([^"]*)"$/
|
||||
* @param string $fieldlocator The field locator.
|
||||
* @param string $value The value to set.
|
||||
* @throws Exception
|
||||
*/
|
||||
public function set_competency_filter(
|
||||
string $fieldlocator,
|
||||
string $value,
|
||||
): void {
|
||||
$field = behat_field_manager::get_form_field_from_label($fieldlocator, $this)->get_node();
|
||||
$session = $this->getSession();
|
||||
|
||||
$value = trim($value);
|
||||
|
||||
// Click into the field.
|
||||
$field->click();
|
||||
|
||||
// Remove any existing text.
|
||||
do {
|
||||
behat_base::type_keys($session, [behat_keys::BACKSPACE, behat_keys::DELETE]);
|
||||
} while (strlen($field->getValue()) > 0);
|
||||
$this->wait_for_pending_js();
|
||||
|
||||
// Type in the new value.
|
||||
behat_base::type_keys($session, str_split($value));
|
||||
$this->wait_for_pending_js();
|
||||
|
||||
// If the autocomplete found suggestions, then it will have:
|
||||
// 1) marked itself as expanded; and
|
||||
// 2) have an aria-selected suggestion in the list.
|
||||
$expanded = $field->getAttribute('aria-expanded');
|
||||
$suggestion = $field->getParent()->getParent()->find('css', '.form-autocomplete-suggestions > [aria-selected="true"]');
|
||||
|
||||
if ($expanded && null !== $suggestion) {
|
||||
// A suggestion was found.
|
||||
// Click on the first item in the list.
|
||||
$suggestion->click();
|
||||
} else {
|
||||
throw new \InvalidArgumentException(
|
||||
"Unable to find '{$value}' in the list of options."
|
||||
);
|
||||
}
|
||||
|
||||
$this->wait_for_pending_js();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ Feature: See the competencies for an activity
|
||||
Scenario: Go to the competency breakdown report
|
||||
When I navigate to "Reports" in current page administration
|
||||
And I click on "Competency breakdown" "link"
|
||||
And I set the field "Filter competencies by resource or activity" to "PageName1"
|
||||
And I set the competency filter "Filter competencies by resource or activity" to "PageName1"
|
||||
Then I should see "Test-Comp1"
|
||||
And I should not see "Test-Comp2"
|
||||
And I should see "Ann, Jill, Grainne, Beauchamp"
|
||||
|
||||
Reference in New Issue
Block a user