@@ -14,6 +14,7 @@ import 'package:zulip/widgets/icons.dart';
14
14
import 'package:zulip/widgets/message_list.dart' ;
15
15
import 'package:zulip/widgets/page.dart' ;
16
16
import 'package:zulip/widgets/store.dart' ;
17
+ import 'package:zulip/widgets/text.dart' ;
17
18
import 'package:zulip/widgets/theme.dart' ;
18
19
19
20
import '../example_data.dart' as eg;
@@ -154,6 +155,41 @@ void main() {
154
155
});
155
156
}
156
157
158
+ /// Test the font weight found by [styleFinder] in the rendering of [content] .
159
+ ///
160
+ /// The weight will be expected to be [expectedWght] when the system
161
+ /// bold-text setting is not set, and to vary appropriately when it is set.
162
+ ///
163
+ /// [styleFinder] must return the [TextStyle] containing the "wght"
164
+ /// (in [TextStyle.fontVariations] ) and the [TextStyle.fontWeight]
165
+ /// to be checked.
166
+ Future <void > testFontWeight (String description, {
167
+ required Widget content,
168
+ required double expectedWght,
169
+ required TextStyle Function (WidgetTester tester) styleFinder,
170
+ }) async {
171
+ for (final platformRequestsBold in [false , true ]) {
172
+ testWidgets (
173
+ description + (platformRequestsBold ? ' (platform requests bold)' : '' ),
174
+ (tester) async {
175
+ tester.platformDispatcher.accessibilityFeaturesTestValue =
176
+ FakeAccessibilityFeatures (boldText: platformRequestsBold);
177
+ await prepareContent (tester, content);
178
+ final style = styleFinder (tester);
179
+ double effectiveExpectedWght = expectedWght;
180
+ if (platformRequestsBold) {
181
+ // bolderWght because that's what [weightVariableTextStyle] uses
182
+ effectiveExpectedWght = bolderWght (expectedWght);
183
+ }
184
+ check (style)
185
+ ..fontVariations.isNotNull ()
186
+ .any ((it) => it..axis.equals ('wght' )..value.equals (effectiveExpectedWght))
187
+ ..fontWeight.equals (clampVariableFontWeight (effectiveExpectedWght));
188
+ tester.platformDispatcher.clearAccessibilityFeaturesTestValue ();
189
+ });
190
+ }
191
+ }
192
+
157
193
group ('ThematicBreak' , () {
158
194
testWidgets ('smoke ThematicBreak' , (tester) async {
159
195
await prepareContent (tester, plainContent (ContentExample .thematicBreak.html));
@@ -471,6 +507,18 @@ void main() {
471
507
472
508
group ('strong (bold)' , () {
473
509
testContentSmoke (ContentExample .strong);
510
+
511
+ TextStyle findWordBold (WidgetTester tester) {
512
+ final root = tester.renderObject <RenderParagraph >(find.textContaining ('bold' )).text;
513
+ return mergedStyleOfSubstring (root, 'bold' )! ;
514
+ }
515
+
516
+ testFontWeight ('in plain paragraph' ,
517
+ expectedWght: 600 ,
518
+ // **bold**
519
+ content: plainContent ('<p><strong>bold</strong></p>' ),
520
+ styleFinder: findWordBold,
521
+ );
474
522
});
475
523
476
524
testContentSmoke (ContentExample .emphasis);
@@ -520,6 +568,34 @@ void main() {
520
568
return style.fontSize! ;
521
569
});
522
570
});
571
+
572
+ testFontWeight ('silent or non-self mention in plain paragraph' ,
573
+ expectedWght: 400 ,
574
+ // @_**Greg Price**
575
+ content: plainContent (
576
+ '<p><span class="user-mention silent" data-user-id="2187">Greg Price</span></p>' ),
577
+ styleFinder: (tester) {
578
+ return textStyleFromWidget (tester,
579
+ tester.widget (find.byType (UserMention )), 'Greg Price' );
580
+ });
581
+
582
+ // TODO(#647):
583
+ // testFontWeight('non-silent self-user mention in plain paragraph',
584
+ // expectedWght: 600, // [etc.]
585
+
586
+ testFontWeight ('silent or non-self mention in bold context' ,
587
+ expectedWght: 600 ,
588
+ // # @_**Chris Bobbe**
589
+ content: plainContent (
590
+ '<h1><span class="user-mention silent" data-user-id="13313">Chris Bobbe</span></h1>' ),
591
+ styleFinder: (tester) {
592
+ return textStyleFromWidget (tester,
593
+ tester.widget (find.byType (UserMention )), 'Chris Bobbe' );
594
+ });
595
+
596
+ // TODO(#647):
597
+ // testFontWeight('non-silent self-user mention in bold context',
598
+ // expectedWght: 800, // [etc.]
523
599
});
524
600
525
601
Future <void > tapText (WidgetTester tester, Finder textFinder) async {
0 commit comments