Conversation
|
@egil @linkdotnet - start of this, not quite ready for review yet but just FYI. |
There was a problem hiding this comment.
Pull request overview
Adds text-based query APIs to bunit.web.query, enabling components to be searched by normalized text content (with options for selector scoping and string comparison), along with associated exceptions and test coverage.
Changes:
- Introduces
FindByText/FindAllByTextextension methods with whitespace normalization, selector filtering, and comparison options. - Adds
ByTextOptionsandTextNotFoundExceptionto support the new query API. - Adds a comprehensive
TextQueryExtensionsTestsuite covering core matching behavior and options.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/bunit.web.query.tests/Text/TextQueryExtensionsTest.cs | Adds unit tests validating text-query matching behavior and options. |
| src/bunit.web.query/Text/TextQueryExtensions.cs | Implements FindByText / FindAllByText with whitespace normalization and selector/comparison options. |
| src/bunit.web.query/Text/TextNotFoundException.cs | Adds exception thrown when FindByText cannot locate a matching element. |
| src/bunit.web.query/Text/ByTextOptions.cs | Adds options record for selector scoping and StringComparison behavior. |
| src/bunit.web.query/ByTextElementFactory.cs | Adds element wrapper factory so returned elements remain valid across re-renders. |
| var element = cut.FindByText("Hello World"); | ||
|
|
||
| element.ShouldNotBeNull(); | ||
| // The first matching element could be a parent or the first span | ||
| // depending on DOM structure - just verify we get a result |
There was a problem hiding this comment.
This test claims to verify that the first matching element is returned, but it only asserts that a non-null element is returned. To make the test meaningful and stable, constrain the selector (e.g., to the two spans) and assert which element is returned (e.g., by checking the id).
| var element = cut.FindByText("Hello World"); | |
| element.ShouldNotBeNull(); | |
| // The first matching element could be a parent or the first span | |
| // depending on DOM structure - just verify we get a result | |
| var element = cut.FindByText("Hello World", o => o.Selector = "span"); | |
| element.ShouldNotBeNull(); | |
| element.Id.ShouldBe("first"); |
|
|
||
| // Using "*" selector, the element could potentially match via multiple paths | ||
| // but should only appear once | ||
| var elements = cut.FindAllByText("Hello", o => o.Selector = "span"); |
There was a problem hiding this comment.
The comment says this test uses the "*" selector, but the test actually sets Selector = "span". Either update the comment or change the selector so the comment matches what’s being exercised.
| var elements = cut.FindAllByText("Hello", o => o.Selector = "span"); | |
| var elements = cut.FindAllByText("Hello", o => o.Selector = "*"); |
Pull request description
PR meta checklist
mainbranch for codeor targeted at
stablebranch for documentation that is live on bunit.dev.Code PR specific checklist