TF-2510 Show PDF icon if `(mimetype == pdf || (mimetype == application/octet-stream && file.extension == pdf)
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -7,6 +7,10 @@ extension AttachmentExtension on Attachment {
|
||||
String getIcon(ImagePaths imagePaths) {
|
||||
final mediaType = type;
|
||||
log('AttachmentExtension::getIcon(): mediaType: $mediaType');
|
||||
if (isDisplayedPDFIcon) {
|
||||
return imagePaths.icFilePdf;
|
||||
}
|
||||
|
||||
if (mediaType == null) {
|
||||
return imagePaths.icFileEPup;
|
||||
}
|
||||
@@ -25,4 +29,7 @@ extension AttachmentExtension on Attachment {
|
||||
}
|
||||
return imagePaths.icFileEPup;
|
||||
}
|
||||
|
||||
bool get isDisplayedPDFIcon => type?.mimeType == 'application/pdf' ||
|
||||
(type?.mimeType == 'application/octet-stream' && name?.endsWith('.pdf') == true);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/attachment_extension.dart';
|
||||
|
||||
void main() {
|
||||
final attachmentA = Attachment(
|
||||
type: MediaType.parse('application/pdf')
|
||||
);
|
||||
|
||||
final attachmentB = Attachment(
|
||||
name: 'attachmentB.pdf',
|
||||
type: MediaType.parse('application/octet-stream')
|
||||
);
|
||||
|
||||
final attachmentC = Attachment(
|
||||
name: 'attachmentC.docx',
|
||||
type: MediaType.parse('application/octet-stream')
|
||||
);
|
||||
|
||||
final attachmentD = Attachment(
|
||||
name: 'attachmentD.png',
|
||||
type: MediaType.parse('image/png')
|
||||
);
|
||||
|
||||
final attachmentE = Attachment(
|
||||
name: 'attachmentE.pdf',
|
||||
type: MediaType.parse('text/html')
|
||||
);
|
||||
|
||||
group('isDisplayedPDFIcon method test', () {
|
||||
test(
|
||||
'GIVE attachmentA has mimeType = `application/pdf`\n'
|
||||
'WHEN perform call `attachmentA.isDisplayedPDFIcon()`\n'
|
||||
'SHOULD return true',
|
||||
() {
|
||||
bool result = attachmentA.isDisplayedPDFIcon;
|
||||
|
||||
expect(result, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'GIVE attachmentB has mimeType = `application/octet-stream`\n'
|
||||
'AND name = `attachmentB.pdf`\n'
|
||||
'WHEN perform call `attachmentB.isDisplayedPDFIcon()`\n'
|
||||
'SHOULD return true',
|
||||
() {
|
||||
bool result = attachmentB.isDisplayedPDFIcon;
|
||||
|
||||
expect(result, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'GIVE attachmentC has mimeType = `application/octet-stream`\n'
|
||||
'AND name = `attachmentC.docx`\n'
|
||||
'WHEN perform call `attachmentC.isDisplayedPDFIcon()`\n'
|
||||
'SHOULD return false',
|
||||
() {
|
||||
bool result = attachmentC.isDisplayedPDFIcon;
|
||||
|
||||
expect(result, isFalse);
|
||||
});
|
||||
|
||||
test(
|
||||
'GIVE attachmentD has mimeType = `image/png`\n'
|
||||
'AND name = `attachmentD.png`\n'
|
||||
'WHEN perform call `attachmentD.isDisplayedPDFIcon()`\n'
|
||||
'SHOULD return false',
|
||||
() {
|
||||
bool result = attachmentD.isDisplayedPDFIcon;
|
||||
|
||||
expect(result, isFalse);
|
||||
});
|
||||
|
||||
test(
|
||||
'GIVE attachmentE has mimeType = `text/html`\n'
|
||||
'AND name = `attachmentE.pdf`\n'
|
||||
'WHEN perform call `attachmentE.isDisplayedPDFIcon()`\n'
|
||||
'SHOULD return false',
|
||||
() {
|
||||
bool result = attachmentE.isDisplayedPDFIcon;
|
||||
|
||||
expect(result, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user