From 3fb17277e158ecc3c1f244fb21469e71ae77a511 Mon Sep 17 00:00:00 2001 From: Marek Rzytki Date: Wed, 5 Jun 2024 09:58:19 +0200 Subject: [PATCH] Start fixes on behat scenarios --- features/creating_new_wishlist.feature | 6 +-- features/editing_name_of_wishlist.feature | 6 +-- .../views/WishlistGroup/index.html.twig | 3 +- tests/Behat/Context/Ui/WishlistContext.php | 48 +++++++++++++++++++ tests/Behat/Page/Shop/Wishlist/IndexPage.php | 42 ++++++++++++++++ .../Page/Shop/Wishlist/IndexPageInterface.php | 11 +++++ 6 files changed, 109 insertions(+), 7 deletions(-) diff --git a/features/creating_new_wishlist.feature b/features/creating_new_wishlist.feature index 343942bc..da01406f 100644 --- a/features/creating_new_wishlist.feature +++ b/features/creating_new_wishlist.feature @@ -11,9 +11,9 @@ Feature: Creating a new wishlist @ui @javascript Scenario: Creating a new wishlist When I go to "/wishlists" - When I press "create_new_wishlist_button" - And I fill in "create_new_wishlist_name" with "WishlistName" - Then I press "create_new_wishlist_save" + When I open modal to create new wishlist + And I set new wishlist name "WishlistName" + Then I save new wishlist modal Then I should wait for one second Then I should be on "/wishlists" And I should have 1 wishlists diff --git a/features/editing_name_of_wishlist.feature b/features/editing_name_of_wishlist.feature index f477aed5..14ee5161 100644 --- a/features/editing_name_of_wishlist.feature +++ b/features/editing_name_of_wishlist.feature @@ -13,8 +13,8 @@ Feature: Editing wishlists name And the store has a wishlist named "Wishlist1" When I go to "/wishlists" Then I should see "Wishlist1" - When I press "wishlist-edit-button-Wishlist1" - And I fill in "edit_wishlist_name" with "Wishlist2" - When I press "edit_wishlist_save" + When I edit "Wishlist1" + And I edit wishlist name "Wishlist2" + When I save edit wishlist modal Then I go to "/wishlists" And I should see "Wishlist2" diff --git a/src/Resources/views/WishlistGroup/index.html.twig b/src/Resources/views/WishlistGroup/index.html.twig index f26694ee..0e7f237a 100644 --- a/src/Resources/views/WishlistGroup/index.html.twig +++ b/src/Resources/views/WishlistGroup/index.html.twig @@ -14,13 +14,14 @@
- diff --git a/tests/Behat/Context/Ui/WishlistContext.php b/tests/Behat/Context/Ui/WishlistContext.php index 0d79d9e9..c7914d13 100644 --- a/tests/Behat/Context/Ui/WishlistContext.php +++ b/tests/Behat/Context/Ui/WishlistContext.php @@ -88,6 +88,54 @@ public function iAddThisProductToSelectedWishlist(string $productName, string $w $this->wishlistPage->addProductToSelectedWishlist($productName, $wishlistName); } + /** + * @When I open modal to create new wishlist + */ + public function iOpenModalToCreateNewWishlist(): void + { + $this->wishlistIndexPage->addNewWishlist(); + } + + /** + * @When I set new wishlist name :wishlistName + */ + public function iSetNewWishlistName(string $wishlistName): void + { + $this->wishlistIndexPage->fillNewWishlistName($wishlistName); + } + + /** + * @When I save new wishlist modal + */ + public function iSaveNewWishlistModal(): void + { + $this->wishlistIndexPage->saveNewWishlist(); + } + + /** + * @When I edit wishlist name :wishlistName + */ + public function iEditWishlistName(string $wishlistName): void + { + $this->wishlistIndexPage->fillEditWishlistName($wishlistName); + } + + /** + * @When I edit :wishlistName + */ + public function iEditWishlist(string $wishlistName): void + { + $this->wishlistIndexPage->editWishlistName($wishlistName); + } + + /** + * @When I save edit wishlist modal + */ + public function iSaveEditWishlistModal(): void + { + $this->wishlistIndexPage->saveEditWishlist(); + } + /** * @Then I should have :productName in selected wishlists :wishlistName */ diff --git a/tests/Behat/Page/Shop/Wishlist/IndexPage.php b/tests/Behat/Page/Shop/Wishlist/IndexPage.php index f128f5b3..700ab7c2 100644 --- a/tests/Behat/Page/Shop/Wishlist/IndexPage.php +++ b/tests/Behat/Page/Shop/Wishlist/IndexPage.php @@ -19,4 +19,46 @@ public function getRouteName(): string { return 'bitbag_sylius_wishlist_plugin_shop_locale_wishlist_list_wishlists'; } + + public function addNewWishlist(): void + { + $this->getElement('add_new_wishlist')->click(); + } + + public function fillNewWishlistName(string $name): void + { + $this->getElement('new_wishlist_name')->setValue($name); + } + + public function saveNewWishlist(): void + { + $this->getElement('save_new_wishlist')->click(); + } + + public function editWishlistName(string $wishlistName): void + { + $this->getSession()->getPage()->find('css', '#wishlist-edit-button-' . $wishlistName)->click(); + } + + public function fillEditWishlistName(string $newWishlistName): void + { + $this->getElement('edit_wishlist_name_input')->setValue($newWishlistName); + } + + public function saveEditWishlist(): void + { + $this->getElement('save_edit_wishlist')->click(); + } + + protected function getDefinedElements(): array + { + return [ + 'add_new_wishlist' => '[data-test-wishlist-add-new-wishlist]', + 'new_wishlist_name' => '#create_new_wishlist_name', + 'save_new_wishlist' => '#create_new_wishlist_save', + 'edit_wishlist_name' => '[data-test-wishlist-wishlist-edit]', + 'edit_wishlist_name_input' => '#edit_wishlist_name', + 'save_edit_wishlist' => '#edit_wishlist_save', + ]; + } } diff --git a/tests/Behat/Page/Shop/Wishlist/IndexPageInterface.php b/tests/Behat/Page/Shop/Wishlist/IndexPageInterface.php index b9336baa..abab1922 100644 --- a/tests/Behat/Page/Shop/Wishlist/IndexPageInterface.php +++ b/tests/Behat/Page/Shop/Wishlist/IndexPageInterface.php @@ -15,4 +15,15 @@ interface IndexPageInterface extends SymfonyPageInterface { + public function addNewWishlist(): void; + + public function fillNewWishlistName(string $name): void; + + public function saveNewWishlist(): void; + + public function editWishlistName(string $wishlistName): void; + + public function fillEditWishlistName(string $newWishlistName): void; + + public function saveEditWishlist(): void; }