From 95bbe193d13c29572016fcd49bfeea5e4cdbbe34 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Wed, 30 Oct 2024 11:46:51 +1100 Subject: [PATCH] [#281] Updated `DraggableViewsTrait`. closes #281 --- MIGRATION.md | 5 +++ README.md | 2 +- src/DraggableViewsTrait.php | 4 +- tests/behat/features/draggableviews.feature | 44 +++++++++++---------- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 991f7a0..b813305 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -4,13 +4,18 @@ A migration map of the step definitions available in v2 to v3. | V2 | V3 | |------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **[`DraggableViewsTrait`](src/DraggableViewsTrait.php) ([example](tests/behat/features/draggableviews.feature))** | | +| `Then I save draggable views :view_id view :views_display_id display :bundle items in the following order:` | `When I save the draggable views items of the view :view_id and the display :views_display_id for the :bundle content in the following order:` | +|   | | | **[`ParagraphsTrait`](src/ParagraphsTrait.php) ([example](tests/behat/features/paragraphs.feature))** | | | `When :field_name in :bundle :entity_type with :entity_field_name of :entity_field_identifer has :paragraph_type paragraph:` | `Given the following fields for the paragraph :paragraph_type exist in the field :parent_field within the :parent_bundle :parent_entity_type identified by the field :parent_lookup_field and the value :parent_lookup_value:` | +|   | | | **[`PathTrait`](src/PathTrait.php) ([example](tests/behat/features/path.feature))** | | | `Then I should be in the :path path` | `Then the path should be :path` | | `Then I should not be in the :path path` | `Then the path should not be :path` | | `Then I :can visit :path with HTTP credentials :user :pass` | `Given the basic authentication with the username :username and the password :password` | | `When I visit :path then the final URL should be :alias` | Removed. Use `When I visit :path` and `Then the path should be :path` | +|   | | | **[`WaitTrait`](src/WaitTrait.php) ([example](tests/behat/features/wait.feature))** | | | `Then /^(?:\|I )wait (\d+) second(s?)$/` | `When I wait for :number second(s)` | | `Given I wait :timeout seconds for AJAX to finish` | `When I wait for :number second(s) for AJAX to finish` | diff --git a/README.md b/README.md index d92cce1..fefa382 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ For migration from v2 to v3, see [MIGRATION.md](MIGRATION.md). | `Then a cookie with( the) name containing :partial_name and value containing :partial_value should not exist` | Check if a cookie with a partial name and partial value does not exist. | |   | | | **[`DraggableViewsTrait`](src/DraggableViewsTrait.php) ([example](tests/behat/features/draggableviews.feature))** | | -| `Then I save draggable views :view_id view :views_display_id display :bundle items in the following order:` | Save the order of the draggable items. | +| `When I save the draggable views items of the view :view_id and the display :views_display_id for the :bundle content in the following order:` | Save the order of the draggable items. | |   | | | **[`EckTrait`](src/EckTrait.php) ([example](tests/behat/features/eck.feature))** | | | `Given :bundle :entity_type entities:` | Create ECK entities. | diff --git a/src/DraggableViewsTrait.php b/src/DraggableViewsTrait.php index a0a42a9..19dea97 100644 --- a/src/DraggableViewsTrait.php +++ b/src/DraggableViewsTrait.php @@ -22,7 +22,7 @@ trait DraggableViewsTrait { /** * Save order of the Draggable Order items. * - * @Then I save draggable views :view_id view :views_display_id display :bundle items in the following order: + * @When I save the draggable views items of the view :view_id and the display :views_display_id for the :bundle content in the following order: */ public function draggableViewsSaveBundleOrder(string $view_id, string $view_display_id, string $bundle, TableNode $order_table): void { $connection = Database::getConnection(); @@ -31,7 +31,7 @@ public function draggableViewsSaveBundleOrder(string $view_id, string $view_disp $node = $this->draggableViewsFindNode($bundle, ['title' => $title]); if (empty($node)) { - throw new \RuntimeException(sprintf('Unable to find node "%s"', $title)); + throw new \RuntimeException(sprintf('Unable to find the node "%s"', $title)); } $entity_id = $node->id(); diff --git a/tests/behat/features/draggableviews.feature b/tests/behat/features/draggableviews.feature index 1845496..2589abc 100644 --- a/tests/behat/features/draggableviews.feature +++ b/tests/behat/features/draggableviews.feature @@ -2,46 +2,50 @@ Feature: Check that DraggableViewsTrait works Scenario: Assert save order of the Draggable Order items - Given I am logged in as a user with the "administrator" role - Then "draggableviews_demo" content: + Given "draggableviews_demo" content: | title | status | created | | Test 1 | 1 | 2014-10-17 8:00am | | Test 2 | 1 | 2014-10-17 9:00am | - Then I visit "/draggableviews-demo" - Then I save screenshot + And I am logged in as a user with the "administrator" role + + When I visit "/draggableviews-demo" + And I save screenshot Then I should see an element ".view-draggableviews-demo .views-row:first-child .views-field-title" using "css" contains "Test 2" text - Then I should see an element ".view-draggableviews-demo .views-row:nth-child(2) .views-field-title" using "css" contains "Test 1" text - Then I save draggable views "draggableviews_demo" view "draggableviews_demo_order" display "draggableviews_demo" items in the following order: + And I should see an element ".view-draggableviews-demo .views-row:nth-child(2) .views-field-title" using "css" contains "Test 1" text + + When I save the draggable views items of the view "draggableviews_demo" and the display "draggableviews_demo_order" for the "draggableviews_demo" content in the following order: | Test 1 | | Test 2 | - # We should not need clear cache at here. Re-check later. - Then I visit "/admin/config/development/performance" - Then I press the "Clear all cache" button - Then I visit "/draggableviews-demo" + And the cache has been cleared + And I visit "/draggableviews-demo" Then I should see an element ".view-draggableviews-demo .views-row:first-child .views-field-title" using "css" contains "Test 1" text - Then I should see an element ".view-draggableviews-demo .views-row:nth-child(2) .views-field-title" using "css" contains "Test 2" text + And I should see an element ".view-draggableviews-demo .views-row:nth-child(2) .views-field-title" using "css" contains "Test 2" text - Then I save draggable views "draggableviews_demo" view "draggableviews_demo_order" display "draggableviews_demo" items in the following order: + When I save the draggable views items of the view "draggableviews_demo" and the display "draggableviews_demo_order" for the "draggableviews_demo" content in the following order: | Test 2 | | Test 1 | - # Clear cache again. - Then I visit "/admin/config/development/performance" - Then I press the "Clear all cache" button - Then I visit "/draggableviews-demo" + And the cache has been cleared + And I visit "/draggableviews-demo" Then I should see an element ".view-draggableviews-demo .views-row:first-child .views-field-title" using "css" contains "Test 2" text - Then I should see an element ".view-draggableviews-demo .views-row:nth-child(2) .views-field-title" using "css" contains "Test 1" text + And I should see an element ".view-draggableviews-demo .views-row:nth-child(2) .views-field-title" using "css" contains "Test 1" text @trait:DraggableViewsTrait - Scenario: Assert save order of the Draggable Order items throws an exception + Scenario: Assert that negative assertion for "When I save the draggable views items of the view :view_id and the display :views_display_id for the :bundle content in the following order:" step throws an exception Given some behat configuration And scenario steps: """ - Given I save draggable views "draggableviews_demo" view "draggableviews_demo_order" display "draggableviews_demo" items in the following order: + Given "draggableviews_demo" content: + | title | status | created | + | Test 1 | 1 | 2014-10-17 8:00am | + | Test 2 | 1 | 2014-10-17 9:00am | + And I am logged in as a user with the "administrator" role + When I save the draggable views items of the view "draggableviews_demo" and the display "draggableviews_demo_order" for the "draggableviews_demo" content in the following order: | Test 1 | | Test 2 | + | Test 3 | """ When I run "behat --no-colors" Then it should fail with an exception: """ - Unable to find node "Test 1" + Unable to find the node "Test 3" """