Skip to content

Commit

Permalink
OP-322: Behat adding block with content element
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jul 2, 2024
1 parent 7ea48ee commit 6b0664e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions features/admin/adding_block.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ Feature: Adding blocks
And I add it
Then I should be notified that the block has been created

@ui @javascript
Scenario: Adding block with content element
When I go to the create block page
And I fill the code with "intro"
And I fill the name with "Intro"
And I add a textarea content element with "Welcome to our store" content
And I add it
Then I should be notified that the block has been created

@ui
Scenario: Trying to add block with existing code
Given there is an existing block with "homepage_image" code
Expand Down
8 changes: 8 additions & 0 deletions tests/Behat/Context/Ui/Admin/BlockContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ public function iAddAndCollectionsToIt(string ...$collectionsNames): void
$this->resolveCurrentPage()->associateCollections($collectionsNames);
}

/**
* @When I add a textarea content element with :content content
*/
public function iAddATextareaContentElementWithContent(string $content): void
{
$this->resolveCurrentPage()->addTextareaContentElementWithContent($content);
}

/**
* @When I add it
* @When I try to add it
Expand Down
21 changes: 21 additions & 0 deletions tests/Behat/Page/Admin/Block/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Tests\BitBag\SyliusCmsPlugin\Behat\Page\Admin\Block;

use Behat\Mink\Exception\ElementNotFoundException;
use DMore\ChromeDriver\ChromeDriver;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorTrait;
Expand Down Expand Up @@ -78,11 +79,31 @@ public function associateCollections(array $collectionsNames): void
}
}

/**
* @throws ElementNotFoundException
*/
public function addTextareaContentElementWithContent(string $content): void
{
Assert::isInstanceOf($this->getDriver(), ChromeDriver::class);

$addButton = $this->getElement('content_elements_add_button');
$addButton->click();

$addButton->waitFor(3, function (): bool {
return $this->hasElement('content_elements_textarea');
});

$textarea = $this->getElement('content_elements_textarea');
$textarea->setValue($content);
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'association_dropdown_collection' => '.field > label:contains("Collections") ~ .sylius-autocomplete',
'association_dropdown_collection_item' => '.field > label:contains("Collections") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")',
'content_elements_add_button' => 'h4:contains("Content elements") .field a[data-form-collection="add"]',
'content_elements_textarea' => '.field > label:contains("Textarea") ~ textarea',
]);
}
}
2 changes: 2 additions & 0 deletions tests/Behat/Page/Admin/Block/CreatePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ public function fillContent(string $content): void;

public function associateCollections(array $collectionsNames): void;

public function addTextareaContentElementWithContent(string $content): void;

public function disable(): void;
}

0 comments on commit 6b0664e

Please sign in to comment.