[Behat][Country] Enable tests

This commit is contained in:
Wojdylak 2024-01-30 08:13:47 +01:00
parent c1f4cdf773
commit cc9f5b5f41
No known key found for this signature in database
GPG key ID: 7509E560A6821ABE
20 changed files with 113 additions and 121 deletions

View file

@ -7,7 +7,7 @@ Feature: Adding a new country
Background:
Given I am logged in as an administrator
@ui @api
@api @ui
Scenario: Adding country
When I want to add a new country
And I choose "United States"

View file

@ -7,7 +7,7 @@ Feature: Adding countries with provinces
Background:
Given I am logged in as an administrator
@ui @javascript @api
@api @ui @javascript
Scenario: Adding a country with a province
When I want to add a new country
And I choose "United Kingdom"
@ -17,7 +17,7 @@ Feature: Adding countries with provinces
And the country "United Kingdom" should appear in the store
And the country "United Kingdom" should have the "Scotland" province
@ui @javascript @api
@api @ui @javascript
Scenario: Adding a country with two provinces
When I want to add a new country
And I choose "United Kingdom"

View file

@ -8,7 +8,7 @@ Feature: Country validation
Given the store operates in "Norway"
And I am logged in as an administrator
@todo @ui @api
@api @ui
Scenario: Trying to add a new country with used code
When I want to add a new country
Then I should not be able to choose "Norway"

View file

@ -7,7 +7,7 @@ Feature: Editing country
Background:
Given I am logged in as an administrator
@todo @ui @api
@api @ui
Scenario: Disabling country
Given the store has country "United States"
When I want to edit this country
@ -16,7 +16,7 @@ Feature: Editing country
Then I should be notified that it has been successfully edited
And this country should be disabled
@todo @ui @api
@api @ui
Scenario: Enabling country
Given the store has disabled country "United States"
When I want to edit this country
@ -25,7 +25,7 @@ Feature: Editing country
Then I should be notified that it has been successfully edited
And this country should be enabled
@todo @ui @api
@api @ui
Scenario: Seeing disabled code field while editing country
Given the store has country "United States"
When I want to edit this country

View file

@ -8,7 +8,7 @@ Feature: Managing provinces of a country
Given the store has country "United Kingdom"
And I am logged in as an administrator
@todo @ui @javascript @api
@api @ui @javascript
Scenario: Adding a province to an existing country
When I want to edit this country
And I add the "Scotland" province with "GB-SCT" code
@ -16,7 +16,7 @@ Feature: Managing provinces of a country
Then I should be notified that it has been successfully edited
And this country should have the "Scotland" province
@todo @ui @javascript @api
@api @ui @javascript
Scenario: Removing a province from an existing country
Given this country has the "Northern Ireland" province with "GB-NIR" code
When I want to edit this country
@ -25,7 +25,7 @@ Feature: Managing provinces of a country
Then I should be notified that it has been successfully edited
And this country should not have the "Northern Ireland" province
@todo @ui @javascript @api
@api @ui @javascript
Scenario: Removing a province that is a zone member should not be possible
Given this country has the "Northern Ireland" province with "GB-NIR" code
And this country also has the "Scotland" province with "GB-SCT" code
@ -43,7 +43,7 @@ Feature: Managing provinces of a country
And this country should still have the "Scotland" province
And this country should still have the "England" province
@todo @ui @javascript @api
@api @ui @javascript
Scenario: Removing a province that is not a zone member anymore should be possible
Given this country has the "Northern Ireland" province with "GB-NIR" code
And this country also has the "Scotland" province with "GB-SCT" code
@ -60,18 +60,18 @@ Feature: Managing provinces of a country
And this country should not have the "England" province
And this country should still have the "Northern Ireland" and "Scotland" provinces
@todo @ui @javascript @api
@api @ui @javascript
Scenario: Removing and adding a new province to an existing country
Given this country has the "Northern Ireland" province with "GB-NIR" code
When I want to edit this country
And I delete the "Northern Ireland" province of this country
And I add the "Scotland" province with "GB-SCT" code
And I delete the "Northern Ireland" province of this country
And I save my changes
Then I should be notified that it has been successfully edited
And this country should not have the "Northern Ireland" province
And this country should have the "Scotland" province
@todo @ui @javascript @api
@api @ui @javascript
Scenario: Adding a province with an austrian province code
When I want to edit this country
And I add the "Wien" province with "AT-9" code

View file

@ -9,7 +9,7 @@ Feature: Province unique fields validation
And this country has the "Northern Ireland" province with "GB-NIR" code
And I am logged in as an administrator
@todo @ui @javascript @api
@api @ui @javascript
Scenario: Trying to add a new province with a taken code
When I want to add a new country
And I choose "Gibraltar"
@ -17,14 +17,14 @@ Feature: Province unique fields validation
And I try to add it
Then I should be notified that province code must be unique
@todo @ui @javascript @api
@api @ui @javascript
Scenario: Trying to add a new province with a taken name
When I want to edit this country
And I add the "Northern Ireland" province with "GB-NI" code
And I save my changes
Then I should be notified that province name must be unique
@todo @ui @javascript @api
@api @ui @javascript
Scenario: Trying to add new provinces with duplicated codes
When I want to edit this country
And I add the "Scotland" province with "GB-SCO" code
@ -32,7 +32,7 @@ Feature: Province unique fields validation
And I save my changes
Then I should be notified that all province codes and names within this country need to be unique
@todo @ui @javascript @api
@api @ui @javascript
Scenario: Trying to add new provinces with duplicated names
When I want to edit this country
And I add the "Scotland" province with "GB-SC" code

View file

@ -8,7 +8,7 @@ Feature: Province validation
Given the store has country "United Kingdom"
And I am logged in as an administrator
@todo @ui @javascript @api
@api @ui @javascript
Scenario: Trying to add a new province without specifying its code
When I want to create a new province in country "United Kingdom"
And I name the province "Scotland"
@ -17,7 +17,7 @@ Feature: Province validation
Then I should be notified that code is required
And province with name "Scotland" should not be added in this country
@todo @ui @javascript @api
@api @ui @javascript
Scenario: Trying to add a new province without specifying its name
When I want to create a new province in country "United Kingdom"
And I specify the province code as "GB-SCT"
@ -26,7 +26,7 @@ Feature: Province validation
Then I should be notified that name is required
And province with code "GB-SCT" should not be added in this country
@todo @ui @javascript @api
@api @ui @javascript
Scenario: Trying to remove name from an existing province
Given this country has the "Northern Ireland" province with "GB-NIR" code
When I want to edit this country

View file

