From e368062d9e558316709285d64a74cef188a19e63 Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 26 Jan 2024 08:18:39 +0700 Subject: [PATCH] TF-2510 Write unit test for validate attachment Signed-off-by: dab246 --- model/test/attachment_test.dart | 153 ++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 model/test/attachment_test.dart diff --git a/model/test/attachment_test.dart b/model/test/attachment_test.dart new file mode 100644 index 000000000..43c8ba829 --- /dev/null +++ b/model/test/attachment_test.dart @@ -0,0 +1,153 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:http_parser/http_parser.dart'; +import 'package:jmap_dart_client/jmap/core/id.dart'; +import 'package:model/model.dart'; + +void main() { + final attachmentA = Attachment( + disposition: ContentDisposition.attachment, + ); + + final attachmentB = Attachment( + disposition: ContentDisposition.attachment, + ); + + final attachmentC = Attachment( + disposition: ContentDisposition.attachment, + cid: 'attachmentC', + ); + + final attachmentD = Attachment( + disposition: ContentDisposition.attachment, + type: MediaType.parse('image/pdf'), + ); + + final attachmentE = Attachment( + disposition: ContentDisposition.attachment, + type: MediaType.parse('application/rtf'), + ); + + final attachmentF = Attachment( + disposition: ContentDisposition.inline, + type: MediaType.parse('application/rtf'), + ); + + final attachmentG = Attachment( + disposition: ContentDisposition.inline, + ); + + final attachmentH = Attachment(); + + final attachmentI = Attachment(blobId: Id('attachmentI')); + + group('isOutsideAttachment method test', () { + test( + 'GIVE attachmentA has disposition = `attachment` and cid is null\n' + 'AND htmlBodyAttachments is empty\n' + 'WHEN perform call `attachmentA.isOutsideAttachment()`\n' + 'SHOULD return true', + () { + List htmlBodyAttachments = []; + bool result = attachmentA.isOutsideAttachment(htmlBodyAttachments); + + expect(result, isTrue); + }); + + test( + 'GIVE attachmentB has disposition = `attachment`\n' + 'AND htmlBodyAttachments is empty\n' + 'WHEN perform call `attachmentB.isOutsideAttachment()`\n' + 'SHOULD return true', + () { + List htmlBodyAttachments = []; + bool result = attachmentB.isOutsideAttachment(htmlBodyAttachments); + + expect(result, isTrue); + }); + + test( + 'GIVE attachmentC has disposition = `attachment` and cid = `attachmentC`\n' + 'AND htmlBodyAttachments is empty\n' + 'WHEN perform call `attachmentB.isOutsideAttachment()`\n' + 'SHOULD return true', + () { + List htmlBodyAttachments = []; + bool result = attachmentC.isOutsideAttachment(htmlBodyAttachments); + + expect(result, isTrue); + }); + + test( + 'GIVE attachmentD has disposition = `attachment` and mediaType = `image/pdf`\n' + 'AND htmlBodyAttachments is empty\n' + 'WHEN perform call `attachmentD.isOutsideAttachment()`\n' + 'SHOULD return true', + () { + List htmlBodyAttachments = []; + bool result = attachmentD.isOutsideAttachment(htmlBodyAttachments); + + expect(result, isTrue); + }); + + test( + 'GIVE attachmentE has disposition = `attachment` and mediaType = `application/rtf`\n' + 'AND htmlBodyAttachments is empty\n' + 'WHEN perform call `attachmentE.isOutsideAttachment()`\n' + 'SHOULD return true', + () { + List htmlBodyAttachments = []; + bool result = attachmentE.isOutsideAttachment(htmlBodyAttachments); + + expect(result, isTrue); + }); + + + test( + 'GIVE attachmentF has disposition = `inline` and mediaType = `application/rtf`\n' + 'AND htmlBodyAttachments is empty\n' + 'WHEN perform call `attachmentF.isOutsideAttachment()`\n' + 'SHOULD return true', + () { + List htmlBodyAttachments = []; + bool result = attachmentF.isOutsideAttachment(htmlBodyAttachments); + + expect(result, isFalse); + }); + + test( + 'GIVE attachmentG has disposition = `inline`\n' + 'AND htmlBodyAttachments is empty\n' + 'WHEN perform call `attachmentG.isOutsideAttachment()`\n' + 'SHOULD return false', + () { + List htmlBodyAttachments = []; + bool result = attachmentG.isOutsideAttachment(htmlBodyAttachments); + + expect(result, isFalse); + }); + + test( + 'GIVE attachmentH has disposition is null\n' + 'AND htmlBodyAttachments is empty\n' + 'WHEN perform call `attachmentH.isOutsideAttachment()`\n' + 'SHOULD return true', + () { + List htmlBodyAttachments = []; + bool result = attachmentH.isOutsideAttachment(htmlBodyAttachments); + + expect(result, isTrue); + }); + + test( + 'GIVE attachmentI has blobId = `attachmentI`\n' + 'AND htmlBodyAttachments has `attachmentI`\n' + 'WHEN perform call `attachmentI.isOutsideAttachment()`\n' + 'SHOULD return false', + () { + List htmlBodyAttachments = [attachmentI]; + bool result = attachmentI.isOutsideAttachment(htmlBodyAttachments); + + expect(result, isFalse); + }); + }); +} \ No newline at end of file