Repository navigation
core: fix BadgeElement text scope and move theme-variant asserts to mixin (#165) - #173
Merged
Merged
Conversation
…ixin (#165) Four review follow-ups on BadgeElement: 1. `getText()` / `assertText()` asserted on the host's full `textContent`, which includes light-DOM text from the `icon` slot, contradicting the Javadoc. `new Badge("Verified", new Span("✓"))` gave the host `textContent == "Verified✓"`, so `assertText("Verified")` timed out. `getText()` is now an override reading only the child nodes that carry no `slot` attribute, following `CardElement`'s `> :not([slot])` convention. 2. `getByText()` documented that the shadow-rendered `number` is excluded from the match, but Playwright's `hasText` filter uses the same shadow-traversing text as `toHaveText`, so `getByText(page, "5")` matches a badge whose only "5" is its number. A light-DOM-only filter is not expressible as a locator, so the Javadoc now states the number *is* matched and says to pass some of the badge's own text. 3. `assertHasThemeVariant` / `assertHasNoThemeVariant` / `themeVariantPattern` were Badge-only but nothing in them is Badge-specific: they work for any space-separated Vaadin `theme` attribute, and the 27 elements implementing `HasThemeElement` combine variants the same way. Moved to `HasThemeElement` as default (and private static) members. 4. `assertNumber()` used `page.waitForCondition()`, so a mismatch surfaced as a bare timeout with no expected/actual. It now uses `hasJSProperty("number", number)` for the non-null case, and asserts absence of `has-number` for null — the 25.3 `vaadin-badge` toggles that attribute exactly when `number != null`. `assertText()` must stay on `waitForCondition` (the value is computed), so its timeout is wrapped in an AssertionError naming both the expected and the actual text. Also adds a `ButtonElement` theme-variant test, which shows why the mixin was needed: `addThemeVariants(LUMO_PRIMARY, LUMO_SMALL)` renders as `theme="small primary"`, so a whole-attribute `assertTheme` is order-sensitive. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Fixes #165 — the four code findings from the review of #156.
1.
assertText()/getText()no longer pick up slotted icon textBadgeElementasserted on the host's fulltextContent, but the Javadoc promised "only the badge's own text content". Any icon that renders a glyph in the light DOM broke that:new Badge("Verified", new Span("✓"))gives the hosttextContent == "Verified✓", soassertText("Verified")timed out andgetText()returned"Verified✓".getText()is now an override that evaluates overchildNodesand keeps only nodes with noslotattribute — the> :not([slot])conventionCardElement.getContentLocator()already uses.assertText()compares against that.2.
getByText()Javadoc correctedThe Javadoc claimed the shadow-rendered
numberis excluded from the match, but Playwright'shasTextfilter uses the same shadow-traversingelementTextastoHaveText, sogetByText(page, "5")matches a badge whose only "5" is its number.A light-DOM-only filter isn't expressible as a Playwright locator, so I took the other option the issue offers: the Javadoc now states the number is part of the matched text, with the concrete example, and advises passing some of the badge's own text.
3. Theme-variant helpers moved to
HasThemeElementNothing in
assertHasThemeVariant/assertHasNoThemeVariant/themeVariantPatternwas Badge-specific — they work for any space-separated Vaadinthemeattribute, and the 27 elements implementingHasThemeElementcombine variants the same way. They are now default (and private static) members of the mixin.The new
ButtonViewIT.testHasThemeVariantshows why this mattered:addThemeVariants(LUMO_PRIMARY, LUMO_SMALL)renders astheme="small primary", so a whole-attributeassertThemeis order-sensitive in a way that isn't the order the variants were added.4.
assertNumber()reports expected/actualassertNumber(9)against a badge showing8reported onlyTimeoutError: Timeout 30000ms exceeded while waiting for condition. The non-null case now usesassertThat(getLocator()).hasJSProperty("number", number)for Playwright's standard expected/received message; thenullcase asserts absence ofhas-number.I confirmed the review's
has-numberclaim against the 25.3.0-beta1@vaadin/badgesource before relying on it —willUpdatedoesthis.toggleAttribute('has-number', this.number != null), i.e. exactly whennumber != null.assertText()has to stay onwaitForCondition(its value is computed, not a JS property), so its timeout is now wrapped in anAssertionErrornaming both the expected and the actual text.5.
GEMINI.mdLeft to #147 as the issue directs.
Test coverage
New ITs:
BadgeViewIT.testTextExcludesIconSlotText— aSpan("✓")icon, hosttextContent"Verified✓", own text"Verified"(fails onmaster)BadgeViewIT.testGetByTextMatchesShadowNumber—getByText(page, "5")resolves to the numbered badge, not the one reading "5 minutes", pinning the newly documented behaviourBadgeViewIT.testNumberMismatchReportsExpectedAndActual/testTextMismatchReportsExpectedAndActual— the failure message names both valuesButtonViewIT.testHasThemeVariant— the mixin off BadgeNew test-UI fixtures:
#badge-with-text-icon,#badge-minutes, and a combined-variants button.Full suite: 671 tests, 0 failures (
./mvnw -Pit verify).api-reference.mdregenerated.🤖 Generated with Claude Code