Skip to content
Open
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
29 changes: 29 additions & 0 deletions STEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ Then the element ".visually-hidden" should not be displayed within a viewport
> - Set field values for various input types including selects and WYSIWYG.
> - Assert field existence, state, and selected options.
> - Support for specialized widgets like color pickers and rich text editors.
> - Support for datetime field widgets with date, time, and datetime options.


<details>
Expand Down Expand Up @@ -511,6 +512,34 @@ When I fill in the WYSIWYG field "edit-body-0-value" with the "<p>This is a <str

</details>

<details>
<summary><code>@When I fill in the datetime field :label with date :date and time :time</code></summary>

<br/>
Fill a datetime field with both date and time values
<br/><br/>

```gherkin
When I fill in the datetime field "Event datetime" with date "2024-07-15" and time "14:30:00"

```

</details>

<details>
<summary><code>@When I fill in the date field :label with date :date</code></summary>

<br/>
Fill a datetime field with date value
<br/><br/>

```gherkin
When I fill in the date field "Event datetime" with date "2024-07-15"

```

</details>

<details>
<summary><code>@When I check the checkbox :selector</code></summary>

Expand Down
56 changes: 56 additions & 0 deletions src/FieldTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* - Set field values for various input types including selects and WYSIWYG.
* - Assert field existence, state, and selected options.
* - Support for specialized widgets like color pickers and rich text editors.
* - Support for datetime field widgets with date, time, and datetime options.
*/
trait FieldTrait {

Expand Down Expand Up @@ -207,6 +208,61 @@
");
}

/**
* Fill a datetime field with both date and time values.
*
* @code
* When I fill in the datetime field "Event datetime" with date "2024-07-15" and time "14:30:00"
* @endcode
*
* @When I fill in the datetime field :label with date :date and time :time
*/
public function fieldFillDateTime(string $label, string $date, string $time): void {
$this->fieldFillDateTimeField($label, 'date', $date);
$this->fieldFillDateTimeField($label, 'time', $time);
}

/**
* Fill a datetime field with date value.
*
* @code
* When I fill in the date field "Event datetime" with date "2024-07-15"
* @endcode
*
* @When I fill in the date field :label with date :date
*/
public function fieldFillDate(string $label, string $date): void {
$this->fieldFillDateTimeField($label, 'date', $date);
}

/**
* Helper method to fill datetime field components.
*
* @param string $label
* The field label.
* @param string $field
* The field component: 'date' or 'time'.
* @param string $value
* The value to set.
*
* @throws \Exception
* If the field is not found.
*/
protected function fieldFillDateTimeField(string $label, string $field, string $value): void {
$xpath = sprintf(
'//*[self::span or self::label or self::h4][contains(normalize-space(.), "%s")]/ancestor::div[contains(@class,"form-item") or contains(@class,"field--widget-datetime-default")]//input[contains(@name,"[%s]")]',
$label,
$field
);

$page = $this->getSession()->getPage();
$element = $page->find('xpath', $xpath);
if (!$element) {
throw new \Exception(sprintf('Date field with label "%s" value not found', $label));

Check warning on line 261 in src/FieldTrait.php

View check run for this annotation

Codecov / codecov/patch

src/FieldTrait.php#L261

Added line #L261 was not covered by tests
}
Comment on lines +261 to +262
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Error message could be more specific.

The error message only mentions "Date field" even when the method might be looking for a time input element.

Consider making the error message reflect the actual field type being searched:

-      throw new \Exception(sprintf('Date field with label "%s" value not found', $label));
+      throw new \Exception(sprintf('%s field with label "%s" value not found', ucfirst($field), $label));

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/FieldTrait.php around lines 251 to 252, the error message always refers
to a "Date field" even when the method might be searching for a time input
element. Modify the error message to dynamically include the actual field type
being searched for, such as "Date field" or "Time field," to make the error more
specific and informative.

$element->setValue($value);
}
Comment on lines +238 to +264
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Helper method implementation is solid but could use additional validation.

The fieldFillDateTimeField helper method effectively handles the task of locating and filling datetime input fields. Consider adding validation for the $field parameter to ensure it only accepts 'date' or 'time' values.

 protected function fieldFillDateTimeField(string $label, string $field, string $value): void {
+    // Validate that field is either 'date' or 'time'
+    if (!in_array($field, ['date', 'time'])) {
+      throw new \InvalidArgumentException(sprintf('Invalid field type "%s". Expected "date" or "time".', $field));
+    }
+
     $xpath = sprintf(
       '//*[self::span or self::label or self::h4][contains(normalize-space(.), "%s")]/ancestor::div[contains(@class,"form-item") or contains(@class,"field--widget-datetime-default")]//input[contains(@name,"[%s]")]',
       $label,
       $field
     );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Helper method to fill datetime field components.
*
* @param string $label
* The field label.
* @param string $field
* The field component: 'date' or 'time'.
* @param string $value
* The value to set.
*
* @throws \Exception
* If the field is not found.
*/
protected function fieldFillDateTimeField(string $label, string $field, string $value): void {
$xpath = sprintf(
'//*[self::span or self::label or self::h4][contains(normalize-space(.), "%s")]/ancestor::div[contains(@class,"form-item") or contains(@class,"field--widget-datetime-default")]//input[contains(@name,"[%s]")]',
$label,
$field
);
$page = $this->getSession()->getPage();
$element = $page->find('xpath', $xpath);
if (!$element) {
throw new \Exception(sprintf('Date field with label "%s" value not found', $label));
}
$element->setValue($value);
}
/**
* Helper method to fill datetime field components.
*
* @param string $label
* The field label.
* @param string $field
* The field component: 'date' or 'time'.
* @param string $value
* The value to set.
*
* @throws \Exception
* If the field is not found.
*/
protected function fieldFillDateTimeField(string $label, string $field, string $value): void {
// Validate that field is either 'date' or 'time'
if (!in_array($field, ['date', 'time'])) {
throw new \InvalidArgumentException(
sprintf('Invalid field type "%s". Expected "date" or "time".', $field)
);
}
$xpath = sprintf(
'//*[self::span or self::label or self::h4][contains(normalize-space(.), "%s")]/ancestor::div[contains(@class,"form-item") or contains(@class,"field--widget-datetime-default")]//input[contains(@name,"[%s]")]',
$label,
$field
);
$page = $this->getSession()->getPage();
$element = $page->find('xpath', $xpath);
if (!$element) {
throw new \Exception(sprintf('Date field with label "%s" value not found', $label));
}
$element->setValue($value);
}
🤖 Prompt for AI Agents
In src/FieldTrait.php between lines 238 and 264, the method
fieldFillDateTimeField accepts a $field parameter but does not validate its
value. Add validation to ensure $field is either 'date' or 'time' before
proceeding. If $field is invalid, throw an exception with a clear message. This
prevents incorrect usage and potential errors in XPath construction.


/**
* Assert that a select has an option.
*
Expand Down
30 changes: 30 additions & 0 deletions tests/behat/features/field_datetime.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Feature: Check that datetime fields are handled correctly in FieldTrait
As a Behat Steps library developer
I want to provide tools to interact with datetime fields
So that users can set date, time, or both values in their tests

@api @datetime
Scenario: Set both date and time values on a datetime field
Given I am logged in as a user with the "administrator" role
When I go to "node/add/article"
And I fill in "Title" with "[TEST] Article with datetime field"
And I fill in the datetime field "Date and time" with date "2024-03-15" and time "14:30:00"
And I select "Published" from "edit-moderation-state-0-state"
And I press "Save"
Then the response status code should be 200
And I should see the text "[TEST] Article with datetime field"
And I should see the text "Date and time"
And I should see the text "03/15/2024 - 14:30"

@api @datetime
Scenario: Set date value on a date field
Given I am logged in as a user with the "administrator" role
When I go to "node/add/article"
And I fill in "Title" with "[TEST] Article with datetime field"
And I fill in the date field "Date only" with date "2024-03-15"
And I select "Published" from "edit-moderation-state-0-state"
And I press "Save"
Then the response status code should be 200
And I should see the text "[TEST] Article with datetime field"
And I should see the text "Date"
And I should see the text "03/15/2024"
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ dependencies:
config:
- field.field.node.article.body
- field.field.node.article.comment
- field.field.node.article.field_date_and_time
- field.field.node.article.field_date_only
- field.field.node.article.field_file
- field.field.node.article.field_image
- field.field.node.article.field_tags
Expand All @@ -14,6 +16,7 @@ dependencies:
module:
- comment
- content_moderation
- datetime
- file
- image
- path
Expand Down Expand Up @@ -47,6 +50,18 @@ content:
region: content
settings: { }
third_party_settings: { }
field_date_and_time:
type: datetime_default
weight: 26
region: content
settings: { }
third_party_settings: { }
field_date_only:
type: datetime_default
weight: 27
region: content
settings: { }
third_party_settings: { }
field_file:
type: file_generic
weight: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ dependencies:
- core.entity_view_display.comment.comment.default
- field.field.node.article.body
- field.field.node.article.comment
- field.field.node.article.field_date_and_time
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Validate configuration dependencies for field storage.

The new view display adds a dependency on the field config field.field.node.article.field_date_and_time but omits the required field storage config field.storage.node.field_date_and_time. Without this, importing the configuration may fail.

Apply this diff to add the storage dependency:

 dependencies:
   config:
     - core.entity_view_display.comment.comment.default
     - field.field.node.article.body
     - field.field.node.article.comment
+    - field.storage.node.field_date_and_time
     - field.field.node.article.field_date_and_time
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- field.field.node.article.field_date_and_time
dependencies:
config:
- core.entity_view_display.comment.comment.default
- field.field.node.article.body
- field.field.node.article.comment
- field.storage.node.field_date_and_time
- field.field.node.article.field_date_and_time
🤖 Prompt for AI Agents
In
tests/behat/fixtures/d10/config/sync/core.entity_view_display.node.article.default.yml
at line 9, the configuration dependencies are missing the required field storage
config 'field.storage.node.field_date_and_time'. Add this field storage
dependency alongside the existing field config dependency to ensure proper
configuration import and avoid failures.

- field.field.node.article.field_date_only
Comment on lines +9 to +10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add missing storage dependencies for datetime fields.
Configuration import may fail without including the corresponding storage dependencies. Please add:

     dependencies:
       config:
         - field.field.node.article.field_date_and_time
+        - field.storage.node.field_date_and_time
         - field.field.node.article.field_date_only
+        - field.storage.node.field_date_only
🤖 Prompt for AI Agents
In
tests/behat/fixtures/d10/config/sync/core.entity_view_display.node.article.default.yml
around lines 9 to 10, the configuration is missing storage dependencies for the
datetime fields field_date_and_time and field_date_only. Add these storage
dependencies explicitly to ensure the configuration import succeeds without
errors related to missing dependencies.

- field.field.node.article.field_file
- field.field.node.article.field_image
- field.field.node.article.field_tags
- image.style.wide
- node.type.article
module:
- comment
- datetime
- file
- image
- text
Expand Down Expand Up @@ -45,6 +48,24 @@ content:
third_party_settings: { }
weight: 0
region: content
field_date_and_time:
type: datetime_default
label: above
settings:
timezone_override: ''
format_type: medium
third_party_settings: { }
weight: 7
region: content
Comment on lines +51 to +59
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Review view display settings for the datetime field.

The field_date_and_time display entry is correctly configured, but you may consider:

  1. Omitting the empty timezone_override: '' if you don’t intend to override the default site timezone.
  2. Removing the empty third_party_settings: {} for brevity.
  3. Verifying that weight: 7 places the field in the intended order relative to other content.
@@ content:
-  field_date_and_time:
-    type: datetime_default
-    label: above
-    settings:
-      timezone_override: ''
-      format_type: medium
-    third_party_settings: {  }
-    weight: 7
-    region: content
+  field_date_and_time:
+    type: datetime_default
+    label: above
+    settings:
+      format_type: medium
+    weight: 7   # ensure this ordering matches UX requirements
+    region: content
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
field_date_and_time:
type: datetime_default
label: above
settings:
timezone_override: ''
format_type: medium
third_party_settings: { }
weight: 7
region: content
field_date_and_time:
type: datetime_default
label: above
settings:
format_type: medium
weight: 7 # ensure this ordering matches UX requirements
region: content
🤖 Prompt for AI Agents
In
tests/behat/fixtures/d10/config/sync/core.entity_view_display.node.article.default.yml
around lines 50 to 58, the datetime field display settings include an empty
timezone_override and an empty third_party_settings object, which are
unnecessary. Remove the empty timezone_override line and the empty
third_party_settings entry to clean up the configuration. Also, double-check
that the weight value of 7 correctly positions the field in the desired display
order relative to other fields.

field_date_only:
type: datetime_default
label: above
settings:
timezone_override: ''
format_type: medium
third_party_settings: { }
weight: 8
region: content
Comment on lines +60 to +68
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Cleanup unnecessary empty settings.
Similarly, for field_date_only, remove empty timezone_override and third_party_settings:

   field_date_only:
-    settings:
-      timezone_override: ''
-      format_type: medium
-    third_party_settings: {  }
+    settings:
+      format_type: medium
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
field_date_only:
type: datetime_default
label: above
settings:
timezone_override: ''
format_type: medium
third_party_settings: { }
weight: 8
region: content
field_date_only:
type: datetime_default
label: above
settings:
format_type: medium
weight: 8
region: content
🤖 Prompt for AI Agents
In
tests/behat/fixtures/d10/config/sync/core.entity_view_display.node.article.default.yml
around lines 60 to 68, remove the empty settings 'timezone_override' under
'settings' and the empty 'third_party_settings' key from the 'field_date_only'
configuration to clean up unnecessary empty values.

field_file:
type: file_default
label: above
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ dependencies:
- core.entity_view_mode.node.rss
- field.field.node.article.body
- field.field.node.article.comment
- field.field.node.article.field_date_and_time
- field.field.node.article.field_date_only
- field.field.node.article.field_file
- field.field.node.article.field_image
- field.field.node.article.field_tags
- node.type.article
Expand All @@ -29,6 +32,8 @@ content:
hidden:
body: true
comment: true
field_date_and_time: true
field_date_only: true
field_file: true
field_image: true
field_tags: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ dependencies:
- core.entity_view_mode.node.search_index
- field.field.node.article.body
- field.field.node.article.comment
- field.field.node.article.field_date_and_time
- field.field.node.article.field_date_only
- field.field.node.article.field_file
- field.field.node.article.field_image
- field.field.node.article.field_tags
Expand Down Expand Up @@ -51,6 +53,8 @@ content:
weight: 1
region: content
hidden:
field_date_and_time: true
field_date_only: true
field_file: true
field_image: true
links: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ dependencies:
- core.entity_view_mode.node.search_result
- field.field.node.article.body
- field.field.node.article.comment
- field.field.node.article.field_date_and_time
- field.field.node.article.field_date_only
- field.field.node.article.field_file
- field.field.node.article.field_image
- field.field.node.article.field_tags
Expand Down Expand Up @@ -53,6 +55,8 @@ content:
region: content
hidden:
comment: true
field_date_and_time: true
field_date_only: true
field_file: true
field_tags: true
search_api_excerpt: true
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ dependencies:
- core.entity_view_mode.node.teaser
- field.field.node.article.body
- field.field.node.article.comment
- field.field.node.article.field_date_and_time
- field.field.node.article.field_date_only
- field.field.node.article.field_file
- field.field.node.article.field_image
- field.field.node.article.field_tags
- image.style.medium
Expand Down Expand Up @@ -58,6 +61,8 @@ content:
region: content
hidden:
comment: true
field_date_and_time: true
field_date_only: true
field_file: true
field_image: true
field_tags: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
uuid: 330488f2-c295-406b-8c67-1b979f1d41ec
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_date_and_time
- node.type.article
module:
- datetime
id: node.article.field_date_and_time
field_name: field_date_and_time
entity_type: node
bundle: article
label: 'Date and time'
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: datetime
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
uuid: 60dc4216-4910-400f-bb93-e66186384875
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_date_only
- node.type.article
module:
- datetime
id: node.article.field_date_only
field_name: field_date_only
entity_type: node
bundle: article
label: 'Date only'
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: datetime
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
uuid: 8c4bc0be-50c6-4722-b3a3-087e28686c89
langcode: en
status: true
dependencies:
module:
- datetime
- node
id: node.field_date_and_time
field_name: field_date_and_time
entity_type: node
type: datetime
settings:
datetime_type: datetime
module: datetime
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
uuid: 7d5ec932-bb3f-4e6b-b4bb-1a703177286c
langcode: en
status: true
dependencies:
module:
- datetime
- node
id: node.field_date_only
field_name: field_date_only
entity_type: node
type: datetime
settings:
datetime_type: date
module: datetime
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Loading