@@ -67,6 +67,8 @@ TextStyle? mergeSpanStylesOuterToInner(
67
67
68
68
/// The "merged style" ([mergeSpanStylesOuterToInner] ) of a text span
69
69
/// whose whole text matches the given pattern, under the given root span.
70
+ ///
71
+ /// See also [mergedStyleOf] , which can be more convenient.
70
72
TextStyle ? mergedStyleOfSubstring (InlineSpan rootSpan, Pattern spanPattern) {
71
73
return mergeSpanStylesOuterToInner (rootSpan,
72
74
(span) {
@@ -81,6 +83,23 @@ TextStyle? mergedStyleOfSubstring(InlineSpan rootSpan, Pattern spanPattern) {
81
83
});
82
84
}
83
85
86
+ /// The "merged style" ([mergeSpanStylesOuterToInner] ) of a text span
87
+ /// whose whole text matches the given pattern, somewhere in the tree.
88
+ ///
89
+ /// This finds the relevant [Text] widget by a search for [spanPattern] .
90
+ /// If [findAncestor] is non-null, the search will only consider descendants
91
+ /// of widgets matching [findAncestor] .
92
+ TextStyle ? mergedStyleOf (WidgetTester tester, Pattern spanPattern, {
93
+ Finder ? findAncestor,
94
+ }) {
95
+ var findTextWidget = find.textContaining (spanPattern);
96
+ if (findAncestor != null ) {
97
+ findTextWidget = find.descendant (of: findAncestor, matching: findTextWidget);
98
+ }
99
+ final rootSpan = tester.renderObject <RenderParagraph >(findTextWidget).text;
100
+ return mergedStyleOfSubstring (rootSpan, spanPattern);
101
+ }
102
+
84
103
/// A callback that finds some target subspan within the given span,
85
104
/// and reports the target's font size.
86
105
typedef TargetFontSizeFinder = double Function (InlineSpan rootSpan);
@@ -486,18 +505,12 @@ void main() {
486
505
testFontWeight ('syntax highlighting: non-bold span' ,
487
506
expectedWght: 400 ,
488
507
content: plainContent (ContentExample .codeBlockHighlightedShort.html),
489
- styleFinder: (tester) {
490
- final root = tester.renderObject <RenderParagraph >(find.textContaining ('class' )).text;
491
- return mergedStyleOfSubstring (root, 'class' )! ;
492
- });
508
+ styleFinder: (tester) => mergedStyleOf (tester, 'class' )! );
493
509
494
510
testFontWeight ('syntax highlighting: bold span' ,
495
511
expectedWght: 700 ,
496
512
content: plainContent (ContentExample .codeBlockHighlightedShort.html),
497
- styleFinder: (tester) {
498
- final root = tester.renderObject <RenderParagraph >(find.textContaining ('A' )).text;
499
- return mergedStyleOfSubstring (root, 'A' )! ;
500
- });
513
+ styleFinder: (tester) => mergedStyleOf (tester, 'A' )! );
501
514
});
502
515
503
516
testContentSmoke (ContentExample .mathBlock);
@@ -550,8 +563,7 @@ void main() {
550
563
testContentSmoke (ContentExample .strong);
551
564
552
565
TextStyle findWordBold (WidgetTester tester) {
553
- final root = tester.renderObject <RenderParagraph >(find.textContaining ('bold' )).text;
554
- return mergedStyleOfSubstring (root, 'bold' )! ;
566
+ return mergedStyleOf (tester, 'bold' )! ;
555
567
}
556
568
557
569
testFontWeight ('in plain paragraph' ,
@@ -906,11 +918,8 @@ void main() {
906
918
find.descendant (of: find.byType (GlobalTime ),
907
919
matching: find.byIcon (ZulipIcons .clock)));
908
920
909
- final textSpan = tester.renderObject <RenderParagraph >(
910
- find.descendant (of: find.byType (GlobalTime ),
911
- matching: find.textContaining (renderedTextRegexp)
912
- )).text;
913
- final textColor = mergedStyleOfSubstring (textSpan, renderedTextRegexp)! .color;
921
+ final textColor = mergedStyleOf (tester,
922
+ findAncestor: find.byType (GlobalTime ), renderedTextRegexp)! .color;
914
923
check (textColor).isNotNull ();
915
924
916
925
check (icon).color.isNotNull ().isSameColorAs (textColor! );
@@ -939,11 +948,8 @@ void main() {
939
948
940
949
testWidgets ('text is scaled' , (tester) async {
941
950
await doCheck (tester, (widget) {
942
- final textSpan = tester.renderObject <RenderParagraph >(
943
- find.descendant (of: find.byWidget (widget),
944
- matching: find.textContaining (renderedTextRegexp)
945
- )).text;
946
- return mergedStyleOfSubstring (textSpan, renderedTextRegexp)! .fontSize! ;
951
+ return mergedStyleOf (tester, findAncestor: find.byWidget (widget),
952
+ renderedTextRegexp)! .fontSize! ;
947
953
});
948
954
});
949
955
@@ -1096,10 +1102,7 @@ void main() {
1096
1102
// | 1 | 2 | 3 | 4 |
1097
1103
content: plainContent (ContentExample .tableWithSingleRow.html),
1098
1104
expectedWght: 700 ,
1099
- styleFinder: (tester) {
1100
- final root = tester.renderObject <RenderParagraph >(find.textContaining ('a' )).text;
1101
- return mergedStyleOfSubstring (root, 'a' )! ;
1102
- });
1105
+ styleFinder: (tester) => mergedStyleOf (tester, 'a' )! );
1103
1106
1104
1107
testWidgets ('header row background color' , (tester) async {
1105
1108
await prepareContent (tester, plainContent (ContentExample .tableWithSingleRow.html));
0 commit comments