onboarding_em_rich_text_test.dart
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import 'package:doublefeel_flutter/app/modules/user_onboarding/widget/onboarding_em_rich_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
const normal = TextStyle(color: Color(0xFF0F0F11));
const emphasis = TextStyle(color: Color(0xFF835DED));
test('parses multiple em segments', () {
const source =
'我们希望可以帮助你\n<em>关注自己的身心变化,也让爱你的人</em>及时发现你的<em>疲惫与需要</em>';
final spans = emTaggedTextSpans(
source,
normalStyle: normal,
emphasisStyle: emphasis,
);
expect(spans.map((s) => s.text).toList(), [
'我们希望可以帮助你\n',
'关注自己的身心变化,也让爱你的人',
'及时发现你的',
'疲惫与需要',
]);
expect(spans[1].style, emphasis);
expect(spans[3].style, emphasis);
});
test('treats unclosed em tag as plain text', () {
const source = 'hello <em>world';
final spans = emTaggedTextSpans(
source,
normalStyle: normal,
emphasisStyle: emphasis,
);
expect(spans.map((s) => s.text).toList(), ['hello ', '<em>world']);
expect(spans.every((s) => s.style == normal), isTrue);
});
}