TF-2047 Re-write unit test for sanitize autolink filter
(cherry picked from commit ee5ee4bcbb1334f0cb2e667d76bfb4f25a4dc26a)
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
|
||||
import 'package:core/utils/linkify_html.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('linkify_html test', () {
|
||||
|
||||
final linkifyHtml = LinkifyHtml();
|
||||
|
||||
test(
|
||||
'generateLinkify should return <a href="url" target="_blank">url</a> when input text contain http/https/ftp',
|
||||
() async {
|
||||
final htmlValidate = linkifyHtml.generateLinkify(
|
||||
'See <https://linagora.com> at Hanoi'
|
||||
);
|
||||
expect(
|
||||
htmlValidate,
|
||||
equals('See <<a href="https://linagora.com" target="_blank">https://linagora.com</a>> at Hanoi'));
|
||||
}
|
||||
);
|
||||
|
||||
test(
|
||||
'generateLinkify should return <a href="https://www" target="_blank">www</a> when input text contain www',
|
||||
() async {
|
||||
final htmlValidate = linkifyHtml.generateLinkify(
|
||||
'See www.google.com at Hanoi'
|
||||
);
|
||||
expect(
|
||||
htmlValidate,
|
||||
equals('See <a href="https://www.google.com" target="_blank">www.google.com</a> at Hanoi'));
|
||||
}
|
||||
);
|
||||
|
||||
test(
|
||||
'generateLinkify should return <a href="mailto:url">url</a> when input text contain email address',
|
||||
() async {
|
||||
final htmlValidate = linkifyHtml.generateLinkify(
|
||||
'See tdvu@linagora.com at Hanoi'
|
||||
);
|
||||
expect(
|
||||
htmlValidate,
|
||||
equals('See <a href="mailto:tdvu@linagora.com">tdvu@linagora.com</a> at Hanoi'));
|
||||
}
|
||||
);
|
||||
|
||||
test(
|
||||
'generateLinkify should preserve the text when input text contain <a href=',
|
||||
() async {
|
||||
final htmlValidate = linkifyHtml.generateLinkify(
|
||||
'Check console output at "<a href="https://ci-builds.apache.org/job/james/job/ApacheJames/job/master/765/">james/ApacheJames/master [master] [765]</a>"'
|
||||
);
|
||||
expect(
|
||||
htmlValidate,
|
||||
equals('Check console output at "<a href="https://ci-builds.apache.org/job/james/job/ApacheJames/job/master/765/">james/ApacheJames/master [master] [765]</a>"')
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:core/presentation/utils/html_transformer/sanitize_autolink_filter.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('SanitizeAutolinkFilter test', () {
|
||||
|
||||
final sanitizeAutolinkFilter = SanitizeAutolinkFilter(const HtmlEscape());
|
||||
|
||||
test(
|
||||
'SanitizeAutolinkFilter should return html a tag with href="urlLink" when input text contain https',
|
||||
() {
|
||||
final htmlValidate = sanitizeAutolinkFilter.process('See https://linagora.com at Hanoi');
|
||||
expect(
|
||||
htmlValidate,
|
||||
equals('See <a href="https://linagora.com" target="_blank">linagora.com</a> at Hanoi')
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
test(
|
||||
'SanitizeAutolinkFilter should return html a tag with href="urlLink" when input text contain http',
|
||||
() {
|
||||
final htmlValidate = sanitizeAutolinkFilter.process('See http://linagora.com at Hanoi');
|
||||
expect(
|
||||
htmlValidate,
|
||||
equals('See <a href="http://linagora.com" target="_blank">linagora.com</a> at Hanoi')
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
test(
|
||||
'SanitizeAutolinkFilter should return html a tag with href="urlLink" when input text contain www',
|
||||
() {
|
||||
final htmlValidate = sanitizeAutolinkFilter.process('See www.linagora.com at Hanoi');
|
||||
expect(
|
||||
htmlValidate,
|
||||
equals('See <a href="https://www.linagora.com" target="_blank">linagora.com</a> at Hanoi')
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
test(
|
||||
'SanitizeAutolinkFilter should return html a tag with href="mailToLink" when input text contain email address',
|
||||
() {
|
||||
final htmlValidate = sanitizeAutolinkFilter.process('See tdvu@linagora.com at Hanoi');
|
||||
expect(
|
||||
htmlValidate,
|
||||
equals('See <a href="mailto:tdvu@linagora.com">tdvu@linagora.com</a> at Hanoi')
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user