Files
pipelines/app/test/features/chat/speech/speech_document_test.dart
T
alan df0614e2f7 Steady read-aloud highlight and a calmer default pace
The spoken word is now painted behind unchanged text instead of
restyling the paragraph, so words never reshape, shift or rewrap as the
highlight moves. Revealing the word measures its own boxes against the
visible area, so a reversed transcript no longer jumps for a word already
in view. Sentence breaks the reading adds no longer map onto the next
item's first letter. 1.0x now reads at 0.8 of the platform's normal rate.
2026-11-13 09:41:02 +00:00

70 lines
2.6 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/speech/speech_document.dart';
void main() {
test('markdown is spoken as sentences and code is announced', () {
final result = markdownToSpeech(
'# Welcome\n\n- **First**\n- [Docs](https://example.com)\n\n```dart\nprint(1);\n```\n\nThat is all.',
);
expect(result.text, 'Welcome. First. Docs. Code block. That is all.');
expect(result.sources.length, result.text.length);
});
test('tilde fences and tables are summarised', () {
final result = markdownToSpeech(
'~~~\nsecret();\n~~~\n\n| A | B |\n|---|---|\n| 1 | 2 |',
);
expect(result.text, 'Code block. Table. A. B. 1. 2');
expect(result.text, isNot(contains('secret')));
});
test('repeated words map to their own occurrence', () {
const markdown = 'First repeat\n\nSecond repeat';
final result = markdownToSpeech(markdown);
final first = result.text.indexOf('repeat');
final second = result.text.lastIndexOf('repeat');
expect(result.sourceRange(0, (start: first, end: first + 6)), (
start: 6,
end: 12,
));
expect(result.sourceRange(0, (start: second, end: second + 6)), (
start: markdown.lastIndexOf('repeat'),
end: markdown.length,
));
});
test('text after a code block maps after the skipped code', () {
const markdown = 'Before repeat\n\n```dart\nrepeat();\n```\n\nAfter repeat';
final result = markdownToSpeech(markdown);
final spoken = result.text.lastIndexOf('repeat');
final range = result.sourceRange(0, (start: spoken, end: spoken + 6))!;
expect(range.start, markdown.lastIndexOf('repeat'));
});
test('parts are trimmed and keep their own sources', () {
final result = speechDocumentFor([' One part\n', '', 'Two part']);
expect(result.parts, ['One part', 'Two part']);
expect(result.text, 'One part. Two part');
expect(result.partOf('\nTwo part '), 1);
final two = result.text.indexOf('Two');
expect(result.sourceRange(1, (start: two, end: two + 3)), (
start: 0,
end: 3,
));
expect(result.sourceRange(0, (start: two, end: two + 3)), isNull);
});
test('a word read with its added sentence break stays on its own text', () {
const markdown = '- one\n- two';
final document = markdownToSpeech(markdown);
final spoken = document.text;
// An engine may report the word with the period the reading added.
final start = spoken.indexOf('one');
final range = document.sourceRange(0, (start: start, end: start + 5));
expect(range, (
start: markdown.indexOf('one'),
end: markdown.indexOf('one') + 3,
));
});
}