From 431a4f1ec2425da03957fe703e5c992f984fe2cf Mon Sep 17 00:00:00 2001 From: dab246 Date: Mon, 25 May 2026 11:42:54 +0700 Subject: [PATCH] TF-4482 Add tests for ResponsiveTableCellTransformer coverage and pipeline coexistence --- .../utils/html_transform_text_html_test.dart | 53 +++++++++++++++ ...esponsive_table_cell_transformer_test.dart | 42 ++++++++++++ .../utils/transform_configuration_test.dart | 65 +++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 core/test/utils/transform_configuration_test.dart diff --git a/core/test/utils/html_transform_text_html_test.dart b/core/test/utils/html_transform_text_html_test.dart index 734fe61a3..59ebb6494 100644 --- a/core/test/utils/html_transform_text_html_test.dart +++ b/core/test/utils/html_transform_text_html_test.dart @@ -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 = + '
safe content
'; + final out = await transform(input); + expect(out, isNot(contains('click'; + 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 = + '
text
'; + 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 = + '
text
'; + 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', () { diff --git a/core/test/utils/responsive_table_cell_transformer_test.dart b/core/test/utils/responsive_table_cell_transformer_test.dart index 1e9508c3d..e75daa7b5 100644 --- a/core/test/utils/responsive_table_cell_transformer_test.dart +++ b/core/test/utils/responsive_table_cell_transformer_test.dart @@ -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('
text
'); + 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('

text

more
'); + 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(''' + + +
outer + + +
inner headerinner cell
+
+ '''); + 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', + ); + } + }); }); } diff --git a/core/test/utils/transform_configuration_test.dart b/core/test/utils/transform_configuration_test.dart new file mode 100644 index 000000000..39e1841e7 --- /dev/null +++ b/core/test/utils/transform_configuration_test.dart @@ -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', + ); + }); + }); +}