fileAttachmentDraft method
Implementation
Future<AttachmentDraft> fileAttachmentDraft({String? filepath}) async {
// ensure attachments exists and permissible to post
final attachmentsFinder =
find.byKey(AttachmentSectionWidget.attachmentsKey);
await attachmentsFinder.should(findsOneWidget);
final attachmentWidget = attachmentsFinder.evaluate().first.widget
as FoundAttachmentSectionWidget;
final attachmentsManager = attachmentWidget.attachmentManager;
final addAttachmentFinder =
find.byKey(AttachmentSectionWidget.addAttachmentBtnKey);
await addAttachmentFinder.should(findsOneWidget);
//
final file = await convertAssetImageToXFile(
filepath ?? 'assets/videos/video.mp4',
);
final context = tester.element(addAttachmentFinder);
final ref = ProviderScope.containerOf(context);
final client = ref.read(alwaysClientProvider);
String? mimeType = lookupMimeType(file.path);
String fileName = file.path.split('/').last;
int fileSize = await file.length();
final fileDraft = client
.fileDraft(file.path, mimeType!)
.filename(fileName)
.size(fileSize);
final attachmentDraft = await attachmentsManager.contentDraft(fileDraft);
return attachmentDraft;
}