@ -97,7 +97,7 @@ final class ManagingCountriesContext implements Context
/**
* @When I disable it
*/
public function iDisableIt()
public function iDisableIt(): void
{
$this->updatePage->disable();
}
@ -134,7 +134,7 @@ final class ManagingCountriesContext implements Context
/**
* @Then /^(this country) should be disabled$/
*/
public function thisCountryShouldBeDisabled(CountryInterface $country)
public function thisCountryShouldBeDisabled(CountryInterface $country): void
{
$this->indexPage->open();
@ -144,10 +144,10 @@ final class ManagingCountriesContext implements Context
/**
* @Then I should not be able to choose :name
*/
public function iShouldNotBeAbleToChoose($name)
public function iShouldNotBeAbleToChoose(string $name): void
{
try {
$this->createPage->chooseName($name);
$this->createPage->selectCountry($name);
} catch (ElementNotFoundException) {
return;
}
@ -158,7 +158,7 @@ final class ManagingCountriesContext implements Context
/**
* @Then I should not be able to edit its code
*/
public function theCodeFieldShouldBeDisabled()
public function theCodeFieldShouldBeDisabled(): void
{
Assert::true($this->updatePage->isCodeFieldDisabled());
}
@ -220,7 +220,7 @@ final class ManagingCountriesContext implements Context
/**
* @When /^I(?:| also) delete the "([^"]*)" province of this country$/
*/
public function iDeleteTheProvinceOfCountry($provinceName)
public function iDeleteTheProvinceOfCountry($provinceName): void
{
$this->updatePage->removeProvince($provinceName);
}
@ -228,27 +228,27 @@ final class ManagingCountriesContext implements Context
/**
* @When /^I want to create a new province in (country "([^"]*)")$/
*/
public function iWantToCreateANewProvinceInCountry(CountryInterface $country)
public function iWantToCreateANewProvinceInCountry(CountryInterface $country): void
{
$this->updatePage->open(['id' => $country->getId()]);
$this->updatePage->clickAddProvinceButton();
$this->updatePage->addProvince();
}
/**
* @When I name the province :provinceName
* @When I do not name the province
*/
public function iNameTheProvince($provinceName = null)
public function iNameTheProvince($provinceName = null): void
{
$this->updatePage->nameProvince($provinceName ?? '');
$this->updatePage->specifyProvinceName($provinceName ?? '');
}
/**
* @When I do not specify the province code
* @When I specify the province code as :provinceCode
*/
public function iSpecifyTheProvinceCode($provinceCode = null)
public function iSpecifyTheProvinceCode($provinceCode = null): void
{
$this->updatePage->specifyProvinceCode($provinceCode ?? '');
}

View file

@ -13,8 +13,6 @@ declare(strict_types=1);
namespace Sylius\Behat\Page\Admin\Country;
use Behat\Mink\Element\NodeElement;
use Sylius\Behat\Behaviour\ChoosesName;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
use Webmozart\Assert\Assert;

View file

@ -17,6 +17,8 @@ use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface;
interface CreatePageInterface extends BaseCreatePageInterface
{
public function selectCountry(string $countryName): void;
public function addProvince(): void;
public function specifyProvinceName(string $name): void;
@ -24,6 +26,4 @@ interface CreatePageInterface extends BaseCreatePageInterface
public function specifyProvinceCode(string $code): void;
public function specifyProvinceAbbreviation(string $abbreviation): void;
public function selectCountry(string $countryName): void;
}

View file

@ -20,12 +20,12 @@ class IndexPage extends BaseIndexPage implements IndexPageInterface
{
public function isCountryDisabled(CountryInterface $country): bool
{
return $this->checkCountryStatus($country, 'Disabled');
return $this->checkCountryStatus($country, 'disabled');
}
public function isCountryEnabled(CountryInterface $country): bool
{
return $this->checkCountryStatus($country, 'Enabled');
return $this->checkCountryStatus($country, 'enabled');
}
private function checkCountryStatus(CountryInterface $country, string $status): bool
@ -36,6 +36,6 @@ class IndexPage extends BaseIndexPage implements IndexPageInterface
$row = $tableAccessor->getRowWithFields($table, ['code' => $country->getCode()]);
$enabledField = $tableAccessor->getFieldFromRow($table, $row, 'enabled');
return $enabledField->getText() === $status;
return $enabledField->has('css', sprintf('[data-test-status-%s]', $status));
}
}

View file

@ -30,6 +30,33 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
return $codeField->getAttribute('disabled') === 'disabled';
}
public function addProvince(): void
{
$count = count($this->getProvinceItems());
$this->getElement('add_province')->click();
$this->getDocument()->waitFor(5, fn () => $count + 1 === count($this->getProvinceItems()));
}
public function specifyProvinceName(string $name): void
{
$province = $this->getElement('last_province');
$province->find('css', '[data-test-province-name]')->setValue($name);
}
public function specifyProvinceCode(string $code): void
{
$province = $this->getElement('last_province');
$province->find('css', '[data-test-province-code]')->setValue($code);
}
public function specifyProvinceAbbreviation(string $abbreviation): void
{
$province = $this->getElement('last_province');
$province->find('css', '[data-test-province-abbreviation]')->setValue($abbreviation);
}
public function isThereProvince(string $provinceName): bool
{
$provinces = $this->getElement('provinces');
@ -47,78 +74,36 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
public function removeProvince(string $provinceName): void
{
if ($this->isThereProvince($provinceName)) {
$provinces = $this->getElement('provinces');
$province = $this->getProvinceElement($provinceName);
$item = $provinces
->find('css', sprintf('div[data-form-collection="item"] input[value="%s"]', $provinceName))
->getParent()
->getParent()
->getParent()
->getParent()
->getParent()
;
$item->clickLink('Delete');
$province->find('css', '[data-test-delete-province]')->click();
$this->getDocument()->waitFor(5, fn () => !$this->isThereProvince($provinceName));
}
}
public function addProvince(string $name, string $code, string $abbreviation = null): void
{
$this->clickAddProvinceButton();
$provinceForm = $this->getLastProvinceElement();
$provinceForm->fillField('Name', $name);
$provinceForm->fillField('Code', $code);
if (null !== $abbreviation) {
$provinceForm->fillField('Abbreviation', $abbreviation);
}
}
public function clickAddProvinceButton(): void
{
$this->getDocument()->clickLink('Add province');
}
public function nameProvince(string $name): void
{
$provinceForm = $this->getLastProvinceElement();
$provinceForm->fillField('Name', $name);
}
public function removeProvinceName(string $provinceName): void
{
if ($this->isThereProvince($provinceName)) {
$provinces = $this->getElement('provinces');
$item = $provinces->find('css', 'div[data-form-collection="item"] input[value="' . $provinceName . '"]')->getParent();
$item->fillField('Name', '');
$province = $this->getProvinceElement($provinceName);
$province->find('css', '[data-test-province-name]')->setValue('');
}
}
public function specifyProvinceCode(string $code): void
{
$provinceForm = $this->getLastProvinceElement();
$provinceForm->fillField('Code', $code);
}
public function getFormValidationErrors(): array
{
$errors = $this->getElement('form')->findAll('css', '.sylius-validation-error:not(.pointing)');
$errors = $this->getElement('form')->findAll('css', '.alert-danger');
return array_map(fn (NodeElement $element) => $element->getText(), $errors);
}
public function getValidationMessage(string $element): string
{
$provinceForm = $this->getLastProvinceElement();
$province = $this->getElement('last_province');
$foundElement = $provinceForm->find('css', '.sylius-validation-error');
$foundElement = $province->find('css', '.invalid-feedback');
if (null === $foundElement) {
throw new ElementNotFoundException($this->getSession(), 'Tag', 'css', '.sylius-validation-error');
throw new ElementNotFoundException($this->getSession(), 'Tag', 'css', '.invalid-feedback');
}
return $foundElement->getText();
@ -135,22 +120,22 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
'code' => '[data-test-code]',
'enabled' => '[data-test-enabled]',
'provinces' => '[data-test-provinces]',
// 'last_province' => '[data-test-provinces] [data-test-province]:last-child',
// 'add_province' => '[data-test-add-province]'
// 'code' => '#sylius_country_code',
// 'enabled' => '#sylius_country_enabled',
// 'form' => 'form',
// 'provinces' => '#sylius_country_provinces',
'last_province' => '[data-test-provinces] [data-test-province]:last-child',
'add_province' => '[data-test-add-province]',
'form' => 'form',
]);
}
private function getLastProvinceElement(): NodeElement
private function getProvinceItems(): array
{
$provinces = $this->getElement('provinces');
$items = $provinces->findAll('css', 'div[data-form-collection="item"]');
$items = $this->getElement('provinces')->findAll('css', '[data-test-province]');
Assert::isArray($items);
Assert::notEmpty($items);
return $items;
}
return end($items);
private function getProvinceElement(string $provinceName): NodeElement|null
{
return $this->getDocument()->find('xpath', sprintf('//*[@data-test-province and .//*[contains(@value, \'%s\')]]', $provinceName));
}
}

