Skip to content

Commit

Permalink
OP-326: Behat - adding page with multiple content elements
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jul 10, 2024
1 parent 726c73d commit 1192bb8
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 1 deletion.
13 changes: 13 additions & 0 deletions features/admin/adding_block.feature
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ Feature: Adding blocks
Then I should be notified that the block has been created
And I should see newly created "Single media" content element in Content elements section

@ui @javascript
Scenario: Adding block with multiple media content element
Given there is an existing media with names "Image 1" and "Image 2"
When I go to the create block page
And I fill the code with "intro"
And I fill the name with "Intro"
And I click on Add button in Content elements section
And I select "Multiple media" content element
And I add a multiple media content element with names "Image 1" and "Image 2"
And I add it
Then I should be notified that the block has been created
And I should see newly created "Single media" content element in Content elements section

@ui @javascript
Scenario: Adding block with heading content element
When I go to the create block page
Expand Down
39 changes: 39 additions & 0 deletions features/admin/adding_page.feature
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,42 @@ Feature: Adding new page
And I add it
Then I should be notified that the page has been created
And I should see newly created "Taxons list" content element in Content elements section

@ui @javascript
Scenario: Adding page with multiple content elements
Given there is an existing media with names "Image 1" and "Image 2"
And the store has "iPhone 8" and "iPhone X" products
And the store classifies its products as "Smartphones" and "Laptops"
When I go to the create page page
And I fill the code with "my_page"
And I fill the slug with "my_page"
And I fill the name with "My page"
And I click on Add button in Content elements section
And I select "Textarea" content element
And I add a textarea content element with "Welcome to our store" content
And I click on Add button in Content elements section
And I select "Single media" content element
And I add a single media content element with name "Image 1"
And I click on Add button in Content elements section
And I select "Multiple media" content element
And I add a multiple media content element with names "Image 1" and "Image 2"
And I click on Add button in Content elements section
And I select "Heading" content element
And I add a heading content element with type "H2" and "Welcome to our store" content
And I click on Add button in Content elements section
And I select "Products carousel" content element
And I add a products carousel content element with "iPhone 8" and "iPhone X" products
And I click on Add button in Content elements section
And I select "Products carousel by Taxon" content element
And I add a products carousel by taxon content element with "Smartphones" taxonomy
And I click on Add button in Content elements section
And I select "Taxons list" content element
And I add a taxons list content element with "Smartphones" and "Laptops" taxonomy
And I add it
Then I should be notified that the page has been created
And I should see newly created "Textarea" content element in Content elements section
And I should see newly created "Single media" content element in Content elements section
And I should see newly created "Multiple media" content element in Content elements section
And I should see newly created "Heading" content element in Content elements section
And I should see newly created "Products carousel" content element in Content elements section
And I should see newly created "Products carousel by Taxon" content element in Content elements section
4 changes: 3 additions & 1 deletion tests/Behat/Behaviour/ContainsContentElementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ public function containsContentElement(string $contentElement): bool
?? $this->getDocument()->findById('bitbag_sylius_cms_plugin_page_contentElements');

if (null === $contentElements) {
throw new \InvalidArgumentException('Content elements container not found');
throw new \InvalidArgumentException('Content elements container not found.');
}

// Autocomplete fields doesn't have labels directly above input field, so we can't use hasField method,
// so we need to check if input field with search class exists instead.
return $isAutocompleteField
? $contentElements->has('css', 'input.search')
: $contentElements->hasField($contentElement);
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 @@ -171,6 +171,14 @@ public function iAddASingleMediaContentElementWithName(string $name): void
$this->resolveCurrentPage()->addSingleMediaContentElementWithName($name);
}

/**
* @When I add a multiple media content element with names :firstMediaName and :secondMediaName
*/
public function iAddAMultipleMediaContentElementWithNames(string ...$mediaNames): void
{
$this->resolveCurrentPage()->addMultipleMediaContentElementWithNames($mediaNames);
}

/**
* @When I add a heading content element with type :type and :content content
*/
Expand Down
25 changes: 25 additions & 0 deletions tests/Behat/Page/Admin/Block/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,29 @@ public function addSingleMediaContentElementWithName(string $name): void
$item->click();
}

/**
* @throws ElementNotFoundException
*/
public function addMultipleMediaContentElementWithNames(array $mediaNames): void
{
$dropdown = $this->getElement('content_elements_multiple_media_dropdown');
$dropdown->click();

foreach ($mediaNames as $mediaName) {
$dropdown->waitFor(10, function () use ($mediaName): bool {
return $this->hasElement('content_elements_multiple_media_dropdown_item', [
'%item%' => $mediaName,
]);
});

$item = $this->getElement('content_elements_multiple_media_dropdown_item', [
'%item%' => $mediaName,
]);

$item->click();
}
}

/**
* @throws ElementNotFoundException
*/
Expand Down Expand Up @@ -232,6 +255,8 @@ protected function getDefinedElements(): array
'content_elements_textarea' => '.field > label:contains("Textarea") ~ textarea',
'content_elements_single_media_dropdown' => '.field > label:contains("Single media") ~ .bitbag-media-autocomplete',
'content_elements_single_media_dropdown_item' => '.field > label:contains("Single media") ~ .bitbag-media-autocomplete > div.menu > div.item:contains("%item%")',
'content_elements_multiple_media_dropdown' => '.field > label:contains("Multiple media") ~ .bitbag-media-autocomplete',
'content_elements_multiple_media_dropdown_item' => '.field > label:contains("Multiple media") ~ .bitbag-media-autocomplete > div.menu > div.item:contains("%item%")',
'content_elements_heading' => '.field > label:contains("Heading type") ~ select',
'content_elements_heading_content' => '.field > label:contains("Heading") ~ input[type="text"]',
'content_elements_products_carousel' => '.field > label:contains("Products") ~ .sylius-autocomplete',
Expand Down
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 @@ -37,6 +37,8 @@ public function addTextareaContentElementWithContent(string $content): void;

public function addSingleMediaContentElementWithName(string $name): void;

public function addMultipleMediaContentElementWithNames(array $mediaNames): void;

public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void;

public function addProductsCarouselContentElementWithProducts(array $productsNames): void;
Expand Down

0 comments on commit 1192bb8

Please sign in to comment.