Skip to content

Commit

Permalink
OP-326: Behat single media
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jul 8, 2024
1 parent 5b9850d commit f74e4e1
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 deletions.
2 changes: 1 addition & 1 deletion features/admin/adding_block.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Feature: Adding blocks
Then I should be notified that the block has been created

@ui @javascript
Scenario: Adding block with content element
Scenario: Adding block with textarea content element
When I go to the create block page
And I fill the code with "intro"
And I fill the name with "Intro"
Expand Down
13 changes: 12 additions & 1 deletion features/admin/adding_page.feature
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,22 @@ Feature: Adding new page
Then I should be notified that the page has been created

@ui @javascript
Scenario: Adding page with content element
Scenario: Adding page with textarea 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 add a textarea content element with "Welcome to our store" content
And I add it
Then I should be notified that the page has been created

@ui @javascript
Scenario: Adding page with single media content element
Given there is an existing media with "image_1" code and name "Image 1"
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 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
12 changes: 12 additions & 0 deletions tests/Behat/Context/Setup/MediaContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ public function thereIsAnExistingMediaWithCode(string $code): void
$this->saveMedia($media);
}

/**
* @Given there is an existing media with :code code and name :name
*/
public function thereIsAnExistingMediaWithCodeAndName(string $code, string $name): void
{
$media = $this->createMedia($code, $name);

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

$this->saveMedia($media);
}

/**
* @Given there is an existing :type media with :code code
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/Behat/Context/Ui/Admin/PageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ public function iAddATextareaContentElementWithContent(string $content): void
$this->resolveCurrentPage()->addTextareaContentElementWithContent($content);
}

/**
* @When I add a single media content element with name :name
*/
public function iAddASingleMediaContentElementWithName(string $name): void
{
$this->resolveCurrentPage()->addSingleMediaContentElementWithName($name);
}

/**
* @When I add it
* @When I try to add it
Expand Down
40 changes: 40 additions & 0 deletions tests/Behat/Page/Admin/Page/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,54 @@ public function addTextareaContentElementWithContent(string $content): void
$textarea->setValue($content);
}

/**
* @throws ElementNotFoundException
*/
public function addSingleMediaContentElementWithName(string $name): 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_select_type');
});

$select = $this->getElement('content_elements_select_type');
$select->selectOption('Single media');

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

$dropdown = $this->getElement('content_elements_single_media_dropdown');
$dropdown->click();

$dropdown->waitFor(10, function () use ($name): bool {
return $this->hasElement('content_elements_single_media_dropdown_item', [
'%item%' => $name,
]);
});

$item = $this->getElement('content_elements_single_media_dropdown_item', [
'%item%' => $name,
]);

$item->click();
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'slug' => '#bitbag_sylius_cms_plugin_page_translations_en_US_slug',
'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' => '#bitbag_sylius_cms_plugin_page_contentElements a[data-form-collection="add"]',
'content_elements_select_type' => '.field > label:contains("Type") ~ select',
'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%")',
]);
}
}
2 changes: 2 additions & 0 deletions tests/Behat/Page/Admin/Page/CreatePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public function fillContent(string $content): void;
public function associateCollections(array $collectionsNames): void;

public function addTextareaContentElementWithContent(string $content): void;

public function addSingleMediaContentElementWithName(string $name): void;
}

0 comments on commit f74e4e1

Please sign in to comment.