Skip to content

Commit

Permalink
OP-326: Behat for heading content element
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jul 9, 2024
1 parent eb610d5 commit 476deb9
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 0 deletions.
11 changes: 11 additions & 0 deletions features/admin/adding_block.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ Feature: Adding blocks
And I add it
Then I should be notified that the block has been created

@ui @javascript
Scenario: Adding block with heading 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 click on Add button in Content elements section
And I select "Heading" content element
And I add a heading content element with type "H3" and "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
25 changes: 25 additions & 0 deletions features/admin/adding_page.feature
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,28 @@ Feature: Adding new page
And I add a single media content element with name "Image 1"
And I add it
Then I should be notified that the page has been created

@ui @javascript
Scenario: Adding page with multiple media content element
Given there is an existing media with names "Image 1" and "Image 2"
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 "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 page has been created

@ui @javascript
Scenario: Adding page with heading content element
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 "Heading" content element
And I add a heading content element with type "H3" and "Welcome to our store" content
And I add it
Then I should be notified that the page has been created
14 changes: 14 additions & 0 deletions tests/Behat/Context/Setup/MediaContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ public function thereIsAnExistingTypeMediaWithCode(string $type, string $code):
$this->saveMedia($media);
}

/**
* @Given there is an existing media with names :firstMediaName and :secondMediaName
*/
public function thereIsExistingMediaWithNames(string ...$mediaNames): void
{
foreach ($mediaNames as $mediaName) {
$media = $this->createMedia(null, $mediaName);

$this->uploadFile($media, 'aston_martin_db_11.jpg');

$this->saveMedia($media);
}
}

private function createMedia(
?string $code = null,
?string $name = null,
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 heading content element with type :type and :content content
*/
public function iAddAHeadingContentElementWithTypeAndContent(string $type, string $content): void
{
$this->resolveCurrentPage()->addHeadingContentElementWithTypeAndContent($type, $content);
}

/**
* @Then I should see :content in the textarea content element
*/
Expand Down
16 changes: 16 additions & 0 deletions tests/Behat/Context/Ui/Admin/PageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ 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
*/
public function iAddAHeadingContentElementWithTypeAndContent(string $type, string $content): void
{
$this->resolveCurrentPage()->addHeadingContentElementWithTypeAndContent($type, $content);
}

/**
* @When I add it
* @When I try to add it
Expand Down
2 changes: 2 additions & 0 deletions tests/Behat/Helpers/ContentElementHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public static function getDefinedElementThatShouldAppearAfterSelectContentElemen
return match ($contentElement) {
'Textarea' => 'content_elements_textarea',
'Single media' => 'content_elements_single_media_dropdown',
'Multiple media' => 'content_elements_multiple_media_dropdown',
'Heading' => 'content_elements_heading',
default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $contentElement)),
};
}
Expand Down
14 changes: 14 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,18 @@ public function addSingleMediaContentElementWithName(string $name): void
$item->click();
}

/**
* @throws ElementNotFoundException
*/
public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void
{
$heading = $this->getElement('content_elements_heading');
$heading->selectOption($type);

$headingContent = $this->getElement('content_elements_heading_content');
$headingContent->setValue($content);
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
Expand All @@ -153,6 +165,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_heading' => '.field > label:contains("Heading type") ~ select',
'content_elements_heading_content' => '.field > label:contains("Heading") ~ input[type="text"]',
]);
}
}
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,5 +37,7 @@ public function addTextareaContentElementWithContent(string $content): void;

public function addSingleMediaContentElementWithName(string $name): void;

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

public function disable(): void;
}
39 changes: 39 additions & 0 deletions tests/Behat/Page/Admin/Page/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,41 @@ 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
*/
public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void
{
$heading = $this->getElement('content_elements_heading');
$heading->selectOption($type);

$headingContent = $this->getElement('content_elements_heading_content');
$headingContent->setValue($content);
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
Expand All @@ -163,6 +198,10 @@ 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"]',
]);
}
}
4 changes: 4 additions & 0 deletions tests/Behat/Page/Admin/Page/CreatePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ public function selectContentElement(string $contentElement): void;
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;
}

0 comments on commit 476deb9

Please sign in to comment.