Skip to content

Commit

Permalink
Improve InlineEdit keyboard testing (#2104)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Sep 9, 2023
1 parent 1ea7959 commit f684b41
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@
"require": {
"php": ">=7.4 <8.4",
"atk4/data": "dev-develop",
"nyholm/psr7": "^1.4",
"nyholm/psr7": "^1.6",
"nyholm/psr7-server": "^1.0",
"symfony/filesystem": "^4.4 || ^5.3 || ^6.0",
"symfony/http-foundation": "^4.4 || ^5.3 || ^6.0"
},
"require-release": {
"php": ">=7.4 <8.4",
"atk4/data": "~5.0.0",
"nyholm/psr7": "^1.4",
"nyholm/psr7": "^1.6",
"nyholm/psr7-server": "^1.0",
"symfony/filesystem": "^4.4 || ^5.3 || ^6.0",
"symfony/http-foundation": "^4.4 || ^5.3 || ^6.0"
},
"require-dev": {
"atk4/behat-mink-selenium2-driver": "^1.6.1",
"atk4/behat-mink-selenium2-driver": "^1.6.2",
"behat/mink-extension": "^2.3.1",
"ergebnis/composer-normalize": "^2.13",
"friendsofphp/php-cs-fixer": "^3.0",
Expand Down
4 changes: 2 additions & 2 deletions src/Behat/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ public function compareInputValueToText(string $selector, string $text): void

$inputValue = $this->findElement(null, $selector)->getValue();
if ($inputValue !== $text) {
throw new \Exception('Input value does not match: ' . $inputValue . ' expected: ' . $text);
throw new \Exception('Input value does not match: ' . $inputValue . ', expected: ' . $text);
}
}

Expand All @@ -678,7 +678,7 @@ public function compareInputValueToElementText(string $inputName, string $select
$expectedText = $this->findElement(null, $selector)->getText();
$input = $this->findElement(null, 'input[name="' . $inputName . '"]');
if ($expectedText !== $input->getValue()) {
throw new \Exception('Input value does not match: ' . $input->getValue() . ' expected: ' . $expectedText);
throw new \Exception('Input value does not match: ' . $input->getValue() . ', expected: ' . $expectedText);
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/Behat/MinkSeleniumDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ protected function mouseOverElement(WebDriverElement $element): void
$this->getWebDriverSession()->moveto(['element' => $element->getID()]);
}

private function executeJsSelectText(WebDriverElement $element, int $start, int $stop = null): void
{
$this->executeScript(
'arguments[0].setSelectionRange(Math.min(arguments[1], Number.MAX_SAFE_INTEGER), Math.min(arguments[2], Number.MAX_SAFE_INTEGER));',
[$element, $start, $stop ?? $start]
);
}

/**
* @param 'type' $action
* @param string $options
Expand All @@ -81,6 +89,11 @@ public function keyboardWrite(string $xpath, $text): void
$focusedElement = $this->getWebDriverSession()->activeElement();
if ($element->getID() !== $focusedElement->getID()) {
$this->clickOnElement($element);
$focusedElement = $this->getWebDriverSession()->activeElement();
}

if (in_array($focusedElement->name(), ['input', 'textarea'], true)) {
$this->executeJsSelectText($focusedElement, \PHP_INT_MAX);
}

$this->executeSynJsAndWait('type', $element, $text);
Expand Down
15 changes: 13 additions & 2 deletions tests-behat/vue.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ Feature: Vue
Then Toast display should contain text "Update saved"
Given I am on "javascript/vue-component.php"
Then I check if input value for "(//input[@name='atk_fp_country__name'])[1]" match text "test autoSave"
When I fill field using "(//input[@name='atk_fp_country__name'])[1]" with "Germany"
When I fill field using "(//input[@name='atk_fp_country__name'])[1]" with "germany"
Then Toast display should contain text "Country name must be unique."
Then I check if input value for "(//input[@name='atk_fp_country__name'])[1]" match text "germany"
When I write "[escape]" into selector "(//input[@name='atk_fp_country__name'])[1]"
Then I check if input value for "(//input[@name='atk_fp_country__name'])[1]" match text "test autoSave"

Scenario: testing InlineEdit - /w onChange callback
Scenario: testing InlineEdit - special keys typing using bitovi/syn
When I persist DB changes across requests
When I write "[ctrl]a[ctrl-up]test ean[left][backspace]" into selector "(//input[@name='atk_fp_country__name'])[1]"
Then No toast should be displayed
When I write "ter[enter]" into selector "(//input[@name='atk_fp_country__name'])[1]"
Then Toast display should contain text "Update saved"
Given I am on "javascript/vue-component.php"
Then I check if input value for "(//input[@name='atk_fp_country__name'])[1]" match text "test enter"

Scenario: testing InlineEdit - /w onChange callback
When I fill field using "(//input[@name='atk_fp_country__name'])[2]" with "test callback"
Then I should see "new value: test callback"
Then I hide js modal
Expand Down

0 comments on commit f684b41

Please sign in to comment.