mirror of
https://github.com/linagora/tmail-flutter.git
synced 2026-12-06 00:05:29 +00:00
TF-4482 Add tests for ResponsiveTableCellTransformer coverage and pipeline coexistence
This commit is contained in:
1 parent
f7e871220b
commit
431a4f1ec2
3 files changed
+160
No files matched your search
@@ -224,6 +224,59 @@ void main() {
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
group('Responsive transformer coexistence with standard pipeline', () {
|
||||
test('RemoveScriptTransformer: script inside td is removed AND td still gets overflow-wrap', () async {
|
||||
const input =
|
||||
'<table><tr><td><script>alert(1)</script>safe content</td></tr></table>';
|
||||
final out = await transform(input);
|
||||
expect(out, isNot(contains('<script')), reason: 'script must be stripped');
|
||||
expect(out, contains('safe content'));
|
||||
expect(out, contains('overflow-wrap: anywhere'),
|
||||
reason: 'td must still get overflow-wrap after script removal');
|
||||
});
|
||||
|
||||
test('SanitizeHyperLinkTagTransformer: link in td gets target/rel AND td gets overflow-wrap', () async {
|
||||
const input =
|
||||
'<table><tr><td><a href="https://example.com">click</a></td></tr></table>';
|
||||
final out = await transform(input);
|
||||
expect(out, contains('target="_blank"'),
|
||||
reason: 'link sanitization must still run');
|
||||
expect(out, contains('rel="noreferrer"'));
|
||||
expect(out, contains('overflow-wrap: anywhere'),
|
||||
reason: 'td must also get overflow-wrap');
|
||||
});
|
||||
|
||||
test('NormalizeLineHeightTransformer: bad line-height removed from td AND overflow-wrap added', () async {
|
||||
const input =
|
||||
'<table><tr><td style="line-height: 1px; padding: 8px;">text</td></tr></table>';
|
||||
final out = await transform(input);
|
||||
expect(out, isNot(contains('line-height: 1px')),
|
||||
reason: 'NormalizeLineHeight must strip the bad line-height value');
|
||||
expect(out, contains('padding: 8px'),
|
||||
reason: 'other styles must be preserved');
|
||||
expect(out, contains('overflow-wrap: anywhere'),
|
||||
reason: 'ResponsiveTableCellTransformer must still run after NormalizeLineHeight');
|
||||
});
|
||||
|
||||
test('NormalizeLineHeightTransformer: td with only bad line-height ends up with overflow-wrap only', () async {
|
||||
const input =
|
||||
'<table><tr><td style="line-height: 1px;">text</td></tr></table>';
|
||||
final out = await transform(input);
|
||||
expect(out, isNot(contains('line-height: 1px')));
|
||||
expect(out, contains('overflow-wrap: anywhere'),
|
||||
reason: 'after NormalizeLineHeight removes the sole style, Responsive must add overflow-wrap');
|
||||
});
|
||||
|
||||
test('full complex email: table cells get overflow-wrap AND existing links are preserved', () async {
|
||||
final out = await transform(HtmlEmailCorpus.htmlComplexNested);
|
||||
expect(out, contains('overflow-wrap: anywhere'),
|
||||
reason: 'all td/th cells in the complex email must get overflow-wrap');
|
||||
expect(out, contains('href="https://finance.example.com/budget"'),
|
||||
reason: 'link sanitization must not remove safe https links');
|
||||
expect(out, contains('Monthly Performance Report'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group('HtmlTransform.transformToHtml — fromDomTransformers', () {
|
||||
|
||||
@@ -96,5 +96,47 @@ void main() {
|
||||
expect(style, contains('padding: 20px'));
|
||||
expect(style, contains('overflow-wrap: anywhere'));
|
||||
});
|
||||
|
||||
test('is idempotent — running twice does not duplicate overflow-wrap', () async {
|
||||
final doc = parse('<table><tr><td>text</td></tr></table>');
|
||||
await transformer.process(document: doc, dioClient: dioClient);
|
||||
await transformer.process(document: doc, dioClient: dioClient);
|
||||
final style = doc.querySelector('td')!.attributes['style']!;
|
||||
expect(
|
||||
'overflow-wrap'.allMatches(style).length,
|
||||
1,
|
||||
reason: 'overflow-wrap must appear exactly once even after multiple passes',
|
||||
);
|
||||
});
|
||||
|
||||
test('does not add overflow-wrap to non-table elements', () async {
|
||||
final doc = await run('<div style="color: red"><p>text</p><span>more</span></div>');
|
||||
for (final el in doc.querySelectorAll('div, p, span')) {
|
||||
expect(
|
||||
el.attributes['style'] ?? '',
|
||||
isNot(contains('overflow-wrap')),
|
||||
reason: 'Only td/th must be modified — not div, p, or span',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('processes all td and th elements in nested tables', () async {
|
||||
final doc = await run('''
|
||||
<table>
|
||||
<tr><td>outer
|
||||
<table>
|
||||
<tr><th>inner header</th><td>inner cell</td></tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
</table>
|
||||
''');
|
||||
for (final cell in doc.querySelectorAll('td, th')) {
|
||||
expect(
|
||||
cell.attributes['style'],
|
||||
contains('overflow-wrap: anywhere'),
|
||||
reason: 'Every td/th in nested tables must have overflow-wrap: anywhere',
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:core/presentation/utils/html_transformer/dom/responsive_table_cell_transformer.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/transform_configuration.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
bool _hasResponsiveTransformer(List transformers) =>
|
||||
transformers.any((t) => t is ResponsiveTableCellTransformer);
|
||||
|
||||
void main() {
|
||||
group('TransformConfiguration — ResponsiveTableCellTransformer membership', () {
|
||||
test('standardDomTransformers includes ResponsiveTableCellTransformer', () {
|
||||
expect(
|
||||
_hasResponsiveTransformer(TransformConfiguration.standardDomTransformers),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('forPreviewEmailOnWeb includes ResponsiveTableCellTransformer', () {
|
||||
expect(
|
||||
_hasResponsiveTransformer(
|
||||
TransformConfiguration.forPreviewEmailOnWeb().domTransformers,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('forPreviewEmail includes ResponsiveTableCellTransformer via standardConfiguration', () {
|
||||
expect(
|
||||
_hasResponsiveTransformer(
|
||||
TransformConfiguration.forPreviewEmail().domTransformers,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('forReplyForwardEmail does NOT include ResponsiveTableCellTransformer', () {
|
||||
expect(
|
||||
_hasResponsiveTransformer(
|
||||
TransformConfiguration.forReplyForwardEmail().domTransformers,
|
||||
),
|
||||
isFalse,
|
||||
reason: 'Reply/forward editor must not mutate quoted content table styles',
|
||||
);
|
||||
});
|
||||
|
||||
test('forDraftsEmail does NOT include ResponsiveTableCellTransformer', () {
|
||||
expect(
|
||||
_hasResponsiveTransformer(
|
||||
TransformConfiguration.forDraftsEmail().domTransformers,
|
||||
),
|
||||
isFalse,
|
||||
reason: 'Draft editor must not mutate table styles',
|
||||
);
|
||||
});
|
||||
|
||||
test('forPrintEmail does NOT include ResponsiveTableCellTransformer', () {
|
||||
expect(
|
||||
_hasResponsiveTransformer(
|
||||
TransformConfiguration.forPrintEmail().domTransformers,
|
||||
),
|
||||
isFalse,
|
||||
reason: 'Print configuration does not need responsive wrapping',
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user