MNT Behat test for hidden form steps

This commit is contained in:
Steve Boyd 2021-03-10 15:56:24 +13:00
parent 79259b593a
commit cdf6264242
45 changed files with 149 additions and 2 deletions

View File

@ -10,7 +10,7 @@ indent_style = space
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
[{*.yml,package.json,*.js,*.scss}] [{*.yml,package.json,*.js,*.scss,*.feature}]
indent_size = 2 indent_size = 2
# The indent size used in the package.json file cannot be changed: # The indent size used in the package.json file cannot be changed:

View File

@ -29,6 +29,12 @@ jobs:
- REQUIRE_INSTALLER="4.7.x-dev" - REQUIRE_INSTALLER="4.7.x-dev"
- PHPUNIT_TEST=1 - PHPUNIT_TEST=1
- PHPCS_TEST=1 - PHPCS_TEST=1
- php: 7.3
env:
- DB=MYSQL
- REQUIRE_INSTALLER="4.7.x-dev"
- BEHAT_TEST=1
- BEHAT_SUITE="userforms"
- php: 7.4 - php: 7.4
env: env:
- DB=MYSQL - DB=MYSQL

34
behat.yml Normal file
View File

@ -0,0 +1,34 @@
# Run asset-admin behat tests with this command (installed with silverstripe/installer)
# Note that asset-admin behat tests require CMS module
# ========================================================================= #
# vendor/bin/selenium-server-standalone -Dwebdriver.firefox.bin="/Applications/Firefox31.app/Contents/MacOS/firefox-bin"
# vendor/bin/serve --bootstrap-file vendor/silverstripe/cms/tests/behat/serve-bootstrap.php
# vendor/bin/behat @asset-admin
# ========================================================================= #
default:
suites:
userforms:
paths:
- "%paths.modules.userforms%/tests/behat/features"
contexts:
- SilverStripe\UserForms\Tests\Behat\Context\FeatureContext
- SilverStripe\Framework\Tests\Behaviour\CmsFormsContext
- SilverStripe\Framework\Tests\Behaviour\CmsUiContext
- SilverStripe\BehatExtension\Context\BasicContext
- SilverStripe\BehatExtension\Context\EmailContext
- SilverStripe\BehatExtension\Context\LoginContext
-
SilverStripe\UserForms\Tests\Behat\Context\FixtureContext:
- "%paths.modules.userforms%/tests/behat/files/"
extensions:
SilverStripe\BehatExtension\Extension:
bootstrap_file: vendor/silverstripe/cms/tests/behat/serve-bootstrap.php
screenshot_path: "%paths.base%/artifacts/screenshots"
retry_seconds: 4 # default is 2
SilverStripe\BehatExtension\MinkExtension:
default_session: facebook_web_driver
javascript_session: facebook_web_driver
facebook_web_driver:
browser: chrome
wd_host: "http://127.0.0.1:9515" #chromedriver port
browser_name: chrome

View File

@ -44,7 +44,8 @@
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"SilverStripe\\UserForms\\": "code/", "SilverStripe\\UserForms\\": "code/",
"SilverStripe\\UserForms\\Tests\\": "tests/" "SilverStripe\\UserForms\\Tests\\": "tests/php/",
"SilverStripe\\UserForms\\Tests\\Behat\\Context\\": "tests/behat/src/"
} }
}, },
"suggest": { "suggest": {

1
tests/behat/README.md Normal file
View File

@ -0,0 +1 @@
See https://github.com/silverstripe-labs/silverstripe-behat-extension

View File

View File

@ -0,0 +1,21 @@
@assets @retry
Feature: Next form step for userforms
As a website user
I want to click to the next form step button to see the next form step
Background:
Given a userform with a hidden form step "My userform"
Scenario: Next step button does not navigate to hidden form steps
When I go to "/my-userform"
And I wait for 2 seconds
And the ".progress-title" element should contain "EditableFormStep_01"
When I click the ".step-button-next" element
Then the ".progress-title" element should contain "EditableFormStep_03"
When I click the ".step-button-prev" element
And I fill in "abc" for "EditableTextField_01"
And I click the ".step-button-next" element
Then the ".progress-title" element should contain "EditableFormStep_02"
# prevent the 'form has unsaved changes' alrt
When I click the ".step-button-prev" element
And I fill in "" for "EditableTextField_01"

View File

@ -0,0 +1 @@
abc

View File

@ -0,0 +1,9 @@
<?php
namespace SilverStripe\UserForms\Tests\Behat\Context;
use SilverStripe\BehatExtension\Context\SilverStripeContext;
class FeatureContext extends SilverStripeContext
{
}

View File

@ -0,0 +1,74 @@
<?php
namespace SilverStripe\UserForms\Tests\Behat\Context;
use SilverStripe\BehatExtension\Context\FixtureContext as BaseFixtureContext;
use SilverStripe\ORM\DataObject;
use SilverStripe\UserForms\Model\EditableCustomRule;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormStep;
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\Versioned\Versioned;
/**
* Context used to create fixtures in the SilverStripe ORM.
*/
class FixtureContext extends BaseFixtureContext
{
/**
* @When /^I click the "([^"]+)" element$/
* @param $selector
*/
public function iClickTheElement(string $selector): void
{
$page = $this->getMainContext()->getSession()->getPage();
$element = $page->find('css', $selector);
assertNotNull($element, sprintf('Element %s not found', $selector));
$element->click();
}
/**
* Example: Given a userform with a hidden form step "My userform"
*
* @Given /^a userform with a hidden form step "([^"]+)"$/
* @param string $udfTitle
*/
public function stepCreateUserFormWithHiddenFormStep(string $udfTitle): void
{
/** @var UserDefinedForm|Versioned $udf */
/** @var EditableTextField $tf01 */
/** @var EditableFormStep $fs02 */
$udf = $this->getFixtureFactory()->createObject(UserDefinedForm::class, $udfTitle);
$this->createEditableFormField(EditableFormStep::class, 'EditableFormStep_01', $udf);
$tf01 = $this->createEditableFormField(EditableTextField::class, 'EditableTextField_01', $udf);
$fs02 = $this->createEditableFormField(EditableFormStep::class, 'EditableFormStep_02', $udf);
$this->createEditableFormField(EditableTextField::class, 'EditableTextField_02', $udf);
$fs02->ShowOnLoad = 0;
$fs02->write();
$this->createCustomRule('cr1', $fs02, $tf01);
$this->createEditableFormField(EditableFormStep::class, 'EditableFormStep_03', $udf);
$this->createEditableFormField(EditableTextField::class, 'EditableTextField_03', $udf);
$udf->publishRecursive();
}
private function createEditableFormField(string $class, string $id, UserDefinedForm $udf): DataObject
{
$field = $this->getFixtureFactory()->createObject($class, $id);
$field->Title = $id;
$field->Parent = $udf;
$field->write();
return $field;
}
private function createCustomRule(string $id, EditableFormStep $fs, EditableTextField $tf): EditableCustomRule
{
/** @var EditableCustomRule $rule */
$rule = $this->getFixtureFactory()->createObject(EditableCustomRule::class, $id);
$rule->Parent = $fs;
$rule->ConditionField = $tf;
$rule->Display = 'Show';
$rule->ConditionOption = 'IsNotBlank';
$rule->write();
return $rule;
}
}

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB