Add create_item support to TypeaheadSelect fill method#120
Merged
digitronik merged 1 commit intoRedHatQE:mainfrom Apr 30, 2026
Merged
Add create_item support to TypeaheadSelect fill method#120digitronik merged 1 commit intoRedHatQE:mainfrom
digitronik merged 1 commit intoRedHatQE:mainfrom
Conversation
Reviewer's GuideExtends the Patternfly TypeaheadSelect widget to support an optional create_item flow in its fill method and adds corresponding tests and fixtures for a typeahead select with a create option. Sequence diagram for TypeaheadSelect fill with create_item supportsequenceDiagram
actor User
participant TypeaheadSelectWidget
participant Browser
User->>TypeaheadSelectWidget: fill(value, create_item)
TypeaheadSelectWidget->>TypeaheadSelectWidget: read()
alt value already filled
TypeaheadSelectWidget-->>User: return False
else value not filled
alt create_item is True and value not in items
TypeaheadSelectWidget->>TypeaheadSelectWidget: input.fill(value)
TypeaheadSelectWidget->>Browser: click(CREATE_ITEM_LOCATOR)
TypeaheadSelectWidget-->>User: return True
else create_item is False or value in items
TypeaheadSelectWidget->>TypeaheadSelectWidget: item_select(value)
TypeaheadSelectWidget-->>User: return True
end
end
Class diagram for updated BaseTypeaheadSelect and TypeaheadSelectclassDiagram
class BaseSelect
class Dropdown
class BaseTypeaheadSelect {
+BUTTON_LOCATOR
+CREATE_ITEM_LOCATOR
+input
+read()
+fill(value, create_item)
}
class TypeaheadSelect {
+DEFAULT_LOCATOR
}
BaseTypeaheadSelect --|> BaseSelect
TypeaheadSelect --|> BaseTypeaheadSelect
TypeaheadSelect --|> Dropdown
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- In
BaseTypeaheadSelect.fill, the click for the create option usesself.root_browser.click(self.CREATE_ITEM_LOCATOR), which bypasses the widget root; consider clicking relative toself.browserso this works correctly when multiple typeahead selects or non-unique IDs are present. - The early-return optimization in
fillonly checksself.read() == valueonce before branching, so whencreate_item=Trueand the value matches the current selection it still goes throughitem_selectand returnsTrue; consider reusing the samereadshort-circuit for thecreate_item=Truepath to avoid unnecessary interaction and keep return semantics consistent.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `BaseTypeaheadSelect.fill`, the click for the create option uses `self.root_browser.click(self.CREATE_ITEM_LOCATOR)`, which bypasses the widget root; consider clicking relative to `self.browser` so this works correctly when multiple typeahead selects or non-unique IDs are present.
- The early-return optimization in `fill` only checks `self.read() == value` once before branching, so when `create_item=True` and the value matches the current selection it still goes through `item_select` and returns `True`; consider reusing the same `read` short-circuit for the `create_item=True` path to avoid unnecessary interaction and keep return semantics consistent.
## Individual Comments
### Comment 1
<location path="src/widgetastic_patternfly5/components/menus/select.py" line_range="223" />
<code_context>
+
+ if create_item and value not in self.items:
+ self.input.fill(value)
+ self.root_browser.click(self.CREATE_ITEM_LOCATOR)
+ return True
+ else:
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `root_browser` with a relative locator may not respect the widget’s root context.
Because `CREATE_ITEM_LOCATOR` is a relative XPath, calling it on `root_browser` (which acts at page root) can match the wrong element when multiple typeahead widgets are present. Please call `click` on the widget-scoped browser (e.g. `self.browser.click(self.CREATE_ITEM_LOCATOR)`) so the locator is constrained to this instance.
</issue_to_address>
### Comment 2
<location path="testing/components/menus/test_select.py" line_range="181-182" />
<code_context>
+ yield view.typeahead_create_select
+
+
+def test_typeahead_create_select_new_item(typeahead_create_select):
+ """Test TypeaheadSelect with create_item option for creating new items."""
+ assert typeahead_create_select.is_displayed
+
+ # Selecting an existing item should work normally
+ typeahead_create_select.fill("Alabama")
+ assert typeahead_create_select.read() == "Alabama"
+ assert not typeahead_create_select.is_open
+
+ # Same value should report no change
+ assert typeahead_create_select.fill("Alabama") is False
+
+ # Non-existing value without create_item should raise
</code_context>
<issue_to_address>
**suggestion (testing):** Add a test case for `create_item=True` when the value is already selected
Since `read() == value` is checked before the `create_item` branch, calling `fill("Alabama", create_item=True)` should also return `False` when the value is already selected. Please add an assertion for this case (either in this test or a small dedicated one) to lock in that early-return behavior and prevent regressions.
```suggestion
# Same value should report no change
assert typeahead_create_select.fill("Alabama") is False
assert typeahead_create_select.fill("Alabama", create_item=True) is False
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #120 +/- ##
==========================================
+ Coverage 91.15% 91.19% +0.04%
==========================================
Files 38 38
Lines 2181 2191 +10
==========================================
+ Hits 1988 1998 +10
Misses 193 193
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Add support for creating new options via the TypeaheadSelect fill method and cover it with tests.
New Features:
Tests: