-
Notifications
You must be signed in to change notification settings - Fork 4k
[refactor][TextAlignment] Adds get_heading helper for tests and updates st_header_test to use this helper replacing index access.
#13033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
get_heading helper for tests and updates st_header_test to use this helper replacing index access.
67bc96f to
ea72594
Compare
fa062dd to
0fdcfd7
Compare
ea72594 to
a4fb6de
Compare
0fdcfd7 to
776e3f8
Compare
776e3f8 to
9e99e17
Compare
a4fb6de to
bdbdfb5
Compare
9e99e17 to
a57ef80
Compare
bdbdfb5 to
62f5988
Compare
a57ef80 to
da25075
Compare
62f5988 to
a0eca20
Compare
da25075 to
a7ddb15
Compare
a0eca20 to
1fac3bd
Compare
a7ddb15 to
0a9e0d3
Compare
1fac3bd to
3ea3a2d
Compare
0a9e0d3 to
a639656
Compare
3ea3a2d to
319b016
Compare
📉 Python coverage change detectedThe Python unit test coverage has decreased by 0.0099%
✅ Coverage change is within normal range. Coverage by files
|
319b016 to
9ca8e02
Compare
ec785ef to
2ac3d2c
Compare
lukasmasuch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 but two questions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the height difference here expected since we are using a different DOM element for the screenshot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was expecting this would change some of the snapshots but I was surprised that it made the snapshot smaller.
It looks like the reason is that there are some negative margins involved. The stHeader div is a bit shorter than the stMarkdownContainer which has this negative margin.
marginBottom: isLabel ? "" : `-${theme.spacing.lg}` // = -1rem = -16px
| The heading element container (stHeading). | ||
| """ | ||
| if isinstance(text_inside_heading, str): | ||
| text_inside_heading = re.compile(text_inside_heading) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be possible to just pass the text_inside_heading string to has_text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we could, this is just following the same pattern as the get_markdown function, is there a difference in requirements? I know the heading elements directly use the same markdown component. Do you remember the reason for adding this in get_markdown, it makes sense to me to handle them all the same way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will merge this for now, but can make another PR to change these and maybe also utilize re.escape() as suggested by Copilot which seems like it might be a good idea also if we continue to convert strings to regex expressions but could be applied to all of these helper functions in the same way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors e2e tests for heading elements to use a new get_heading helper function instead of index-based element access, making tests more robust and maintainable.
Key changes:
- Introduces
get_heading()helper inapp_utils.pyto locate heading elements by their text content - Updates
st_heading_test.pyto use text-based selectors viaget_heading()instead of.nth()index access - Adds explicit regex patterns where needed to avoid ambiguous matches (e.g., "header with help" vs "header with help and hidden anchor")
Reviewed Changes
Copilot reviewed 2 out of 14 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| e2e_playwright/shared/app_utils.py | Adds get_heading() helper function to find heading elements by text content using the stHeading test ID |
| e2e_playwright/st_heading_test.py | Refactors tests to use get_heading() with text-based selectors, adding regex patterns for exact matching and scroll_into_view_if_needed() for width tests |
| e2e_playwright/snapshots/linux/st_heading_test/st_subheader-width_300px[*].png | New snapshot files for subheader width tests (light/dark themes, chromium/firefox/webkit) |
| e2e_playwright/snapshots/linux/st_heading_test/st_header-width_400px[*].png | New snapshot files for header width tests (light/dark themes, chromium/firefox/webkit) |
| The heading element container (stHeading). | ||
| """ | ||
| if isinstance(text_inside_heading, str): | ||
| text_inside_heading = re.compile(text_inside_heading) |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The get_heading function converts string inputs to regex patterns automatically, but this can cause issues when the heading text contains regex special characters. For example, if a heading contains characters like ., *, +, ?, [, ], etc., they will be interpreted as regex metacharacters rather than literal text.
Consider using re.escape() when converting strings to patterns:
if isinstance(text_inside_heading, str):
text_inside_heading = re.compile(re.escape(text_inside_heading))This ensures that headings with special characters like "Price: $5.00" or "Question?" are matched literally.
| text_inside_heading = re.compile(text_inside_heading) | |
| text_inside_heading = re.compile(re.escape(text_inside_heading)) |
2ac3d2c to
cdb18b9
Compare

Describe your changes
Opportunistically replacing some index access tests with the newer pattern of using a helper
get_headerthat using the text in the heading element to find the correct element.GitHub Issue Link (if applicable)
Testing Plan
Test only.
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.