Skip to content

core: compare theme variants as an unordered set in assertTheme - #183

Merged
jcgueriaud1 merged 1 commit into
masterfrom
fix/theme-assertion-order
Sep 22, 2026
Merged

jcgueriaud1 merged 1 commit into
masterfrom
fix/theme-assertion-order

Conversation

@jcgueriaud1

@jcgueriaud1 jcgueriaud1 commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

assertTheme(...) matched the whole theme attribute as a raw string. Flow serializes every applied theme variant into that single attribute in an order it controls — not the order the variants were added — so the match is brittle:

Locator expected to have attribute 'theme'
Expected: small primary
Received: primary small

button.addThemeVariants(LUMO_PRIMARY, LUMO_SMALL) renders as small primary on Vaadin 25.3.0-beta1 and as primary small on 25.3.0-rc1, breaking ButtonViewIT.testHasThemeVariant. This PR is what unblocks the rc1 bump in #184.

Fix

assertTheme compares the variants as an unordered set: it builds a pattern with one anchored lookahead per expected variant plus a token count, so

  • assertTheme("small primary") and assertTheme("primary small") both pass,
  • an extra unexpected variant still fails (the count clause catches it),
  • Playwright's auto-retry and timeout behaviour are unchanged — it is still hasAttribute(name, Pattern).

The hand-rolled metacharacter escaping (Playwright compiles patterns into a JS RegExp, which does not understand Pattern.quote's \Q...\E) is factored into a shared escape() helper used by both the set pattern and the existing single-variant pattern. assertHasThemeVariant / assertHasNoThemeVariant are unchanged.

Also updated: the "Theme Variant Order" pitfall in AGENTS.md, the BadgeElement.md spec wording, the regenerated api-reference.md, and ButtonViewIT, which now asserts both orderings.

Testing

mvn verify on the current beta1: 717 tests, 0 failures. On rc1 (i.e. with #184 applied): 717 tests, 0 failures.

🤖 Generated with Claude Code

Flow serializes every applied theme variant into a single `theme`
attribute in an order it controls, not the order the variants were
added, so a whole-string match flips whenever that order changes:
addThemeVariants(LUMO_PRIMARY, LUMO_SMALL) renders as `primary small`,
failing assertTheme("small primary").

assertTheme now builds a pattern with one anchored lookahead per
expected variant plus a token count, so the variants may come in any
order while an extra unexpected variant still fails. Playwright's
auto-retry is unchanged — it is still a hasAttribute(name, Pattern)
assertion. The hand-rolled metacharacter escaping is shared with the
single-variant pattern.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jcgueriaud1
jcgueriaud1 merged commit c924308 into master Sep 22, 2026
3 checks passed
@jcgueriaud1
jcgueriaud1 deleted the fix/theme-assertion-order branch September 22, 2026 11:07
@jcgueriaud1 jcgueriaud1 changed the title core: compare theme variants as an unordered set in assertTheme build: upgrade Vaadin to 25.3.0-rc1, compare theme variants as an unordered set Sep 22, 2026
@jcgueriaud1 jcgueriaud1 changed the title build: upgrade Vaadin to 25.3.0-rc1, compare theme variants as an unordered set core: compare theme variants as an unordered set in assertTheme Sep 22, 2026
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.

1 participant