Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#281] Updated DraggableViewsTrait. #307

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
4 changes: 2 additions & 2 deletions src/DraggableViewsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
44 changes: 24 additions & 20 deletions tests/behat/features/draggableviews.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"""