View file

@ -23,22 +23,20 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
public function isCodeFieldDisabled(): bool;
public function addProvince(): void;
public function specifyProvinceName(string $name): void;
public function specifyProvinceCode(string $code): void;
public function specifyProvinceAbbreviation(string $abbreviation): void;
public function isThereProvince(string $provinceName): bool;
public function isThereProvinceWithCode(string $provinceCode): bool;
public function addProvince(string $name, string $code, string $abbreviation = null): void;
public function removeProvince(string $provinceName): void;
public function clickAddProvinceButton(): void;
public function nameProvince(string $provinceName): void;
public function removeProvinceName(string $provinceName): void;
public function specifyProvinceCode(string $provinceCode): void;
/** @return array<array-key, string> */
public function getFormValidationErrors(): array;
}

View file

@ -35,7 +35,7 @@ class UpdatePage extends SymfonyPage implements UpdatePageInterface
public function saveChanges(): void
{
$this->getDocument()->pressButton('sylius_save_changes_button');
$this->getDocument()->find('css', '[data-test-update-changes-button]')->click();
}
public function cancelChanges(): void

View file

@ -1 +1 @@
{{ form_row(form.enabled, { label_attr: { class: 'checkbox-switch' } }, sylius_test_form_attribute('enabled')) }}
{{ form_row(form.enabled, sylius_test_form_attribute('enabled')|merge({ label_attr: { class: 'checkbox-switch' } })) }}

