TF-3349 Escape messages when forward and reply email

This commit is contained in:
dab246
2024-12-16 15:39:33 +07:00
committed by Dat H. Pham
parent e859d977ee
commit 490196b36f
10 changed files with 196 additions and 24 deletions
@@ -0,0 +1,39 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:model/extensions/email_address_extension.dart';
void main() {
group('EmailAddressExtension::asFullStringWithLtGtCharacter::', () {
test('Should returns displayName and emailAddress formatted correctly', () {
final emailAddress = EmailAddress(
'john doe',
'john.doe@example.com',
);
expect(
emailAddress.asFullStringWithLtGtCharacter(),
'John Doe <john.doe@example.com>',
);
});
test('Should returns displayName capitalized when emailAddress is empty', () {
final emailAddress = EmailAddress(
'jane doe',
'',
);
expect(emailAddress.asFullStringWithLtGtCharacter(), 'Jane Doe');
});
test('Should returns emailAddress enclosed in <> when displayName is empty', () {
final emailAddress = EmailAddress(
'',
'jane.doe@example.com',
);
expect(emailAddress.asFullStringWithLtGtCharacter(), '<jane.doe@example.com>');
});
test('Should returns an empty string when both displayName and emailAddress are empty', () {
final emailAddress = EmailAddress('', '');
expect(emailAddress.asFullStringWithLtGtCharacter(), '');
});
});
}
@@ -0,0 +1,46 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:model/extensions/list_email_address_extension.dart';
void main() {
group('ListEmailAddressExtension::toEscapeHtmlString::', () {
test('Should returns empty string for null or empty list', () {
expect((<EmailAddress>{}).toEscapeHtmlString(', '), '');
Set<EmailAddress>? listEmails;
expect(listEmails.toEscapeHtmlString(', '), '');
});
test('Should returns joined HTML strings with separator', () {
final emails = {
EmailAddress('John Doe', 'john@example.com'),
EmailAddress('Jane Smith', 'jane@example.com'),
};
final result = emails.toEscapeHtmlString(' | ');
expect(result, 'John Doe &lt;john@example.com&gt; | Jane Smith &lt;jane@example.com&gt;');
});
test('Should handles displayName-only or email-only cases', () {
final emails = {
EmailAddress('John Doe', ''),
EmailAddress('', 'jane@example.com'),
};
final result = emails.toEscapeHtmlString(', ');
expect(result, 'John Doe, &lt;jane@example.com&gt;');
});
});
group('ListEmailAddressExtension::toEscapeHtmlStringUseCommaSeparator::', () {
test('Should uses ", " as separator', () {
final emails = {
EmailAddress('John Doe', 'john@example.com'),
EmailAddress('Jane Smith', 'jane@example.com'),
};
final result = emails.toEscapeHtmlStringUseCommaSeparator();
expect(result, 'John Doe &lt;john@example.com&gt;, Jane Smith &lt;jane@example.com&gt;');
});
});
}