Skip to content

Commit

Permalink
Merge pull request #228 from ibexa/merge-ibx-1481-added-language-sele…
Browse files Browse the repository at this point in the history
…ction-coverage-for-behat

[Behat] Merge IBX-1481 added language selection coverage for behat
  • Loading branch information
Nattfarinn authored Jan 25, 2022
2 parents 5a5f75a + 41b3e59 commit e894d4e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/lib/Behat/BrowserContext/ContentUpdateContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public function verifyFieldIsNotEditable(string $fieldName): void
Assert::assertEquals(NonEditableField::EXPECTED_NON_EDITABLE_TEXT, $field->getValue()[0]);
}

/**
* @When the :fieldName field in :fieldGroup field group cannot be edited due to limitation
*/
public function theFieldCannotBeEditedDueToLimitation(string $fieldName, string $fieldGroup): void
{
$this->contentUpdateItemPage->switchToFieldGroup($fieldGroup);
$this->contentUpdateItemPage->verifyFieldCannotBeEditedDueToLimitation($fieldName);
}

/**
* @When I set content fields for user
*/
Expand Down
5 changes: 3 additions & 2 deletions src/lib/Behat/BrowserContext/ContentViewContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ public function __construct(

/**
* @Given I start creating a new Content :contentType
* @Given I start creating a new Content :contentType in :language language
*/
public function startCreatingContent(string $contentType): void
public function startCreatingContent(string $contentType, string $language = null): void
{
$this->contentViewPage->startCreatingContent($contentType);
$this->contentViewPage->startCreatingContent($contentType, $language);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/lib/Behat/Component/ContentTypePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@

namespace Ibexa\AdminUi\Behat\Component;

use Behat\Mink\Session;
use Ibexa\Behat\Browser\Component\Component;
use Ibexa\Behat\Browser\Element\Criterion\ElementTextCriterion;
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;

class ContentTypePicker extends Component
{
private IbexaDropdown $ibexaDropdown;

public function __construct(Session $session, IbexaDropdown $ibexaDropdown)
{
parent::__construct($session);
$this->ibexaDropdown = $ibexaDropdown;
}

public function select(string $contentTypeName): void
{
$countBeforeFiltering = $this->getDisplayedItemsCount();
Expand All @@ -27,6 +36,12 @@ public function select(string $contentTypeName): void
->click();
}

public function selectLanguage(string $language): void
{
$this->getHTMLPage()->find($this->getLocator('languageDropdown'))->click();
$this->ibexaDropdown->selectOption($language);
}

protected function getDisplayedItemsCount(): int
{
return $this->getHTMLPage()->findAll($this->getLocator('filteredItem'))->count();
Expand All @@ -44,6 +59,7 @@ protected function specifyLocators(): array
new VisibleCSSLocator('filterInput', '.ibexa-extra-actions__section-content--content-type .ibexa-instant-filter__input'),
new VisibleCSSLocator('filteredItem', '.ibexa-extra-actions__section-content--content-type .ibexa-instant-filter__group-item:not([hidden]) .form-check-label'),
new VisibleCSSLocator('header', '.ibexa-extra-actions--create .ibexa-extra-actions__header h2'),
new VisibleCSSLocator('languageDropdown', '.ibexa-dropdown__selection-info'),
];
}
}
9 changes: 9 additions & 0 deletions src/lib/Behat/Page/ContentUpdateItemPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ protected function specifyLocators(): array
new VisibleCSSLocator('formElement', '[name=ezplatform_content_forms_content_edit]'),
new VisibleCSSLocator('closeButton', '.ibexa-anchor-navigation-menu__back'),
new VisibleCSSLocator('nthField', '.ibexa-field-edit:nth-of-type(%s)'),
new VisibleCSSLocator('fieldGroupNthField', '[data-anchor-section-id="%s"] div .ibexa-field-edit:nth-of-type(%s)'),
new VisibleCSSLocator('noneditableFieldClass', 'ibexa-field-edit--eznoneditable'),
new VisibleCSSLocator('fieldOfType', '.ibexa-field-edit--%s'),
new VisibleCSSLocator('navigationTabs', '.ibexa-anchor-navigation-menu__item'),
Expand Down Expand Up @@ -176,4 +177,12 @@ public function switchToFieldGroup(string $tabName): void
->getByCriterion(new ElementTextCriterion($tabName))
->click();
}

public function verifyFieldCannotBeEditedDueToLimitation(string $fieldName)
{
$activeSections = $this->getHTMLPage()->findAll(new VisibleCSSLocator('activeSection', '.ibexa-anchor-navigation-menu__item-btn--active'));
$fieldLocator = new VisibleCSSLocator('', sprintf($this
->getLocator('fieldGroupNthField')->getSelector(), $activeSections->single()->getAttribute('data-anchor-target-section-id'), $this->getFieldPosition($fieldName)));
$this->getHTMLPage()->find($fieldLocator)->assert()->hasClass('ibexa-field-edit--disabled');
}
}
5 changes: 4 additions & 1 deletion src/lib/Behat/Page/ContentViewPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@ public function __construct(
$this->universalDiscoveryWidget = $universalDiscoveryWidget;
}

public function startCreatingContent(string $contentTypeName)
public function startCreatingContent(string $contentTypeName, string $language = null)
{
$this->contentActionsMenu->clickButton('Create content');
$this->contentTypePicker->verifyIsLoaded();
if ($language !== null) {
$this->contentTypePicker->selectLanguage($language);
}
$this->contentTypePicker->select($contentTypeName);
}

Expand Down

0 comments on commit e894d4e

Please sign in to comment.