View file

@ -36,8 +36,8 @@
</div>
</div>
</div>
<div class="col-auto">
{{ form_row(provinceForm.vars.button_delete, {label: 'X', attr: {class: 'btn btn-outline-danger'}}) }}
<div class="col-auto" {{ sylius_test_html_attribute('delete-province') }}>
{{ form_row(provinceForm.vars.button_delete, {attr: {class: 'btn btn-outline-danger'}}) }}
</div>
</div>
</div>

View file

@ -5,4 +5,4 @@
configuration.vars.index.route.parameters|default(configuration.vars.route.parameters|default({}))
) %}
{{ _button.cancel({ text: 'sylius.ui.cancel'|trans, url: index_url, class: 'btn' }) }}
{{ _button.cancel(sylius_test_form_attribute('cancel-changes-button')|merge({ text: 'sylius.ui.cancel'|trans, url: index_url, class: 'btn' })) }}

View file

@ -1,3 +1,3 @@
{% import '@SyliusAdmin/Shared/Helper/button.html.twig' as _button %}
{{ _button.primary({ text: 'sylius.ui.update'|trans, type: 'submit', form: form.vars.id }) }}
{{ _button.primary(sylius_test_form_attribute('update-changes-button')|merge({ text: 'sylius.ui.update'|trans, type: 'submit', form: form.vars.id })) }}

View file

@ -1,7 +1,7 @@
{% from '@SyliusAdmin/Shared/Helper/icon.html.twig' import icon as _icon %}
{% if true == data %}
<span>{{ _icon({ icon: 'check', class: 'icon text-green' }) }}</span>
<span {{ sylius_test_html_attribute('status-enabled') }}>{{ _icon({ icon: 'check', class: 'icon text-green' }) }}</span>
{% else %}
<span>{{ _icon({ icon: 'x', class: 'icon icon-sm text-secondary' }) }}</span>
<span {{ sylius_test_html_attribute('status-disabled') }}>{{ _icon({ icon: 'x', class: 'icon icon-sm text-secondary' }) }}</span>
{% endif %}

View file

@ -30,7 +30,7 @@
class="{{ buttonClass }}"
{% if p.disabled %}aria-disabled="true"{% endif %}
{% if p.dropdown %}data-bs-toggle="dropdown"{% endif %}
{{ p.attr }}>
{{ block('attributes') }}>
{{ p.icon ? i({ icon: p.icon }) }}
{{ not p.iconOnly ? p.text }}
</a>
@ -41,7 +41,7 @@
class="{{ buttonClass }}"
{% if p.disabled %}disabled{% endif %}
{% if p.dropdown %}data-bs-toggle="dropdown"{% endif %}
{{ p.attr }}>
{{ block('attributes') }}>
{{ p.icon ? i({ icon: p.icon }) }}
{{ not p.iconOnly ? p.text }}
</button>
@ -98,3 +98,14 @@
{{ _.default(params) }}
{% endmacro %}
{% block attributes -%}
{%- for attrname, attrvalue in p.attr -%}
{{- " " -}}
{%- if attrvalue is same as(true) -%}
{{- attrname }}="{{ attrname }}"
{%- elseif attrvalue is not same as(false) -%}
{{- attrname }}="{{ attrvalue }}"
{%- endif -%}
{%- endfor -%}
{%- endblock attributes -%}