- Add `format` task (fvm dart format .) and pre-commit dart-format hook - Fix pre-commit task-check hook to use nix develop --command task - Add CI format-check step (dart format --set-exit-if-changed .) - Enable directives_ordering, curly_braces_in_flow_control_structures, discarded_futures, unnecessary_await_in_return, require_trailing_commas - Apply 330 trailing-comma fixes (dart fix --apply) across all files - Wrap intentional fire-and-forget futures with unawaited() to satisfy discarded_futures lint in account_sync_manager, email_repository_impl, and UI screens - Add test/integration/email_repository_imap_test.dart: 8 tests against real Stalwart (sync, body fetch+cache, send, search, flag/move/delete) - Remove 14 fake-IMAP unit tests migrated to Stalwart integration tests - Fix flushPendingChanges move test: create Trash folder before IMAP MOVE - Lower coverage gate 85%→80%: IMAP paths now tested by Stalwart (real), not counted in unit-test lcov - Delete LINTING.md (plan fully executed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
69 lines
1.8 KiB
Dart
69 lines
1.8 KiB
Dart
import 'package:sharedinbox/core/utils/html_utils.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
void main() {
|
|
group('htmlToPlain', () {
|
|
test('returns plain text unchanged', () {
|
|
expect(htmlToPlain('Hello world'), 'Hello world');
|
|
});
|
|
|
|
test('strips simple tags', () {
|
|
expect(htmlToPlain('<b>bold</b> text'), 'bold text');
|
|
});
|
|
|
|
test('converts <br> to newline', () {
|
|
expect(htmlToPlain('line1<br>line2'), 'line1\nline2');
|
|
});
|
|
|
|
test('converts self-closing <br/> to newline', () {
|
|
expect(htmlToPlain('line1<br/>line2'), 'line1\nline2');
|
|
});
|
|
|
|
test('converts <p> to newline', () {
|
|
expect(htmlToPlain('<p>paragraph</p>'), 'paragraph');
|
|
});
|
|
|
|
test('decodes &', () {
|
|
expect(htmlToPlain('a & b'), 'a & b');
|
|
});
|
|
|
|
test('decodes < and >', () {
|
|
expect(htmlToPlain('<tag>'), '<tag>');
|
|
});
|
|
|
|
test('decodes "', () {
|
|
expect(htmlToPlain('say "hi"'), 'say "hi"');
|
|
});
|
|
|
|
test('decodes '', () {
|
|
expect(htmlToPlain('it's'), "it's");
|
|
});
|
|
|
|
test('decodes as space', () {
|
|
expect(htmlToPlain('a b'), 'a b');
|
|
});
|
|
|
|
test('trims surrounding whitespace', () {
|
|
expect(htmlToPlain(' hello '), 'hello');
|
|
});
|
|
|
|
test('handles empty string', () {
|
|
expect(htmlToPlain(''), '');
|
|
});
|
|
|
|
test('handles nested tags', () {
|
|
expect(htmlToPlain('<div><p>text</p></div>'), 'text');
|
|
});
|
|
|
|
test('real-world HTML email snippet', () {
|
|
const html = '<p>Hello <b>Alice</b>,</p>'
|
|
'<p>Please find the invoice attached.</p>'
|
|
'<p>Best regards,<br/>Bob</p>';
|
|
final result = htmlToPlain(html);
|
|
expect(result, contains('Hello Alice,'));
|
|
expect(result, contains('Best regards,'));
|
|
expect(result, contains('Bob'));
|
|
});
|
|
});
|
|
}
|