Skip to content

core: fix BadgeElement text scope and move theme-variant asserts to mixin (#165) - #173

Merged
jcgueriaud1 merged 1 commit into
masterfrom
fix/165-badge-element-review-followups
Sep 7, 2026
Merged

jcgueriaud1 merged 1 commit into
masterfrom
fix/165-badge-element-review-followups

Conversation

@jcgueriaud1

Copy link
Copy Markdown
Collaborator

Fixes #165 — the four code findings from the review of #156.

1. assertText() / getText() no longer pick up slotted icon text

BadgeElement asserted on the host's full textContent, 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 host textContent == "Verified✓", so assertText("Verified") timed out and getText() returned "Verified✓".

getText() is now an override that evaluates over childNodes and keeps only nodes with no slot attribute — the > :not([slot]) convention CardElement.getContentLocator() already uses. assertText() compares against that.

2. getByText() Javadoc corrected

The Javadoc claimed the shadow-rendered number is excluded from the match, but Playwright's hasText filter uses the same shadow-traversing elementText as toHaveText, so getByText(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 HasThemeElement

Nothing in assertHasThemeVariant / assertHasNoThemeVariant / themeVariantPattern was Badge-specific — they work for any space-separated Vaadin theme attribute, and the 27 elements implementing HasThemeElement combine variants the same way. They are now default (and private static) members of the mixin.

The new ButtonViewIT.testHasThemeVariant shows why this mattered: addThemeVariants(LUMO_PRIMARY, LUMO_SMALL) renders as theme="small primary", so a whole-attribute assertTheme is order-sensitive in a way that isn't the order the variants were added.

4. assertNumber() reports expected/actual

assertNumber(9) against a badge showing 8 reported only TimeoutError: Timeout 30000ms exceeded while waiting for condition. The non-null case now uses assertThat(getLocator()).hasJSProperty("number", number) for Playwright's standard expected/received message; the null case asserts absence of has-number.

I confirmed the review's has-number claim against the 25.3.0-beta1 @vaadin/badge source before relying on it — willUpdate does this.toggleAttribute('has-number', this.number != null), i.e. exactly when number != null.

assertText() has to stay on waitForCondition (its value is computed, not a JS property), so its timeout is now wrapped in an AssertionError naming both the expected and the actual text.

5. GEMINI.md

Left to #147 as the issue directs.

Test coverage

New ITs:

  • BadgeViewIT.testTextExcludesIconSlotText — a Span("✓") icon, host textContent "Verified✓", own text "Verified" (fails on master)
  • BadgeViewIT.testGetByTextMatchesShadowNumber — getByText(page, "5") resolves to the numbered badge, not the one reading "5 minutes", pinning the newly documented behaviour
  • BadgeViewIT.testNumberMismatchReportsExpectedAndActual / testTextMismatchReportsExpectedAndActual — the failure message names both values
  • ButtonViewIT.testHasThemeVariant — the mixin off Badge

New 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.md regenerated.

🤖 Generated with Claude Code

…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>
@jcgueriaud1
jcgueriaud1 merged commit d74933c into master Sep 7, 2026
3 checks passed
@jcgueriaud1
jcgueriaud1 deleted the fix/165-badge-element-review-followups branch September 7, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BadgeElement review follow-ups: text assertions include slotted icon text, getByText Javadoc wrong, theme-variant helpers should be in HasThemeElement

1 participant