onboarding_em_rich_text_test.dart 1.24 KB
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);
  });
}