From ac746b0301d2ad01490f89ab0ad78a12695398da Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 7 Mar 2025 15:08:24 +0700 Subject: [PATCH] TF-3514 Add test case `processing 100 base64 images` in HtmlAnalyzer unit test Signed-off-by: dab246 --- .../composer/data/html_analyzer_test.dart | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/features/composer/data/html_analyzer_test.dart b/test/features/composer/data/html_analyzer_test.dart index ea2d81189..14f8efd7d 100644 --- a/test/features/composer/data/html_analyzer_test.dart +++ b/test/features/composer/data/html_analyzer_test.dart @@ -190,6 +190,41 @@ void main() { verify(mockFileUploader.uploadAttachment(any, any, uploadUri)).called(2); }); + test( + 'When processing 100 base64 images,\n' + 'should replace each with a unique CID and add corresponding attachments', + () async { + int countImage = 100; + final htmlContent = ''' + ${List.generate(countImage, (index) => '').join(' ')} + '''; + final inlineAttachments = {}; + final uploadUri = Uri.parse('https://example.com/upload'); + + when(mockUuid.v1()).thenAnswer((_) => 'uuid1'); + + when(mockFileUploader.uploadAttachment(any, any, any)) + .thenAnswer((_) async => Attachment( + blobId: Id('blob123'), + type: MediaType('image', 'png'), + disposition: ContentDisposition.inline, + )); + + final result = await htmlAnalyzer.replaceImageBase64ToImageCID( + emailContent: htmlContent, + inlineAttachments: inlineAttachments, + uploadUri: uploadUri, + ); + + final document = parse(result.value1); + final imgTags = document.querySelectorAll('img'); + expect(imgTags.length, countImage); + expect(imgTags.every((img) => img.attributes['src']!.contains('cid:')), isTrue); + expect(result.value2.length, countImage); + verify(mockUuid.v1()).called(countImage); + verify(mockFileUploader.uploadAttachment(any, any, uploadUri)).called(countImage); + }); + test( 'When one image upload throws an exception out of multiple base64 images,\n' 'should replace successful upload with CID and keep original src for failed one',