From f920295a45f2787022846ab46094b39554e4e0c3 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 19 Jun 2024 10:45:42 +1200 Subject: [PATCH] MNT Add behat test for elemental searchable fields --- tests/Behat/Context/FixtureContext.php | 27 +++++++++++++ .../searchable-dropdown-fields.feature | 39 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/Behat/features/searchable-dropdown-fields.feature diff --git a/tests/Behat/Context/FixtureContext.php b/tests/Behat/Context/FixtureContext.php index 564434bd..482f43b1 100644 --- a/tests/Behat/Context/FixtureContext.php +++ b/tests/Behat/Context/FixtureContext.php @@ -8,6 +8,8 @@ use SilverStripe\Core\ClassInfo; use SilverStripe\ORM\DB; use SilverStripe\ORM\Queries\SQLInsert; +use SilverStripe\FrameworkTest\Elemental\Model\ElementalSearchableFieldsBlock; +use SilverStripe\FrameworkTest\Elemental\Model\ElementalSearchableFieldsObject; /** * Context used to create fixtures in the SilverStripe ORM. @@ -44,6 +46,31 @@ public function theHasAContentElementWithContent($type, $pageTitle, $elementTitl } } + /** + * @Given /a "([^"]+)" "([^"]+)" with a "([^"]+)" searchable fields block/ + * + * @param string $pageTitle + * @param string $type + * @param string $elementTitle + */ + public function thePageHasASearchableFieldsBlock($type, $pageTitle, $elementTitle) + { + $elementalArea = $this->getElementalArea($type, $pageTitle); + $elementalArea->Elements()->add( + $this->getFixtureFactory()->createObject(ElementalSearchableFieldsBlock::class, $elementTitle) + ); + } + + /** + * @Given /a "([^"]+)" searchable fields object/ + * + * @param string $title + */ + public function thePageHasASearchableFieldsObject($title) + { + $this->getFixtureFactory()->createObject(ElementalSearchableFieldsObject::class, $title); + } + /** * @Given /(?:the|a) "([^"]+)" "([^"]+)" (?:with|has) a broken element named "([^"]+)"/ */ diff --git a/tests/Behat/features/searchable-dropdown-fields.feature b/tests/Behat/features/searchable-dropdown-fields.feature new file mode 100644 index 00000000..15dfb462 --- /dev/null +++ b/tests/Behat/features/searchable-dropdown-fields.feature @@ -0,0 +1,39 @@ +@javascript +Feature: Searchable fields + As a CMS user + I want searchable dropdown fields to function when used in a content block + So that I can continue to update my content + + Background: + Given I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class + And a "page" "Blocks Page" with a "My block" searchable fields block + And a "test-1" searchable fields object + And a "test-2" searchable fields object + And a "test-3" searchable fields object + Given the "group" "EDITOR" has permissions "Access to 'Pages' section" + And I am logged in as a member of "EDITOR" group + And I go to "/admin/pages" + And I left click on "Blocks Page" in the tree + When I see a list of blocks + Then I should see "My block" + When I click on block 1 + + Scenario: I can use lazy-loaded searchable dropdown fields + When I click on the "#Form_ElementForm_1_PageElements_1_ElementalSearchableFieldsObjectID .ss-searchable-dropdown-field__value-container" element + And I type "test-1" in the field + And I wait 2 seconds + And I press the "Enter" key globally + When I click on the "#Form_ElementForm_1_PageElements_1_ElementalSearchableFieldsObjects .ss-searchable-dropdown-field__value-container" element + And I type "test-2" in the field + And I wait 2 seconds + And I press the "Enter" key globally + And I type "test-3" in the field + And I wait 2 seconds + And I press the "Enter" key globally + When I press the "View actions" button + And I press the "Save" button + And I wait 1 second + Then I should see a "Saved 'My block' successfully" success toast + And I should see "test-1" + And I should see "test-2" + And I should see "test-3"