Skip to content

Commit

Permalink
IBX-5754: Behat tests for Taxonomy (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnocon authored Aug 25, 2023
1 parent 916f3fc commit b41e41c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/lib/Behat/BrowserContext/ContentActionsMenuContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ public function buttonIsNotVisible(string $buttonName): void
{
Assert::assertFalse($this->contentActionsMenu->isButtonVisible($buttonName));
}

/**
* @Given the :buttonName button is visible
*/
public function buttonIsVisible(string $buttonName): void
{
Assert::assertTrue($this->contentActionsMenu->isButtonVisible($buttonName));
}
}
8 changes: 8 additions & 0 deletions src/lib/Behat/BrowserContext/ContentUpdateContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public function iSetFields(TableNode $table): void
}
}

/**
* @When field :fieldName contains validation error :errorMessage
*/
public function fieldContainsValidationError(string $fieldName, string $errorMessage): void
{
$this->contentUpdateItemPage->verifyValidationMessage($fieldName, $errorMessage);
}

/**
* @Given the :fieldName field is noneditable
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Behat/Component/CreateNewPopup.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function specifyLocators(): array
{
return [
new VisibleCSSLocator('popupHeader', '.ibexa-extra-actions__header'),
new VisibleCSSLocator('addButton', '.ibexa-extra-actions__pre-form-btns .ibexa-btn--primary'),
new VisibleCSSLocator('addButton', '.ibexa-extra-actions__pre-form-btns .ibexa-btn--primary, .ibexa-extra-actions--create .ibexa-btn--primary'),
new VisibleCSSLocator('cancelButton', '.ibexa-extra-actions__pre-form-btns .ibexa-btn--secondary'),
new VisibleCSSLocator('popup', '.ibexa-extra-actions:not(.ibexa-extra-actions--hidden)'),
new VisibleCSSLocator('formGroup', '.form-group'),
Expand Down
8 changes: 8 additions & 0 deletions src/lib/Behat/Component/Fields/FieldTypeComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public function setValue(array $parameters): void
$this->getHTMLPage()->find($fieldSelector)->setValue($value);
}

public function verifyValidationMessage(string $expectedMessage): void
{
$this->getHTMLPage()
->find($this->parentLocator)
->find(new VisibleCSSLocator('validation', '.ibexa-form-error'))
->assert()->textEquals($expectedMessage);
}

public function getValue(): array
{
$fieldSelector = CSSLocatorBuilder::base($this->parentLocator)
Expand Down
10 changes: 10 additions & 0 deletions src/lib/Behat/Page/ContentUpdateItemPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
use Ibexa\Behat\Browser\Page\Page;
use Ibexa\Behat\Browser\Routing\Router;
use InvalidArgumentException;
use PHPUnit\Framework\Assert;

class ContentUpdateItemPage extends Page
Expand Down Expand Up @@ -100,6 +101,11 @@ public function close(): void
$this->getHTMLPage()->find($this->getLocator('closeButton'))->click();
}

public function verifyValidationMessage(string $fieldName, string $expectedMessage): void
{
$this->getField($fieldName)->verifyValidationMessage($expectedMessage);
}

protected function specifyLocators(): array
{
return [
Expand Down Expand Up @@ -167,6 +173,10 @@ public function getField(string $fieldName, ?int $fieldPosition = null): FieldTy
return $fieldTypeComponent;
}
}

throw new InvalidArgumentException(
sprintf('Could not handle field %s with field type identifier %s', $fieldName, $fieldTypeIdentifier)
);
}

protected function getFieldPosition(string $fieldName): int
Expand Down

0 comments on commit b41e41c

Please sign in to comment.