Skip to content

test(widgets): TextSubstringHighlighting (+6 tests)#376

Merged
TaprootFreak merged 1 commit into
developfrom
test/text-substring-highlighting
May 15, 2026
Merged

test(widgets): TextSubstringHighlighting (+6 tests)#376
TaprootFreak merged 1 commit into
developfrom
test/text-substring-highlighting

Conversation

@TaprootFreak

Copy link
Copy Markdown
Contributor

Summary

Stage 52 of the coverage push. Widget tests for the highlight-substring helper used by legal copy and toast snippets.

Cases

Target Cases
`TextSubstringHighlighting` 6 — substring-not-found fallback (plain `Text`, internal `TextSpan.children` is null); substring-found splits into three spans (before / match / after); default `highlightedStyle` is `base.copyWith(fontWeight: bold)`; custom `highlightedStyle` replaces the default bold entirely; `onHighlightedTap` attaches a `TapGestureRecognizer` and firing it triggers the callback; null callback → recognizer is null

What's pinned

  • The fallback vs highlight branch is observable from the rendered tree: the fallback wraps a plain `Text` (internal `RichText.text.children == null`), the highlight branch builds a `RichText` directly with three children. Pin both.
  • The default highlighting style preserves the base font size (`copyWith`) — refactoring the default to a fresh `TextStyle()` would break callers that rely on font-size inheritance.
  • The tap recognizer is optional: when `onHighlightedTap` is null, no recognizer is attached so the span doesn't intercept touches.

Test plan

  • `flutter test test/widgets/text_substring_highlighting_test.dart` — 6 pass
  • `flutter analyze` clean on the new file
  • CI green

Stage 52 of the coverage push. Widget tests for the highlight-
substring helper used by legal copy and toast snippets.

- substring not found → fallback Text widget (no TextSpan
  children list on the internal RichText)
- substring found → RichText with three spans (before / match /
  after)
- highlighted span inherits the base style + adds FontWeight.bold
  when no custom style is given
- custom highlightedStyle replaces the default bold entirely
- onHighlightedTap → attaches a TapGestureRecognizer; manually
  firing it triggers the callback
- no onHighlightedTap → recognizer is null
@TaprootFreak TaprootFreak marked this pull request as ready for review May 15, 2026 20:03
@TaprootFreak TaprootFreak merged commit 5bb7b6c into develop May 15, 2026
1 check passed
@TaprootFreak TaprootFreak deleted the test/text-substring-highlighting branch May 15, 2026 20:03
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