mirror of
https://github.com/linagora/tmail-flutter.git
synced 2026-12-05 16:08:46 +00:00
Hotfix: Second Save as Draft Fails for Draft Emails with Attachments or Inline Images (#4505)
This commit is contained in:
1 parent
d2309cee16
commit
54ffff4e1d
56 files changed
+1629
-238
No files matched your search
@@ -1,14 +1,16 @@
|
||||
import 'package:patrol/patrol.dart';
|
||||
|
||||
import '../robots/abstract/abstract_app_grid_robot.dart';
|
||||
import '../robots/mobile/mobile_app_grid_robot.dart';
|
||||
import 'robot_factory.dart';
|
||||
import '../robots/abstract/abstract_login_robot.dart';
|
||||
import '../robots/abstract/abstract_thread_robot.dart';
|
||||
import '../robots/abstract/abstract_composer_robot.dart';
|
||||
import '../robots/abstract/abstract_login_robot.dart';
|
||||
import '../robots/abstract/abstract_mailbox_menu_robot.dart';
|
||||
import '../robots/abstract/abstract_thread_robot.dart';
|
||||
import '../robots/mailbox_menu_robot.dart';
|
||||
import '../robots/mobile/mobile_app_grid_robot.dart';
|
||||
import '../robots/mobile/mobile_composer_robot.dart';
|
||||
import '../robots/mobile/mobile_login_robot.dart';
|
||||
import '../robots/mobile/mobile_thread_robot.dart';
|
||||
import '../robots/mobile/mobile_composer_robot.dart';
|
||||
import 'robot_factory.dart';
|
||||
|
||||
class MobileRobotFactory implements RobotFactory {
|
||||
final PatrolIntegrationTester $;
|
||||
@@ -26,4 +28,7 @@ class MobileRobotFactory implements RobotFactory {
|
||||
|
||||
@override
|
||||
AbstractAppGridRobot appGridRobot() => MobileAppGridRobot($);
|
||||
|
||||
@override
|
||||
AbstractMailboxMenuRobot mailboxMenuRobot() => MailboxMenuRobot($);
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
import '../robots/abstract/abstract_app_grid_robot.dart';
|
||||
import '../robots/abstract/abstract_login_robot.dart';
|
||||
import '../robots/abstract/abstract_thread_robot.dart';
|
||||
import '../robots/abstract/abstract_composer_robot.dart';
|
||||
import '../robots/abstract/abstract_login_robot.dart';
|
||||
import '../robots/abstract/abstract_mailbox_menu_robot.dart';
|
||||
import '../robots/abstract/abstract_thread_robot.dart';
|
||||
|
||||
abstract class RobotFactory {
|
||||
AbstractLoginRobot loginRobot();
|
||||
AbstractThreadRobot threadRobot();
|
||||
AbstractComposerRobot composerRobot();
|
||||
AbstractAppGridRobot appGridRobot();
|
||||
AbstractMailboxMenuRobot mailboxMenuRobot();
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
import 'package:patrol/patrol.dart';
|
||||
|
||||
import '../robots/abstract/abstract_app_grid_robot.dart';
|
||||
import '../robots/abstract/abstract_composer_robot.dart';
|
||||
import '../robots/abstract/abstract_login_robot.dart';
|
||||
import '../robots/abstract/abstract_mailbox_menu_robot.dart';
|
||||
import '../robots/abstract/abstract_thread_robot.dart';
|
||||
import '../robots/mailbox_menu_robot.dart';
|
||||
import '../robots/web/web_app_grid_robot.dart';
|
||||
import '../robots/web/web_composer_robot.dart';
|
||||
import '../robots/web/web_login_robot.dart';
|
||||
import '../robots/web/web_thread_robot.dart';
|
||||
import 'robot_factory.dart';
|
||||
import '../robots/abstract/abstract_login_robot.dart';
|
||||
import '../robots/abstract/abstract_thread_robot.dart';
|
||||
import '../robots/abstract/abstract_composer_robot.dart';
|
||||
import '../robots/web/web_composer_robot.dart';
|
||||
|
||||
class WebRobotFactory implements RobotFactory {
|
||||
final PatrolIntegrationTester $;
|
||||
@@ -26,4 +28,7 @@ class WebRobotFactory implements RobotFactory {
|
||||
|
||||
@override
|
||||
AbstractAppGridRobot appGridRobot() => WebAppGridRobot($);
|
||||
|
||||
@override
|
||||
AbstractMailboxMenuRobot mailboxMenuRobot() => MailboxMenuRobot($);
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:model/email/prefix_email_address.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/composer_controller.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
abstract class AbstractComposerRobot {
|
||||
Future<void> expectComposerViewVisible();
|
||||
@@ -12,4 +15,16 @@ abstract class AbstractComposerRobot {
|
||||
Future<void> focusEditorAboveReplyBody();
|
||||
Future<void> addInlineAtCursorPosition(File file);
|
||||
Future<void> waitForSignatureToLoad();
|
||||
Future<void> tapCloseComposer();
|
||||
Future<void> tapSaveButtonOnSaveDraftConfirmDialog(AppLocalizations appLocalizations);
|
||||
// Use bytes instead of File so these methods work on web (no dart:io / path_provider).
|
||||
Future<void> addAttachmentFromBytes(Uint8List bytes, String fileName);
|
||||
Future<void> addInlineFromBytes(Uint8List bytes, String fileName);
|
||||
Future<void> tapSaveAsDraftButton();
|
||||
Future<void> tapSaveAsTemplateButton();
|
||||
Future<void> tapDiscardChanges();
|
||||
/// Returns the active [ComposerController] for the currently visible composer.
|
||||
/// Platform implementations must resolve the correct GetX tag (web uses a
|
||||
/// per-instance composerId; mobile uses the default null tag).
|
||||
ComposerController? findComposerController();
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
abstract class AbstractMailboxMenuRobot {
|
||||
Future<void> openFolderByName(String name);
|
||||
Future<void> pullToRefresh();
|
||||
}
|
||||
@@ -2,4 +2,6 @@ abstract class AbstractThreadRobot {
|
||||
Future<void> openComposer();
|
||||
Future<void> expectAppGridVisible();
|
||||
Future<void> openAppGrid();
|
||||
Future<void> openMailbox();
|
||||
Future<void> openEmailWithSubject(String subject);
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:model/upload/file_info.dart';
|
||||
import 'package:core/presentation/views/button/tmail_button_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:model/email/prefix_email_address.dart';
|
||||
import 'package:model/extensions/session_extension.dart';
|
||||
import 'package:rich_text_composer/rich_text_composer.dart';
|
||||
@@ -90,12 +91,8 @@ class ComposerRobot extends CoreRobot {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> tapCloseComposer(ImagePaths imagePaths) async {
|
||||
await $(AppBarComposerWidget)
|
||||
.$(TMailButtonWidget)
|
||||
.which<TMailButtonWidget>(
|
||||
(widget) => widget.icon == imagePaths.icCancel)
|
||||
.tap();
|
||||
Future<void> tapCloseComposer([ImagePaths? imagePaths]) async {
|
||||
await $(const ValueKey(UiKeys.closeComposerButton)).tap();
|
||||
}
|
||||
|
||||
Future<void> tapSaveButtonOnSaveDraftConfirmDialog(
|
||||
@@ -140,15 +137,24 @@ class ComposerRobot extends CoreRobot {
|
||||
await $(AppLocalizations().saveAsTemplate).tap();
|
||||
}
|
||||
|
||||
ComposerController? findComposerController() => getBinding<ComposerController>();
|
||||
|
||||
Future<void> addAttachment(File file) async {
|
||||
final controller = Get.find<ComposerController>();
|
||||
final controller = findComposerController()!;
|
||||
final fileInfo = await file.toFileInfo();
|
||||
_uploadAttachment(controller, fileInfo);
|
||||
}
|
||||
|
||||
Future<void> addAttachmentFromBytes(Uint8List bytes, String fileName) async {
|
||||
final controller = findComposerController()!;
|
||||
final fileInfo = FileInfo.fromBytes(bytes: bytes, name: fileName);
|
||||
_uploadAttachment(controller, fileInfo);
|
||||
}
|
||||
|
||||
void _uploadAttachment(ComposerController controller, FileInfo fileInfo) {
|
||||
controller.uploadController.justUploadAttachmentsAction(
|
||||
uploadFiles: [
|
||||
fileInfo,
|
||||
],
|
||||
uploadUri:
|
||||
controller.mailboxDashBoardController.sessionCurrent!.getUploadUri(
|
||||
uploadFiles: [fileInfo],
|
||||
uploadUri: controller.mailboxDashBoardController.sessionCurrent!.getUploadUri(
|
||||
controller.mailboxDashBoardController.accountId.value!,
|
||||
jmapUrl: controller.dynamicUrlInterceptors.jmapUrl,
|
||||
),
|
||||
@@ -156,8 +162,18 @@ class ComposerRobot extends CoreRobot {
|
||||
}
|
||||
|
||||
Future<void> addInline(File file) async {
|
||||
final controller = Get.find<ComposerController>();
|
||||
final controller = findComposerController()!;
|
||||
final fileInfo = await file.toFileInfo();
|
||||
await _addInlineFromFileInfo(controller, fileInfo);
|
||||
}
|
||||
|
||||
Future<void> addInlineFromBytes(Uint8List bytes, String fileName) async {
|
||||
final controller = findComposerController()!;
|
||||
final fileInfo = FileInfo.fromBytes(bytes: bytes, name: fileName, isInline: true);
|
||||
await _addInlineFromFileInfo(controller, fileInfo);
|
||||
}
|
||||
|
||||
Future<void> _addInlineFromFileInfo(ComposerController controller, FileInfo fileInfo) async {
|
||||
controller.handleSuccessViewState(LocalImagePickerSuccess(fileInfo));
|
||||
await controller.viewState.stream.firstWhere((state) => state.fold(
|
||||
(failure) => false,
|
||||
@@ -181,4 +197,18 @@ class ComposerRobot extends CoreRobot {
|
||||
Future<void> tapDiscardChanges() async {
|
||||
await $(AppLocalizations().discardChanges).tap();
|
||||
}
|
||||
|
||||
Future<void> tapSaveAsDraftButton() async {
|
||||
await $(const Key(UiKeys.composerMoreButton)).tap();
|
||||
await $.pumpAndSettle();
|
||||
await $(const Key(UiKeys.saveDraftPopupItem)).tap();
|
||||
await $.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> tapSaveAsTemplateButton() async {
|
||||
await $(const Key(UiKeys.composerMoreButton)).tap();
|
||||
await $.pumpAndSettle();
|
||||
await $(const Key(UiKeys.saveTemplatePopupItem)).tap();
|
||||
await $.pumpAndSettle();
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,12 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
import '../base/core_robot.dart';
|
||||
import '../exceptions/mailbox/null_inbox_unread_count_exception.dart';
|
||||
import '../exceptions/mailbox/null_quota_exception.dart';
|
||||
import 'abstract/abstract_mailbox_menu_robot.dart';
|
||||
|
||||
class MailboxMenuRobot extends CoreRobot {
|
||||
class MailboxMenuRobot extends CoreRobot implements AbstractMailboxMenuRobot {
|
||||
MailboxMenuRobot(super.$);
|
||||
|
||||
@override
|
||||
Future<void> openFolderByName(String name) async {
|
||||
final mailboxItem = $(MailboxItemWidget).$(LabelMailboxItemWidget).$(name);
|
||||
await $(mailboxItem).waitUntilExists();
|
||||
@@ -185,4 +187,9 @@ class MailboxMenuRobot extends CoreRobot {
|
||||
await $(mailboxName).tap();
|
||||
await $.pumpAndTrySettle();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> pullToRefresh() async {
|
||||
await $.platformAutomator.mobile.pullToRefresh();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:patrol/patrol.dart';
|
||||
import 'package:tmail_ui_user/features/base/model/ui_keys.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/composer_controller.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/composer_view_web.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/widgets/web/web_editor_widget.dart';
|
||||
|
||||
@@ -26,4 +30,31 @@ class WebComposerRobot extends MobileComposerRobot {
|
||||
text: content,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> tapSaveAsDraftButton() async {
|
||||
await $(const Key(UiKeys.saveDraftButton)).tap();
|
||||
await $.pumpAndSettle();
|
||||
}
|
||||
|
||||
/// Resolves the [ComposerController] from the web [ComposerView] widget in
|
||||
/// the tree. On web, the controller is registered in GetX with a per-instance
|
||||
/// composerId tag, so [Get.find] without a tag fails. Reading it from the
|
||||
/// widget's [controller] getter is the only reliable approach.
|
||||
@override
|
||||
ComposerController? findComposerController() {
|
||||
final widgets = $.tester
|
||||
.widgetList<ComposerView>(find.byType(ComposerView))
|
||||
.toList();
|
||||
if (widgets.isEmpty) return null;
|
||||
return widgets.first.controller;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> tapSaveAsTemplateButton() async {
|
||||
await $(const Key(UiKeys.composerMoreButton)).tap();
|
||||
await $.pumpAndSettle();
|
||||
await $(const Key(UiKeys.saveTemplatePopupItem)).tap();
|
||||
await $.pumpAndSettle();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,45 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:labels/extensions/label_extension.dart';
|
||||
import 'package:patrol/patrol.dart';
|
||||
import 'package:tmail_ui_user/features/base/model/ui_keys.dart';
|
||||
import 'package:tmail_ui_user/features/thread/presentation/widgets/email_tile_web_builder.dart';
|
||||
|
||||
import '../mobile/mobile_thread_robot.dart';
|
||||
|
||||
class WebThreadRobot extends MobileThreadRobot {
|
||||
WebThreadRobot(super.$);
|
||||
|
||||
static const Duration _emailOpenPumpDuration = Duration(seconds: 2);
|
||||
|
||||
@override
|
||||
Future<void> expectAppGridVisible() async {
|
||||
await $(const ValueKey(UiKeys.toggleAppGridButton)).waitUntilVisible();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> openEmailWithSubject(String subject) async {
|
||||
final email = $(EmailTileBuilder).which<EmailTileBuilder>(
|
||||
(view) =>
|
||||
view.presentationEmail.subject != null &&
|
||||
view.presentationEmail.subject == subject,
|
||||
);
|
||||
await _openEmailTile(email);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> openEmailWithLabel(String labelDisplayName) async {
|
||||
final email = $(EmailTileBuilder).which<EmailTileBuilder>(
|
||||
(view) =>
|
||||
view.labels
|
||||
?.any((label) => label.safeDisplayName == labelDisplayName) ==
|
||||
true,
|
||||
);
|
||||
await _openEmailTile(email);
|
||||
}
|
||||
|
||||
Future<void> _openEmailTile(PatrolFinder emailFinder) async {
|
||||
await $.waitUntilVisible(emailFinder);
|
||||
await emailFinder.tap();
|
||||
await $.pump(_emailOpenPumpDuration);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:model/email/prefix_email_address.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
import '../../base/base_test_scenario.dart';
|
||||
import '../../resources/test_images.dart';
|
||||
import '../../robots/abstract/abstract_composer_robot.dart';
|
||||
import '../../utils/wait_for_condition.dart';
|
||||
|
||||
abstract class BaseSaveAndReopenScenario extends BaseTestScenario {
|
||||
const BaseSaveAndReopenScenario(super.$, super.robots);
|
||||
|
||||
String get subject;
|
||||
|
||||
Future<void> attachContent(AbstractComposerRobot composerRobot, Uint8List bytes);
|
||||
|
||||
Future<void> waitForContentUploaded(AbstractComposerRobot composerRobot);
|
||||
|
||||
String folderDisplayName(AppLocalizations l10n);
|
||||
|
||||
Future<void> performFirstSave(
|
||||
AbstractComposerRobot composerRobot,
|
||||
AppLocalizations l10n,
|
||||
);
|
||||
|
||||
Future<void> performSubsequentSave(
|
||||
AbstractComposerRobot composerRobot,
|
||||
AppLocalizations l10n,
|
||||
);
|
||||
|
||||
Future<void> onPreComposerSetup() async {}
|
||||
|
||||
Future<void> onAfterContentUploaded() async {}
|
||||
|
||||
Future<void> onAfterComposerReopened() async {}
|
||||
|
||||
@override
|
||||
Future<void> runTestLogic() async {
|
||||
const email = String.fromEnvironment('BASIC_AUTH_EMAIL');
|
||||
assert(email.isNotEmpty, 'BASIC_AUTH_EMAIL must not be empty');
|
||||
|
||||
final uniqueSubject = '$subject ${DateTime.now().microsecondsSinceEpoch}';
|
||||
final threadRobot = robots.threadRobot();
|
||||
final mailboxMenuRobot = robots.mailboxMenuRobot();
|
||||
final composerRobot = robots.composerRobot();
|
||||
final appLocalizations = AppLocalizations();
|
||||
|
||||
await onPreComposerSetup();
|
||||
|
||||
await threadRobot.openComposer();
|
||||
await composerRobot.expectComposerViewVisible();
|
||||
await composerRobot.grantContactPermission();
|
||||
|
||||
await composerRobot.addRecipient(PrefixEmailAddress.to, email);
|
||||
await composerRobot.addSubject(uniqueSubject);
|
||||
|
||||
final bytes = base64Decode(TestImages.base64);
|
||||
await attachContent(composerRobot, bytes);
|
||||
await waitForContentUploaded(composerRobot);
|
||||
|
||||
await onAfterContentUploaded();
|
||||
|
||||
await performFirstSave(composerRobot, appLocalizations);
|
||||
|
||||
if (PlatformInfo.isMobile) {
|
||||
await threadRobot.openMailbox();
|
||||
}
|
||||
await mailboxMenuRobot.openFolderByName(folderDisplayName(appLocalizations));
|
||||
await waitForCondition(() => $(uniqueSubject).exists);
|
||||
await threadRobot.openEmailWithSubject(uniqueSubject);
|
||||
await composerRobot.expectComposerViewVisible();
|
||||
await composerRobot.grantContactPermission();
|
||||
|
||||
await onAfterComposerReopened();
|
||||
|
||||
await composerRobot.addSubject(' edited');
|
||||
await performSubsequentSave(composerRobot, appLocalizations);
|
||||
|
||||
await composerRobot.addSubject(' again');
|
||||
await performSubsequentSave(composerRobot, appLocalizations);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
import '../../robots/abstract/abstract_composer_robot.dart';
|
||||
import 'base_save_and_reopen_scenario.dart';
|
||||
|
||||
abstract class BaseSaveDraftThenReopenScenario extends BaseSaveAndReopenScenario {
|
||||
const BaseSaveDraftThenReopenScenario(super.$, super.robots);
|
||||
|
||||
@override
|
||||
String folderDisplayName(AppLocalizations l10n) => l10n.draftsMailboxDisplayName;
|
||||
|
||||
@override
|
||||
Future<void> performFirstSave(
|
||||
AbstractComposerRobot composerRobot,
|
||||
AppLocalizations l10n,
|
||||
) async {
|
||||
await composerRobot.tapCloseComposer();
|
||||
await $.pumpAndTrySettle();
|
||||
await expectViewVisible($(#confirm_dialog_action));
|
||||
await composerRobot.tapSaveButtonOnSaveDraftConfirmDialog(l10n);
|
||||
await $.pumpAndTrySettle();
|
||||
await _expectSaveDraftSuccessToast(l10n);
|
||||
await $.pumpAndTrySettle();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> performSubsequentSave(
|
||||
AbstractComposerRobot composerRobot,
|
||||
AppLocalizations l10n,
|
||||
) async {
|
||||
await composerRobot.tapSaveAsDraftButton();
|
||||
await $.pumpAndTrySettle();
|
||||
await _expectSaveDraftSuccessToast(l10n);
|
||||
}
|
||||
|
||||
Future<void> _expectSaveDraftSuccessToast(AppLocalizations l10n) async {
|
||||
await expectViewVisible($(find.text(l10n.drafts_saved)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
import '../../robots/abstract/abstract_composer_robot.dart';
|
||||
import 'base_save_and_reopen_scenario.dart';
|
||||
|
||||
abstract class BaseSaveTemplateThenReopenScenario extends BaseSaveAndReopenScenario {
|
||||
const BaseSaveTemplateThenReopenScenario(super.$, super.robots);
|
||||
|
||||
@override
|
||||
String folderDisplayName(AppLocalizations l10n) => l10n.templatesMailboxDisplayName;
|
||||
|
||||
@override
|
||||
Future<void> onPreComposerSetup() async {
|
||||
if (PlatformInfo.isMobile) {
|
||||
await robots.threadRobot().openMailbox();
|
||||
await $.pumpAndTrySettle();
|
||||
await robots.mailboxMenuRobot().pullToRefresh();
|
||||
await mobileBack($);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onAfterContentUploaded() async {
|
||||
await $.pumpAndTrySettle(duration: const Duration(seconds: 2));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> performFirstSave(
|
||||
AbstractComposerRobot composerRobot,
|
||||
AppLocalizations l10n,
|
||||
) async {
|
||||
await composerRobot.tapSaveAsTemplateButton();
|
||||
await _expectSaveTemplateSuccessToast(l10n);
|
||||
await $.pumpAndTrySettle();
|
||||
await composerRobot.tapCloseComposer();
|
||||
await $.pumpAndTrySettle();
|
||||
await composerRobot.tapDiscardChanges();
|
||||
await $.pumpAndTrySettle();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onAfterComposerReopened() async {
|
||||
await $.pumpAndTrySettle(duration: const Duration(seconds: 2));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> performSubsequentSave(
|
||||
AbstractComposerRobot composerRobot,
|
||||
AppLocalizations l10n,
|
||||
) async {
|
||||
await composerRobot.tapSaveAsTemplateButton();
|
||||
await _expectUpdateTemplateSuccessToast(l10n);
|
||||
}
|
||||
|
||||
Future<void> _expectSaveTemplateSuccessToast(AppLocalizations l10n) async {
|
||||
await expectViewVisible($(find.text(l10n.saveMessageToTemplateSuccess)));
|
||||
}
|
||||
|
||||
Future<void> _expectUpdateTemplateSuccessToast(AppLocalizations l10n) async {
|
||||
await expectViewVisible($(find.text(l10n.updateMessageToTemplateSuccess)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../robots/abstract/abstract_composer_robot.dart';
|
||||
import '../../utils/wait_for_condition.dart';
|
||||
import 'base_save_and_reopen_scenario.dart';
|
||||
|
||||
mixin WithAttachmentContentMixin on BaseSaveAndReopenScenario {
|
||||
@override
|
||||
Future<void> attachContent(AbstractComposerRobot composerRobot, Uint8List bytes) =>
|
||||
composerRobot.addAttachmentFromBytes(bytes, 'test-attachment.png');
|
||||
|
||||
@override
|
||||
Future<void> waitForContentUploaded(AbstractComposerRobot composerRobot) =>
|
||||
waitForCondition(() {
|
||||
final controller = composerRobot.findComposerController();
|
||||
return controller?.uploadController.allAttachmentsUploaded.isNotEmpty ?? false;
|
||||
});
|
||||
}
|
||||
|
||||
mixin WithInlineImageContentMixin on BaseSaveAndReopenScenario {
|
||||
@override
|
||||
Future<void> attachContent(AbstractComposerRobot composerRobot, Uint8List bytes) =>
|
||||
composerRobot.addInlineFromBytes(bytes, 'test-inline.png');
|
||||
|
||||
@override
|
||||
Future<void> waitForContentUploaded(AbstractComposerRobot composerRobot) =>
|
||||
waitForCondition(() {
|
||||
final controller = composerRobot.findComposerController();
|
||||
return controller?.uploadController.inlineAttachmentsUploaded.isNotEmpty ?? false;
|
||||
});
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import 'base_save_draft_then_reopen_scenario.dart';
|
||||
import 'composer_content_mixins.dart';
|
||||
|
||||
class SaveDraftWithAttachmentThenOpenAndSaveDraftAgainScenario
|
||||
extends BaseSaveDraftThenReopenScenario with WithAttachmentContentMixin {
|
||||
const SaveDraftWithAttachmentThenOpenAndSaveDraftAgainScenario(super.$, super.robots);
|
||||
|
||||
@override
|
||||
String get subject => 'Draft with attachment - second save';
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import 'base_save_draft_then_reopen_scenario.dart';
|
||||
import 'composer_content_mixins.dart';
|
||||
|
||||
class SaveDraftWithInlineImageThenOpenAndSaveDraftAgainScenario
|
||||
extends BaseSaveDraftThenReopenScenario with WithInlineImageContentMixin {
|
||||
const SaveDraftWithInlineImageThenOpenAndSaveDraftAgainScenario(super.$, super.robots);
|
||||
|
||||
@override
|
||||
String get subject => 'Draft with inline image - second save';
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import 'base_save_template_then_reopen_scenario.dart';
|
||||
import 'composer_content_mixins.dart';
|
||||
|
||||
class SaveTemplateWithAttachmentThenOpenAndSaveTemplateAgainScenario
|
||||
extends BaseSaveTemplateThenReopenScenario with WithAttachmentContentMixin {
|
||||
const SaveTemplateWithAttachmentThenOpenAndSaveTemplateAgainScenario(super.$, super.robots);
|
||||
|
||||
@override
|
||||
String get subject => 'Template with attachment - second save';
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import 'base_save_template_then_reopen_scenario.dart';
|
||||
import 'composer_content_mixins.dart';
|
||||
|
||||
class SaveTemplateWithInlineImageThenOpenAndSaveTemplateAgainScenario
|
||||
extends BaseSaveTemplateThenReopenScenario with WithInlineImageContentMixin {
|
||||
const SaveTemplateWithInlineImageThenOpenAndSaveTemplateAgainScenario(super.$, super.robots);
|
||||
|
||||
@override
|
||||
String get subject => 'Template with inline image - second save';
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import '../../base/test_base.dart';
|
||||
import '../../models/test_tags.dart';
|
||||
import '../../scenarios/composer/save_draft_with_attachment_then_open_and_save_draft_again_scenario.dart';
|
||||
|
||||
void main() {
|
||||
TestBase().runPatrolTest(
|
||||
description: 'Should save draft successfully a second time '
|
||||
'after reopening a draft email that contains an attachment',
|
||||
scenarioBuilder: ($, robots) =>
|
||||
SaveDraftWithAttachmentThenOpenAndSaveDraftAgainScenario($, robots),
|
||||
tags: [TestTags.android, TestTags.ios, TestTags.web],
|
||||
);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import '../../base/test_base.dart';
|
||||
import '../../models/test_tags.dart';
|
||||
import '../../scenarios/composer/save_draft_with_inline_image_then_open_and_save_draft_again_scenario.dart';
|
||||
|
||||
void main() {
|
||||
TestBase().runPatrolTest(
|
||||
description: 'Should save draft successfully a second time '
|
||||
'after reopening a draft email that contains an inline image',
|
||||
scenarioBuilder: ($, robots) =>
|
||||
SaveDraftWithInlineImageThenOpenAndSaveDraftAgainScenario($, robots),
|
||||
tags: [TestTags.android, TestTags.ios, TestTags.web],
|
||||
);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import '../../base/test_base.dart';
|
||||
import '../../models/test_tags.dart';
|
||||
import '../../scenarios/composer/save_template_with_attachment_then_open_and_save_template_again_scenario.dart';
|
||||
|
||||
void main() {
|
||||
TestBase().runPatrolTest(
|
||||
description: 'Should save template successfully a second time '
|
||||
'after reopening a template email that contains an attachment',
|
||||
scenarioBuilder: ($, robots) =>
|
||||
SaveTemplateWithAttachmentThenOpenAndSaveTemplateAgainScenario($, robots),
|
||||
tags: [TestTags.android, TestTags.ios, TestTags.web],
|
||||
);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import '../../base/test_base.dart';
|
||||
import '../../models/test_tags.dart';
|
||||
import '../../scenarios/composer/save_template_with_inline_image_then_open_and_save_template_again_scenario.dart';
|
||||
|
||||
void main() {
|
||||
TestBase().runPatrolTest(
|
||||
description: 'Should save template successfully a second time '
|
||||
'after reopening a template email that contains an inline image',
|
||||
scenarioBuilder: ($, robots) =>
|
||||
SaveTemplateWithInlineImageThenOpenAndSaveTemplateAgainScenario($, robots),
|
||||
tags: [TestTags.android, TestTags.ios, TestTags.web],
|
||||
);
|
||||
}
|
||||
@@ -5,4 +5,10 @@ class UiKeys {
|
||||
static const String sendEmailButton = 'sendEmailButton';
|
||||
static const String listViewAppGrid = 'listViewAppGrid';
|
||||
static const String toggleAppGridButton = 'toggleAppGridButton';
|
||||
}
|
||||
static const String closeComposerButton = 'closeComposerButton';
|
||||
static const String saveDraftButton = 'saveDraftButton';
|
||||
static const String saveTemplatePopupItem = 'saveAsTemplatePopupItem';
|
||||
// Keep snake_case values — existing widgets and tests already reference these key names.
|
||||
static const String composerMoreButton = 'composer_more_button';
|
||||
static const String saveDraftPopupItem = 'save_as_draft_popup_item';
|
||||
}
|
||||
@@ -1,20 +1,27 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
|
||||
class UpdatingEmailDrafts extends LoadingState {}
|
||||
|
||||
class UpdateEmailDraftsSuccess extends UIState {
|
||||
|
||||
final EmailId emailId;
|
||||
final List<Attachment> attachments;
|
||||
final List<Attachment> htmlBodyAttachments;
|
||||
|
||||
UpdateEmailDraftsSuccess(this.emailId);
|
||||
UpdateEmailDraftsSuccess({
|
||||
required this.emailId,
|
||||
required this.attachments,
|
||||
this.htmlBodyAttachments = const [],
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [emailId, ...super.props];
|
||||
List<Object?> get props => [emailId, attachments, htmlBodyAttachments, ...super.props];
|
||||
}
|
||||
|
||||
class UpdateEmailDraftsFailure extends FeatureFailure {
|
||||
|
||||
UpdateEmailDraftsFailure(dynamic exception) : super(exception: exception);
|
||||
}
|
||||
}
|
||||
+136
-45
@@ -3,7 +3,11 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart' as dartz;
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/extensions/email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/exceptions/compose_email_exception.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/repository/composer_repository.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/generate_email_state.dart';
|
||||
@@ -12,6 +16,7 @@ import 'package:tmail_ui_user/features/composer/domain/state/update_email_drafts
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/create_email_request.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/mailbox_exception.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/remote/unknown_remote_exception.dart';
|
||||
|
||||
class CreateNewAndSaveEmailToDraftsInteractor {
|
||||
@@ -27,67 +32,153 @@ class CreateNewAndSaveEmailToDraftsInteractor {
|
||||
required CreateEmailRequest createEmailRequest,
|
||||
CancelToken? cancelToken,
|
||||
}) async* {
|
||||
final draftEmailId = createEmailRequest.draftsEmailId;
|
||||
final isCreatingNewDraft = draftEmailId == null;
|
||||
try {
|
||||
yield dartz.Right<Failure, Success>(GenerateEmailLoading());
|
||||
|
||||
final emailCreated = await _createEmailObject(createEmailRequest);
|
||||
if (emailCreated == null) {
|
||||
yield dartz.Left<Failure, Success>(
|
||||
GenerateEmailFailure(CannotCreateEmailObjectException()),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (emailCreated != null) {
|
||||
if (createEmailRequest.draftsEmailId == null) {
|
||||
yield dartz.Right<Failure, Success>(SaveEmailAsDraftsLoading());
|
||||
final draftPayload = (
|
||||
session: createEmailRequest.session,
|
||||
accountId: createEmailRequest.accountId,
|
||||
email: emailCreated,
|
||||
draftsMailboxId: createEmailRequest.draftsMailboxId,
|
||||
);
|
||||
|
||||
final emailDraftSaved = await _emailRepository.saveEmailAsDrafts(
|
||||
createEmailRequest.session,
|
||||
createEmailRequest.accountId,
|
||||
emailCreated,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
|
||||
yield dartz.Right<Failure, Success>(
|
||||
SaveEmailAsDraftsSuccess(
|
||||
emailDraftSaved.id!,
|
||||
createEmailRequest.draftsMailboxId,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
yield dartz.Right<Failure, Success>(UpdatingEmailDrafts());
|
||||
|
||||
final emailDraftSaved = await _emailRepository.updateEmailDrafts(
|
||||
createEmailRequest.session,
|
||||
createEmailRequest.accountId,
|
||||
emailCreated,
|
||||
createEmailRequest.draftsEmailId!,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
|
||||
yield dartz.Right<Failure, Success>(
|
||||
UpdateEmailDraftsSuccess(emailDraftSaved.id!)
|
||||
);
|
||||
}
|
||||
if (isCreatingNewDraft) {
|
||||
yield* _saveEmailAsDrafts(
|
||||
draftPayload: draftPayload,
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
} else {
|
||||
yield dartz.Left<Failure, Success>(GenerateEmailFailure(CannotCreateEmailObjectException()));
|
||||
yield* _updateDraftsEmail(
|
||||
draftPayload: draftPayload,
|
||||
draftsEmailId: draftEmailId,
|
||||
cancelToken: cancelToken,
|
||||
isUpdateDraftToClose: createEmailRequest.isUpdateDraftToClose,
|
||||
);
|
||||
}
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'CreateNewAndSaveEmailToDraftsInteractor::execute: exception=${e.runtimeType}',
|
||||
stackTrace: st,
|
||||
);
|
||||
if (e is UnknownRemoteException && e.error is List<SavingEmailToDraftsCanceledException>) {
|
||||
if (createEmailRequest.draftsEmailId == null) {
|
||||
yield dartz.Left<Failure, Success>(SaveEmailAsDraftsFailure(SavingEmailToDraftsCanceledException()));
|
||||
} else {
|
||||
yield dartz.Left<Failure, Success>(UpdateEmailDraftsFailure(SavingEmailToDraftsCanceledException()));
|
||||
}
|
||||
} else {
|
||||
if (createEmailRequest.draftsEmailId == null) {
|
||||
yield dartz.Left<Failure, Success>(SaveEmailAsDraftsFailure(e));
|
||||
} else {
|
||||
yield dartz.Left<Failure, Success>(UpdateEmailDraftsFailure(e));
|
||||
}
|
||||
}
|
||||
yield* _handleFailure(exception: e, isCreatingNewDraft: isCreatingNewDraft);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<dartz.Either<Failure, Success>> _saveEmailAsDrafts({
|
||||
required ({
|
||||
AccountId accountId,
|
||||
MailboxId? draftsMailboxId,
|
||||
Email email,
|
||||
Session session,
|
||||
}) draftPayload,
|
||||
CancelToken? cancelToken,
|
||||
}) async* {
|
||||
try {
|
||||
yield dartz.Right<Failure, Success>(SaveEmailAsDraftsLoading());
|
||||
|
||||
final emailDraftSaved = await _emailRepository.saveEmailAsDrafts(
|
||||
draftPayload.session,
|
||||
draftPayload.accountId,
|
||||
draftPayload.email,
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
|
||||
final newEmailId = emailDraftSaved.id;
|
||||
|
||||
if (newEmailId == null) {
|
||||
yield dartz.Left<Failure, Success>(
|
||||
SaveEmailAsDraftsFailure(NotFoundEmailIdException()),
|
||||
);
|
||||
} else {
|
||||
yield dartz.Right<Failure, Success>(
|
||||
SaveEmailAsDraftsSuccess(
|
||||
newEmailId,
|
||||
draftPayload.draftsMailboxId,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'CreateNewAndSaveEmailToDraftsInteractor::_saveEmailAsDrafts: exception=${e.runtimeType}',
|
||||
stackTrace: st,
|
||||
);
|
||||
yield* _handleFailure(exception: e, isCreatingNewDraft: true);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<dartz.Either<Failure, Success>> _updateDraftsEmail({
|
||||
required ({
|
||||
AccountId accountId,
|
||||
MailboxId? draftsMailboxId,
|
||||
Session session,
|
||||
Email email,
|
||||
}) draftPayload,
|
||||
required EmailId draftsEmailId,
|
||||
CancelToken? cancelToken,
|
||||
bool isUpdateDraftToClose = false,
|
||||
}) async* {
|
||||
try {
|
||||
yield dartz.Right<Failure, Success>(UpdatingEmailDrafts());
|
||||
|
||||
final emailDraftSaved = await _emailRepository.updateEmailDrafts(
|
||||
draftPayload.session,
|
||||
draftPayload.accountId,
|
||||
draftPayload.email,
|
||||
draftsEmailId,
|
||||
cancelToken: cancelToken,
|
||||
isUpdateDraftToClose: isUpdateDraftToClose,
|
||||
);
|
||||
|
||||
final newEmailId = emailDraftSaved.id;
|
||||
|
||||
if (newEmailId == null) {
|
||||
yield dartz.Left<Failure, Success>(
|
||||
UpdateEmailDraftsFailure(NotFoundEmailIdException()),
|
||||
);
|
||||
} else {
|
||||
yield dartz.Right<Failure, Success>(
|
||||
UpdateEmailDraftsSuccess(
|
||||
emailId: newEmailId,
|
||||
attachments: emailDraftSaved.allAttachments,
|
||||
htmlBodyAttachments: emailDraftSaved.htmlBodyAttachments,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'CreateNewAndSaveEmailToDraftsInteractor::_updateDraftsEmail: exception=${e.runtimeType}',
|
||||
stackTrace: st,
|
||||
);
|
||||
yield* _handleFailure(exception: e, isCreatingNewDraft: false);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<dartz.Either<Failure, Success>> _handleFailure({
|
||||
required Object? exception,
|
||||
required bool isCreatingNewDraft,
|
||||
}) async* {
|
||||
final resolvedEx = (exception is UnknownRemoteException &&
|
||||
exception.error is List<SavingEmailToDraftsCanceledException>)
|
||||
? SavingEmailToDraftsCanceledException()
|
||||
: exception;
|
||||
|
||||
yield dartz.Left<Failure, Success>(
|
||||
isCreatingNewDraft
|
||||
? SaveEmailAsDraftsFailure(resolvedEx)
|
||||
: UpdateEmailDraftsFailure(resolvedEx),
|
||||
);
|
||||
}
|
||||
|
||||
Future<Email?> _createEmailObject(CreateEmailRequest createEmailRequest) async {
|
||||
try {
|
||||
final emailCreated = await _composerRepository.generateEmail(
|
||||
|
||||
@@ -59,6 +59,7 @@ import 'package:tmail_ui_user/features/composer/domain/usecases/save_composer_ca
|
||||
import 'package:tmail_ui_user/features/composer/presentation/controller/rich_text_mobile_tablet_controller.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/controller/rich_text_web_controller.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/handle_mobile_auto_save_extension.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/refresh_composer_attachments_extension.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/attachment_detection_extension.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/auto_create_tag_for_recipients_extension.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/get_draft_mailbox_id_for_composer_extension.dart';
|
||||
@@ -1357,6 +1358,7 @@ class ComposerController extends BaseController
|
||||
_saveToDraftButtonState = ButtonState.enabled;
|
||||
emailIdEditing = resultState.emailId;
|
||||
mailboxDashBoardController.consumeState(Stream.value(Right<Failure, Success>(resultState)));
|
||||
autoRefreshAllAttachments(resultState.attachments, resultState.htmlBodyAttachments);
|
||||
_updateSavedEmailDraftHash();
|
||||
} else if ((resultState is SaveEmailAsDraftsFailure && resultState.exception is SavingEmailToDraftsCanceledException) ||
|
||||
(resultState is UpdateEmailDraftsFailure && resultState.exception is SavingEmailToDraftsCanceledException)) {
|
||||
@@ -1440,6 +1442,7 @@ class ComposerController extends BaseController
|
||||
);
|
||||
} else if (resultState is UpdateTemplateEmailSuccess && context.mounted == true) {
|
||||
currentTemplateEmailId = resultState.emailId;
|
||||
autoRefreshAllAttachments(resultState.attachments, resultState.htmlBodyAttachments);
|
||||
appToast.showToastSuccessMessage(
|
||||
context,
|
||||
AppLocalizations.of(context).updateMessageToTemplateSuccess,
|
||||
@@ -2148,7 +2151,8 @@ class ComposerController extends BaseController
|
||||
emailContent: emailContent,
|
||||
uploadUri: uploadUri,
|
||||
draftEmailId: draftEmailId,
|
||||
cancelToken: cancelToken
|
||||
cancelToken: cancelToken,
|
||||
isUpdateDraftToClose: true,
|
||||
);
|
||||
|
||||
if (resultState is SaveEmailAsDraftsSuccess || resultState is UpdateEmailDraftsSuccess) {
|
||||
@@ -2196,6 +2200,7 @@ class ComposerController extends BaseController
|
||||
required Uri? uploadUri,
|
||||
EmailId? draftEmailId,
|
||||
CancelToken? cancelToken,
|
||||
bool isUpdateDraftToClose = false,
|
||||
}) {
|
||||
final childWidget = PointerInterceptor(
|
||||
child: SavingMessageDialogView(
|
||||
@@ -2226,6 +2231,7 @@ class ComposerController extends BaseController
|
||||
emailSendingQueue: arguments.sendingEmail,
|
||||
displayMode: screenDisplayMode.value,
|
||||
uploadUri: uploadUri,
|
||||
isUpdateDraftToClose: isUpdateDraftToClose,
|
||||
),
|
||||
createNewAndSaveEmailToDraftsInteractor: _createNewAndSaveEmailToDraftsInteractor,
|
||||
onCancelSavingEmailToDraftsAction: _handleCancelSavingMessageToDrafts,
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:model/extensions/list_attachment_extension.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/composer_controller.dart';
|
||||
|
||||
extension RefreshComposerAttachmentsExtension on ComposerController {
|
||||
void autoRefreshAllAttachments(
|
||||
List<Attachment> attachments,
|
||||
List<Attachment> htmlBodyAttachments,
|
||||
) {
|
||||
// If server returned no attachments but the composer still shows attachments,
|
||||
// Email/get likely fell back to the Set response which lacks attachment data.
|
||||
// Skip the refresh to avoid clearing the UI.
|
||||
// Use current upload state (not initialAttachments) so removing all attachments
|
||||
// before saving correctly updates initialAttachments to empty.
|
||||
if (attachments.isEmpty &&
|
||||
(uploadController.attachmentsUploaded.isNotEmpty ||
|
||||
uploadController.inlineAttachmentsUploaded.isNotEmpty)) {
|
||||
log('RefreshComposerAttachmentsExtension::autoRefreshAllAttachments: skipping — empty server response with non-empty composer state');
|
||||
return;
|
||||
}
|
||||
|
||||
initialAttachments = attachments.getListAttachmentsDisplayedOutside(htmlBodyAttachments);
|
||||
uploadController.refreshAllAttachments(attachments, htmlBodyAttachments);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tmail_ui_user/features/base/model/ui_keys.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
enum ComposerActionType {
|
||||
@@ -65,9 +66,9 @@ enum ComposerActionType {
|
||||
case ComposerActionType.requestReadReceipt:
|
||||
return const Key('read_receipt_popup_item');
|
||||
case ComposerActionType.saveAsDraft:
|
||||
return const Key('save_as_draft_popup_item');
|
||||
return const Key(UiKeys.saveDraftPopupItem);
|
||||
case ComposerActionType.saveAsTemplate:
|
||||
return const Key('save_as_template_popup_item');
|
||||
return const Key(UiKeys.saveTemplatePopupItem);
|
||||
case ComposerActionType.delete:
|
||||
return const Key('delete_popup_item');
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ class CreateEmailRequest with EquatableMixin {
|
||||
final EmailActionType? savedActionType;
|
||||
final EmailId? savedEmailDraftId;
|
||||
final List<KeyWordIdentifier>? keywords;
|
||||
final bool isUpdateDraftToClose;
|
||||
|
||||
CreateEmailRequest({
|
||||
required this.session,
|
||||
@@ -86,6 +87,7 @@ class CreateEmailRequest with EquatableMixin {
|
||||
this.savedActionType,
|
||||
this.savedEmailDraftId,
|
||||
this.keywords,
|
||||
this.isUpdateDraftToClose = false,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -125,5 +127,6 @@ class CreateEmailRequest with EquatableMixin {
|
||||
savedActionType,
|
||||
savedEmailDraftId,
|
||||
keywords,
|
||||
isUpdateDraftToClose,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ class AppBarComposerWidget extends StatelessWidget {
|
||||
child: Row(
|
||||
children: [
|
||||
TMailButtonWidget.fromIcon(
|
||||
key: const Key(UiKeys.closeComposerButton),
|
||||
icon: imagePaths.icCancel,
|
||||
backgroundColor: Colors.transparent,
|
||||
tooltipMessage: AppLocalizations.of(context).saveAndClose,
|
||||
@@ -105,7 +106,7 @@ class AppBarComposerWidget extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: MobileAppBarComposerWidgetStyle.space),
|
||||
TMailButtonWidget.fromIcon(
|
||||
key: const Key('composer_more_button'),
|
||||
key: const Key(UiKeys.composerMoreButton),
|
||||
icon: imagePaths.icMore,
|
||||
iconColor: MobileAppBarComposerWidgetStyle.iconColor,
|
||||
backgroundColor: Colors.transparent,
|
||||
|
||||
+2
@@ -46,6 +46,7 @@ class LandscapeAppBarComposerWidget extends StatelessWidget {
|
||||
child: Row(
|
||||
children: [
|
||||
TMailButtonWidget.fromIcon(
|
||||
key: const Key(UiKeys.closeComposerButton),
|
||||
icon: imagePaths.icCancel,
|
||||
backgroundColor: Colors.transparent,
|
||||
tooltipMessage: AppLocalizations.of(context).saveAndClose,
|
||||
@@ -107,6 +108,7 @@ class LandscapeAppBarComposerWidget extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: MobileAppBarComposerWidgetStyle.space),
|
||||
TMailButtonWidget.fromIcon(
|
||||
key: const Key(UiKeys.composerMoreButton),
|
||||
icon: imagePaths.icMore,
|
||||
iconColor: MobileAppBarComposerWidgetStyle.iconColor,
|
||||
backgroundColor: Colors.transparent,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/presentation/views/button/tmail_button_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tmail_ui_user/features/base/model/ui_keys.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/screen_display_mode.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/styles/app_bar_composer_widget_style.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/widgets/title_composer_widget.dart';
|
||||
@@ -72,6 +73,7 @@ class TabletAppBarComposerWidget extends StatelessWidget {
|
||||
const SizedBox(width: AppBarComposerWidgetStyle.space),
|
||||
],
|
||||
TMailButtonWidget.fromIcon(
|
||||
key: const Key(UiKeys.closeComposerButton),
|
||||
icon: imagePaths.icCancel,
|
||||
backgroundColor: Colors.transparent,
|
||||
tooltipMessage: AppLocalizations.of(context).saveAndClose,
|
||||
|
||||
@@ -149,6 +149,7 @@ class BottomBarComposerWidget extends StatelessWidget {
|
||||
PopupMenuOverlayWidget(
|
||||
controller: menuMoreOptionController,
|
||||
iconButton: HighlightSVGIconOnHover(
|
||||
key: const Key(UiKeys.composerMoreButton),
|
||||
icon: imagePaths.icMore,
|
||||
size: BottomBarComposerWidgetStyle.iconSize,
|
||||
iconColor: BottomBarComposerWidgetStyle.iconColor,
|
||||
@@ -207,6 +208,7 @@ class BottomBarComposerWidget extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
PopupItemWidget(
|
||||
key: const Key(UiKeys.saveTemplatePopupItem),
|
||||
iconAction: imagePaths.icSaveToDraft,
|
||||
nameAction: AppLocalizations.of(context).saveAsTemplate,
|
||||
colorIcon: BottomBarComposerWidgetStyle.iconColor,
|
||||
@@ -235,6 +237,7 @@ class BottomBarComposerWidget extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: BottomBarComposerWidgetStyle.space),
|
||||
TMailButtonWidget.fromIcon(
|
||||
key: const Key(UiKeys.saveDraftButton),
|
||||
icon: imagePaths.icSaveToDraft,
|
||||
borderRadius: BottomBarComposerWidgetStyle.iconRadius,
|
||||
padding: BottomBarComposerWidgetStyle.iconPadding,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/presentation/views/button/tmail_button_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tmail_ui_user/features/base/model/ui_keys.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/screen_display_mode.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/styles/app_bar_composer_widget_style.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/widgets/web/minimize_composer_widget.dart';
|
||||
@@ -64,6 +65,7 @@ class DesktopAppBarComposerWidget extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: AppBarComposerWidgetStyle.space),
|
||||
TMailButtonWidget.fromIcon(
|
||||
key: const Key(UiKeys.closeComposerButton),
|
||||
icon: imagePaths.icCancel,
|
||||
backgroundColor: Colors.transparent,
|
||||
tooltipMessage: AppLocalizations.of(context).saveAndClose,
|
||||
@@ -75,6 +77,7 @@ class DesktopAppBarComposerWidget extends StatelessWidget {
|
||||
]
|
||||
else
|
||||
TMailButtonWidget.fromIcon(
|
||||
key: const Key(UiKeys.closeComposerButton),
|
||||
icon: imagePaths.icCancel,
|
||||
backgroundColor: Colors.transparent,
|
||||
tooltipMessage: AppLocalizations.of(context).saveAndClose,
|
||||
|
||||
+3
@@ -70,6 +70,7 @@ class MobileResponsiveAppBarComposerWidget extends StatelessWidget {
|
||||
child: Row(
|
||||
children: [
|
||||
TMailButtonWidget.fromIcon(
|
||||
key: const Key(UiKeys.closeComposerButton),
|
||||
icon: imagePaths.icCancel,
|
||||
backgroundColor: Colors.transparent,
|
||||
tooltipMessage: AppLocalizations.of(context).saveAndClose,
|
||||
@@ -192,6 +193,7 @@ class MobileResponsiveAppBarComposerWidget extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
PopupItemWidget(
|
||||
key: const Key(UiKeys.saveDraftPopupItem),
|
||||
iconAction: imagePaths.icSaveToDraft,
|
||||
nameAction: AppLocalizations.of(context).saveAsDraft,
|
||||
colorIcon: MobileAppBarComposerWidgetStyle.popupItemIconColor,
|
||||
@@ -203,6 +205,7 @@ class MobileResponsiveAppBarComposerWidget extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
PopupItemWidget(
|
||||
key: const Key(UiKeys.saveTemplatePopupItem),
|
||||
iconAction: imagePaths.icSaveToDraft,
|
||||
nameAction: AppLocalizations.of(context).saveAsTemplate,
|
||||
colorIcon: MobileAppBarComposerWidgetStyle.popupItemIconColor,
|
||||
|
||||
@@ -99,7 +99,10 @@ abstract class EmailDataSource {
|
||||
AccountId accountId,
|
||||
Email newEmail,
|
||||
EmailId oldEmailId,
|
||||
{CancelToken? cancelToken}
|
||||
{
|
||||
CancelToken? cancelToken,
|
||||
bool isUpdateDraftToClose = false,
|
||||
}
|
||||
);
|
||||
|
||||
Future<Email> saveEmailAsTemplate(
|
||||
|
||||
@@ -193,7 +193,10 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
AccountId accountId,
|
||||
Email newEmail,
|
||||
EmailId oldEmailId,
|
||||
{CancelToken? cancelToken}
|
||||
{
|
||||
CancelToken? cancelToken,
|
||||
bool isUpdateDraftToClose = false,
|
||||
}
|
||||
) {
|
||||
return Future.sync(() async {
|
||||
return await emailAPI.updateEmailDrafts(
|
||||
@@ -201,7 +204,8 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
accountId,
|
||||
newEmail,
|
||||
oldEmailId,
|
||||
cancelToken: cancelToken
|
||||
cancelToken: cancelToken,
|
||||
isUpdateDraftToClose: isUpdateDraftToClose,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@@ -327,7 +327,10 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
AccountId accountId,
|
||||
Email newEmail,
|
||||
EmailId oldEmailId,
|
||||
{CancelToken? cancelToken}
|
||||
{
|
||||
CancelToken? cancelToken,
|
||||
bool isUpdateDraftToClose = false,
|
||||
}
|
||||
) async {
|
||||
await _emailCacheManager.update(
|
||||
accountId,
|
||||
|
||||
@@ -202,7 +202,7 @@ class EmailLocalStorageDataSourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> updateEmailDrafts(Session session, AccountId accountId, Email newEmail, EmailId oldEmailId, {CancelToken? cancelToken}) {
|
||||
Future<Email> updateEmailDrafts(Session session, AccountId accountId, Email newEmail, EmailId oldEmailId, {CancelToken? cancelToken, bool isUpdateDraftToClose = false}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ class EmailSessionStorageDatasourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> updateEmailDrafts(Session session, AccountId accountId, Email newEmail, EmailId oldEmailId, {CancelToken? cancelToken}) {
|
||||
Future<Email> updateEmailDrafts(Session session, AccountId accountId, Email newEmail, EmailId oldEmailId, {CancelToken? cancelToken, bool isUpdateDraftToClose = false}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ import 'package:tmail_ui_user/features/download/domain/state/download_attachment
|
||||
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/move_to_mailbox_request.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/restore_deleted_message_request.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/mailbox_exception.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_request.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/constants/thread_constants.dart';
|
||||
import 'package:tmail_ui_user/main/error/capability_validator.dart';
|
||||
@@ -84,6 +85,41 @@ class EmailAPI
|
||||
|
||||
EmailAPI(this._httpClient, this._downloadManager, this._dioClient, this._uuid);
|
||||
|
||||
Future<Email> getEmailMetadata(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
Properties properties,
|
||||
) async {
|
||||
final processingInvocation = ProcessingInvocation();
|
||||
final jmapRequestBuilder = JmapRequestBuilder(_httpClient, processingInvocation);
|
||||
|
||||
final getEmailMethod = GetEmailMethod(accountId)
|
||||
..addIds({emailId.id})
|
||||
..addProperties(properties);
|
||||
|
||||
final getEmailInvocation = jmapRequestBuilder.invocation(getEmailMethod);
|
||||
|
||||
final capabilities = getEmailMethod.requiredCapabilities
|
||||
.toCapabilitiesSupportTeamMailboxes(session, accountId);
|
||||
|
||||
final result = await (jmapRequestBuilder
|
||||
..usings(capabilities))
|
||||
.build()
|
||||
.execute();
|
||||
|
||||
final resultList = result.parse<GetEmailResponse>(
|
||||
getEmailInvocation.methodCallId,
|
||||
GetEmailResponse.deserialize,
|
||||
);
|
||||
|
||||
if (resultList?.list.isNotEmpty == true) {
|
||||
return resultList!.list.first;
|
||||
} else {
|
||||
throw NotFoundEmailException();
|
||||
}
|
||||
}
|
||||
|
||||
Future<Email> getEmailContent(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
@@ -585,27 +621,27 @@ class EmailAPI
|
||||
AccountId accountId,
|
||||
Email newEmail,
|
||||
EmailId oldEmailId,
|
||||
{CancelToken? cancelToken}
|
||||
{
|
||||
CancelToken? cancelToken,
|
||||
bool isUpdateDraftToClose = false,
|
||||
}
|
||||
) async {
|
||||
final emailCreated = await saveEmailAsDrafts(
|
||||
session,
|
||||
accountId,
|
||||
newEmail,
|
||||
cancelToken: cancelToken
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
return _postSaveEmailProcessing(
|
||||
savedEmail: emailCreated,
|
||||
removeOldEmail: () => removeEmailDrafts(
|
||||
session, accountId, oldEmailId, cancelToken: cancelToken,
|
||||
),
|
||||
callerTag: 'EmailAPI::updateEmailDrafts',
|
||||
session: session,
|
||||
accountId: accountId,
|
||||
skipMetadataFetch: isUpdateDraftToClose,
|
||||
);
|
||||
|
||||
try {
|
||||
await removeEmailDrafts(
|
||||
session,
|
||||
accountId,
|
||||
oldEmailId,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
} catch (e) {
|
||||
logWarning('EmailAPI::updateEmailDrafts: Exception = $e');
|
||||
}
|
||||
|
||||
return emailCreated;
|
||||
}
|
||||
|
||||
Future<Email> saveEmailAsTemplate(
|
||||
@@ -614,7 +650,7 @@ class EmailAPI
|
||||
Email email,
|
||||
{
|
||||
CreateNewMailboxRequest? createNewMailboxRequest,
|
||||
CancelToken? cancelToken
|
||||
CancelToken? cancelToken,
|
||||
}
|
||||
) => _emailSetCreateMethod(session, accountId, email, createNewMailboxRequest: createNewMailboxRequest, cancelToken: cancelToken);
|
||||
|
||||
@@ -636,21 +672,50 @@ class EmailAPI
|
||||
session,
|
||||
accountId,
|
||||
newEmail,
|
||||
cancelToken: cancelToken
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
return _postSaveEmailProcessing(
|
||||
savedEmail: emailCreated,
|
||||
removeOldEmail: () => removeEmailTemplate(
|
||||
session, accountId, oldEmailId, cancelToken: cancelToken,
|
||||
),
|
||||
callerTag: 'EmailAPI::updateEmailTemplate',
|
||||
session: session,
|
||||
accountId: accountId,
|
||||
);
|
||||
}
|
||||
|
||||
Future<Email> _postSaveEmailProcessing({
|
||||
required Email savedEmail,
|
||||
required Future<void> Function() removeOldEmail,
|
||||
required String callerTag,
|
||||
required Session session,
|
||||
required AccountId accountId,
|
||||
bool skipMetadataFetch = false,
|
||||
}) async {
|
||||
final emailId = savedEmail.id;
|
||||
if (emailId == null) throw NotFoundEmailIdException();
|
||||
|
||||
try {
|
||||
await removeEmailTemplate(
|
||||
session,
|
||||
accountId,
|
||||
oldEmailId,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
await removeOldEmail();
|
||||
} catch (e) {
|
||||
logWarning('EmailAPI::updateEmailTemplate: Exception = $e');
|
||||
logWarning('$callerTag: remove old email exception = $e');
|
||||
}
|
||||
|
||||
return emailCreated;
|
||||
if (!skipMetadataFetch) {
|
||||
try {
|
||||
return await getEmailMetadata(
|
||||
session,
|
||||
accountId,
|
||||
emailId,
|
||||
ThreadConstants.propertiesComposerEmailFetch,
|
||||
);
|
||||
} catch (e) {
|
||||
logWarning('$callerTag: getEmailMetadata exception = $e');
|
||||
}
|
||||
}
|
||||
|
||||
return savedEmail;
|
||||
}
|
||||
|
||||
Future<({
|
||||
|
||||
@@ -279,14 +279,18 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
AccountId accountId,
|
||||
Email newEmail,
|
||||
EmailId oldEmailId,
|
||||
{CancelToken? cancelToken}
|
||||
{
|
||||
CancelToken? cancelToken,
|
||||
bool isUpdateDraftToClose = false,
|
||||
}
|
||||
) async {
|
||||
final result = await emailDataSource[DataSourceType.network]!.updateEmailDrafts(
|
||||
session,
|
||||
accountId,
|
||||
newEmail,
|
||||
oldEmailId,
|
||||
cancelToken: cancelToken
|
||||
cancelToken: cancelToken,
|
||||
isUpdateDraftToClose: isUpdateDraftToClose,
|
||||
);
|
||||
try {
|
||||
await emailDataSource[DataSourceType.hiveCache]!.updateEmailDrafts(
|
||||
@@ -294,6 +298,7 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
accountId,
|
||||
result,
|
||||
oldEmailId,
|
||||
isUpdateDraftToClose: isUpdateDraftToClose,
|
||||
);
|
||||
} catch (e) {
|
||||
logWarning('EmailRepositoryImpl::updateEmailDrafts:exception $e');
|
||||
|
||||
@@ -94,7 +94,10 @@ abstract class EmailRepository {
|
||||
AccountId accountId,
|
||||
Email newEmail,
|
||||
EmailId oldEmailId,
|
||||
{CancelToken? cancelToken}
|
||||
{
|
||||
CancelToken? cancelToken,
|
||||
bool isUpdateDraftToClose = false,
|
||||
}
|
||||
);
|
||||
|
||||
Future<Email> saveEmailAsTemplate(
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
|
||||
class UpdatingTemplateEmail extends LoadingState {}
|
||||
|
||||
class UpdateTemplateEmailSuccess extends UIState {
|
||||
UpdateTemplateEmailSuccess(this.emailId);
|
||||
|
||||
final EmailId emailId;
|
||||
final List<Attachment> attachments;
|
||||
final List<Attachment> htmlBodyAttachments;
|
||||
|
||||
UpdateTemplateEmailSuccess({
|
||||
required this.emailId,
|
||||
required this.attachments,
|
||||
this.htmlBodyAttachments = const [],
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [emailId];
|
||||
List<Object?> get props => [emailId, attachments, htmlBodyAttachments, ...super.props];
|
||||
}
|
||||
|
||||
class UpdateTemplateEmailFailure extends FeatureFailure {
|
||||
|
||||
@@ -3,7 +3,10 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/extensions/email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/repository/composer_repository.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/generate_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/create_email_request.dart';
|
||||
@@ -11,6 +14,7 @@ import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/save_template_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/update_template_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/mailbox_exception.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_request.dart';
|
||||
|
||||
class SaveTemplateEmailInteractor {
|
||||
@@ -27,57 +31,121 @@ class SaveTemplateEmailInteractor {
|
||||
required CreateNewMailboxRequest? createNewMailboxRequest,
|
||||
CancelToken? cancelToken,
|
||||
}) async* {
|
||||
yield Right(GenerateEmailLoading());
|
||||
|
||||
final templateEmailId = createEmailRequest.templateEmailId;
|
||||
final isCreatingNewTemplate = templateEmailId == null;
|
||||
try {
|
||||
final emailCreated = await _createEmailObject(createEmailRequest);
|
||||
yield Right(GenerateEmailLoading());
|
||||
|
||||
final emailCreated = await _createEmailObject(createEmailRequest);
|
||||
if (emailCreated == null) {
|
||||
yield Left(GenerateEmailFailure(CannotCreateEmailObjectException()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (createEmailRequest.templateEmailId != null) {
|
||||
yield Right(UpdatingTemplateEmail());
|
||||
final emailTemplateSaved = await _emailRepository.updateEmailTemplate(
|
||||
createEmailRequest.session,
|
||||
createEmailRequest.accountId,
|
||||
emailCreated,
|
||||
createEmailRequest.templateEmailId!,
|
||||
final payload = (
|
||||
session: createEmailRequest.session,
|
||||
accountId: createEmailRequest.accountId,
|
||||
email: emailCreated,
|
||||
);
|
||||
|
||||
if (!isCreatingNewTemplate) {
|
||||
yield* _updateTemplateEmail(
|
||||
payload: payload,
|
||||
templateEmailId: templateEmailId,
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
yield Right(UpdateTemplateEmailSuccess(emailTemplateSaved.id!));
|
||||
} else {
|
||||
yield Right(SavingTemplateEmail());
|
||||
final emailTemplateSaved = await _emailRepository.saveEmailAsTemplate(
|
||||
createEmailRequest.session,
|
||||
createEmailRequest.accountId,
|
||||
emailCreated,
|
||||
yield* _saveEmailAsTemplate(
|
||||
payload: payload,
|
||||
createNewMailboxRequest: createNewMailboxRequest,
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
yield Right(SaveTemplateEmailSuccess(emailTemplateSaved.id!));
|
||||
}
|
||||
} catch (e) {
|
||||
logWarning('SaveTemplateEmailInteractor::execute(): $e');
|
||||
if (createEmailRequest.templateEmailId != null) {
|
||||
yield Left(UpdateTemplateEmailFailure(exception: e));
|
||||
} else {
|
||||
yield Left(SaveTemplateEmailFailure(exception: e));
|
||||
}
|
||||
yield _buildFailure(exception: e, isCreatingNewTemplate: isCreatingNewTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<Either<Failure, Success>> _saveEmailAsTemplate({
|
||||
required ({Session session, AccountId accountId, Email email}) payload,
|
||||
required CreateNewMailboxRequest? createNewMailboxRequest,
|
||||
CancelToken? cancelToken,
|
||||
}) async* {
|
||||
try {
|
||||
yield Right(SavingTemplateEmail());
|
||||
|
||||
final emailSaved = await _emailRepository.saveEmailAsTemplate(
|
||||
payload.session,
|
||||
payload.accountId,
|
||||
payload.email,
|
||||
createNewMailboxRequest: createNewMailboxRequest,
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
|
||||
final newEmailId = emailSaved.id;
|
||||
if (newEmailId == null) {
|
||||
yield Left(SaveTemplateEmailFailure(exception: NotFoundEmailIdException()));
|
||||
} else {
|
||||
yield Right(SaveTemplateEmailSuccess(newEmailId));
|
||||
}
|
||||
} catch (e) {
|
||||
logWarning('SaveTemplateEmailInteractor::_saveEmailAsTemplate(): $e');
|
||||
yield _buildFailure(exception: e, isCreatingNewTemplate: true);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<Either<Failure, Success>> _updateTemplateEmail({
|
||||
required ({Session session, AccountId accountId, Email email}) payload,
|
||||
required EmailId templateEmailId,
|
||||
CancelToken? cancelToken,
|
||||
}) async* {
|
||||
try {
|
||||
yield Right(UpdatingTemplateEmail());
|
||||
|
||||
final emailSaved = await _emailRepository.updateEmailTemplate(
|
||||
payload.session,
|
||||
payload.accountId,
|
||||
payload.email,
|
||||
templateEmailId,
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
|
||||
final updatedEmailId = emailSaved.id;
|
||||
if (updatedEmailId == null) {
|
||||
yield Left(UpdateTemplateEmailFailure(exception: NotFoundEmailIdException()));
|
||||
} else {
|
||||
yield Right(UpdateTemplateEmailSuccess(
|
||||
emailId: updatedEmailId,
|
||||
attachments: emailSaved.allAttachments,
|
||||
htmlBodyAttachments: emailSaved.htmlBodyAttachments,
|
||||
));
|
||||
}
|
||||
} catch (e) {
|
||||
logWarning('SaveTemplateEmailInteractor::_updateTemplateEmail(): $e');
|
||||
yield _buildFailure(exception: e, isCreatingNewTemplate: false);
|
||||
}
|
||||
}
|
||||
|
||||
Either<Failure, Success> _buildFailure({
|
||||
required Object? exception,
|
||||
required bool isCreatingNewTemplate,
|
||||
}) => Left(
|
||||
!isCreatingNewTemplate
|
||||
? UpdateTemplateEmailFailure(exception: exception)
|
||||
: SaveTemplateEmailFailure(exception: exception),
|
||||
);
|
||||
|
||||
Future<Email?> _createEmailObject(CreateEmailRequest createEmailRequest) async {
|
||||
try {
|
||||
final emailCreated = await _composerRepository.generateEmail(
|
||||
return await _composerRepository.generateEmail(
|
||||
createEmailRequest,
|
||||
withIdentityHeader: true,
|
||||
isTemplate: true);
|
||||
return emailCreated;
|
||||
isTemplate: true,
|
||||
);
|
||||
} catch (e) {
|
||||
logWarning('CreateNewAndSaveEmailToDraftsInteractor::_createEmailObject: Exception: $e');
|
||||
logWarning('SaveTemplateEmailInteractor::_createEmailObject(): $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,4 +97,12 @@ class ThreadConstants {
|
||||
EmailProperty.messageId,
|
||||
EmailProperty.references,
|
||||
});
|
||||
}
|
||||
|
||||
static final propertiesComposerEmailFetch = Properties({
|
||||
EmailProperty.id,
|
||||
EmailProperty.blobId,
|
||||
EmailProperty.threadId,
|
||||
EmailProperty.htmlBody,
|
||||
EmailProperty.attachments,
|
||||
});
|
||||
}
|
||||
+1
-1
@@ -51,7 +51,7 @@ extension ThreadDetailOnSelectedEmailUpdated on ThreadDetailController {
|
||||
return;
|
||||
}
|
||||
|
||||
if (PlatformInfo.isWeb) {
|
||||
if (PlatformInfo.isWeb && currentExpandedEmailId.value != null) {
|
||||
mailboxDashBoardController.dispatchEmailUIAction(
|
||||
DisposePreviousExpandedEmailAction(
|
||||
currentExpandedEmailId.value!,
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:model/extensions/attachment_extension.dart';
|
||||
import 'package:model/extensions/list_attachment_extension.dart';
|
||||
import 'package:model/upload/file_info.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/message_dialog_action_manager.dart';
|
||||
@@ -473,6 +474,32 @@ class UploadController extends BaseController {
|
||||
...inlineAttachmentsUploaded,
|
||||
];
|
||||
|
||||
void refreshAllAttachments(
|
||||
List<Attachment> attachments,
|
||||
List<Attachment> htmlBodyAttachments,
|
||||
) {
|
||||
final regularAttachments = attachments.getListAttachmentsDisplayedOutside(htmlBodyAttachments);
|
||||
final inlineAttachments = attachments.listAttachmentsDisplayedInContent;
|
||||
|
||||
_uploadingStateFiles.clear();
|
||||
_uploadingStateFiles.addAll(_toUploadFileStates(regularAttachments));
|
||||
|
||||
_uploadingStateInlineFiles.clear();
|
||||
_uploadingStateInlineFiles.addAll(_toUploadFileStates(inlineAttachments));
|
||||
|
||||
_refreshListUploadAttachmentState();
|
||||
log('UploadController::refreshAllAttachments(): regular=${regularAttachments.length} | inline=${inlineAttachments.length}');
|
||||
}
|
||||
|
||||
Iterable<UploadFileState> _toUploadFileStates(List<Attachment> attachments) =>
|
||||
attachments
|
||||
.where((a) => a.blobId != null)
|
||||
.map((a) => UploadFileState(
|
||||
UploadTaskId(a.blobId!.value),
|
||||
uploadStatus: UploadFileStatus.succeed,
|
||||
attachment: a,
|
||||
));
|
||||
|
||||
void _handleUploadAttachmentFailure(UploadAttachmentFailure failure) {
|
||||
if (currentContext != null && currentOverlayContext != null) {
|
||||
appToast.showToastErrorMessage(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/model/upload_task_id.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/model/upload_file_state.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/model/upload_file_status.dart';
|
||||
@@ -49,8 +50,7 @@ class UploadFileStateList {
|
||||
return false;
|
||||
}
|
||||
return _uploadingStateFiles
|
||||
.nonNulls
|
||||
.every((file) => file.uploadStatus == UploadFileStatus.succeed);
|
||||
.every((file) => file?.uploadStatus == UploadFileStatus.succeed);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
@@ -70,4 +70,9 @@ class UploadFileStateList {
|
||||
UploadFileState? getUploadFileStateById(UploadTaskId uploadTaskId) {
|
||||
return _uploadingStateFiles.firstWhereOrNull((fileState) => fileState?.uploadTaskId == uploadTaskId);
|
||||
}
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
void addNullableForTest(UploadFileState? state) {
|
||||
_uploadingStateFiles.add(state);
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ docker compose down || true
|
||||
cd ..
|
||||
|
||||
# Forward traffic to tmail-backend
|
||||
export BASIC_AUTH_URL="http://localhost/"
|
||||
export WEBSOCKET_URL="ws://localhost/"
|
||||
export BASIC_AUTH_URL="http://localhost"
|
||||
export WEBSOCKET_URL="ws://localhost"
|
||||
|
||||
cd backend-docker
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ docker compose down || true
|
||||
cd ..
|
||||
|
||||
# Forward traffic to tmail-backend
|
||||
export BASIC_AUTH_URL="http://localhost/"
|
||||
export WEBSOCKET_URL="ws://localhost/"
|
||||
export BASIC_AUTH_URL="http://localhost"
|
||||
export WEBSOCKET_URL="ws://localhost"
|
||||
|
||||
cd backend-docker
|
||||
|
||||
|
||||
+157
-81
@@ -1,14 +1,22 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
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:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:model/email/email_action_type.dart';
|
||||
import 'package:model/extensions/session_extension.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/exceptions/compose_email_exception.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/repository/composer_repository.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/save_email_as_drafts_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/update_email_drafts_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/create_new_and_save_email_to_drafts_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/create_email_request.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/mailbox_exception.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/remote/unknown_remote_exception.dart';
|
||||
|
||||
import '../../../../fixtures/account_fixtures.dart';
|
||||
import '../../../../fixtures/session_fixtures.dart';
|
||||
@@ -21,100 +29,168 @@ import 'create_new_and_save_email_to_drafts_interactor_test.mocks.dart';
|
||||
void main() {
|
||||
late MockEmailRepository emailRepository;
|
||||
late MockComposerRepository composerRepository;
|
||||
late CreateNewAndSaveEmailToDraftsInteractor createNewAndSaveEmailToDraftsInteractor;
|
||||
late CreateNewAndSaveEmailToDraftsInteractor interactor;
|
||||
|
||||
final draftEmailId = EmailId(Id('draft-id'));
|
||||
|
||||
CreateEmailRequest buildRequest({EmailId? draftsEmailId}) => CreateEmailRequest(
|
||||
session: SessionFixtures.aliceSession,
|
||||
accountId: AccountFixtures.aliceAccountId,
|
||||
emailActionType: EmailActionType.editDraft,
|
||||
ownEmailAddress: SessionFixtures.aliceSession.getOwnEmailAddressOrEmpty(),
|
||||
subject: 'subject',
|
||||
emailContent: 'emailContent',
|
||||
draftsEmailId: draftsEmailId,
|
||||
);
|
||||
|
||||
setUp(() {
|
||||
emailRepository = MockEmailRepository();
|
||||
composerRepository = MockComposerRepository();
|
||||
createNewAndSaveEmailToDraftsInteractor = CreateNewAndSaveEmailToDraftsInteractor(
|
||||
emailRepository,
|
||||
composerRepository);
|
||||
interactor = CreateNewAndSaveEmailToDraftsInteractor(emailRepository, composerRepository);
|
||||
});
|
||||
|
||||
|
||||
group('create new and save email to drafts interactor test:', () {
|
||||
test(
|
||||
'should call generateEmail from composerRepository with withIdentityHeader is true '
|
||||
'when execute is called '
|
||||
'and draftsEmailId != null',
|
||||
'should call generateEmail with withIdentityHeader=true when draftsEmailId != null',
|
||||
() async {
|
||||
// arrange
|
||||
final createEmailRequest = CreateEmailRequest(
|
||||
session: SessionFixtures.aliceSession,
|
||||
accountId: AccountFixtures.aliceAccountId,
|
||||
emailActionType: EmailActionType.editDraft,
|
||||
ownEmailAddress: SessionFixtures
|
||||
.aliceSession
|
||||
.getOwnEmailAddressOrEmpty(),
|
||||
subject: 'subject',
|
||||
emailContent: 'emailContent',
|
||||
draftsEmailId: EmailId(Id('some-id'))
|
||||
);
|
||||
when(composerRepository.generateEmail(
|
||||
any,
|
||||
withIdentityHeader: anyNamed('withIdentityHeader'),
|
||||
isDraft: anyNamed('isDraft'),
|
||||
)).thenAnswer((_) async => Email());
|
||||
final request = buildRequest(draftsEmailId: draftEmailId);
|
||||
when(composerRepository.generateEmail(any, withIdentityHeader: anyNamed('withIdentityHeader'), isDraft: anyNamed('isDraft')))
|
||||
.thenAnswer((_) async => Email());
|
||||
when(emailRepository.updateEmailDrafts(any, any, any, any))
|
||||
.thenAnswer((_) async => Email());
|
||||
|
||||
// act
|
||||
createNewAndSaveEmailToDraftsInteractor
|
||||
.execute(createEmailRequest: createEmailRequest)
|
||||
.last;
|
||||
await untilCalled(composerRepository.generateEmail(
|
||||
any,
|
||||
withIdentityHeader: anyNamed('withIdentityHeader'),
|
||||
isDraft: anyNamed('isDraft'),
|
||||
));
|
||||
|
||||
// assert
|
||||
verify(composerRepository.generateEmail(
|
||||
createEmailRequest,
|
||||
withIdentityHeader: true,
|
||||
isDraft: true,
|
||||
)).called(1);
|
||||
.thenAnswer((_) async => Email());
|
||||
|
||||
interactor.execute(createEmailRequest: request).last;
|
||||
await untilCalled(composerRepository.generateEmail(any, withIdentityHeader: anyNamed('withIdentityHeader'), isDraft: anyNamed('isDraft')));
|
||||
|
||||
verify(composerRepository.generateEmail(request, withIdentityHeader: true, isDraft: true)).called(1);
|
||||
});
|
||||
|
||||
test(
|
||||
'should call generateEmail from composerRepository with withIdentityHeader is true '
|
||||
'when execute is called '
|
||||
'and draftsEmailId == null',
|
||||
'should call generateEmail with withIdentityHeader=true when draftsEmailId == null',
|
||||
() async {
|
||||
// arrange
|
||||
final createEmailRequest = CreateEmailRequest(
|
||||
session: SessionFixtures.aliceSession,
|
||||
accountId: AccountFixtures.aliceAccountId,
|
||||
emailActionType: EmailActionType.editDraft,
|
||||
ownEmailAddress: SessionFixtures
|
||||
.aliceSession
|
||||
.getOwnEmailAddressOrEmpty(),
|
||||
subject: 'subject',
|
||||
emailContent: 'emailContent',
|
||||
);
|
||||
when(composerRepository.generateEmail(
|
||||
any,
|
||||
withIdentityHeader: anyNamed('withIdentityHeader'),
|
||||
isDraft: anyNamed('isDraft'),
|
||||
)).thenAnswer((_) async => Email());
|
||||
final request = buildRequest();
|
||||
when(composerRepository.generateEmail(any, withIdentityHeader: anyNamed('withIdentityHeader'), isDraft: anyNamed('isDraft')))
|
||||
.thenAnswer((_) async => Email());
|
||||
when(emailRepository.saveEmailAsDrafts(any, any, any))
|
||||
.thenAnswer((_) async => Email());
|
||||
|
||||
// act
|
||||
createNewAndSaveEmailToDraftsInteractor
|
||||
.execute(createEmailRequest: createEmailRequest)
|
||||
.last;
|
||||
await untilCalled(composerRepository.generateEmail(
|
||||
any,
|
||||
withIdentityHeader: anyNamed('withIdentityHeader'),
|
||||
isDraft: anyNamed('isDraft'),
|
||||
));
|
||||
|
||||
// assert
|
||||
verify(composerRepository.generateEmail(
|
||||
createEmailRequest,
|
||||
withIdentityHeader: true,
|
||||
isDraft: true,
|
||||
)).called(1);
|
||||
.thenAnswer((_) async => Email());
|
||||
|
||||
interactor.execute(createEmailRequest: request).last;
|
||||
await untilCalled(composerRepository.generateEmail(any, withIdentityHeader: anyNamed('withIdentityHeader'), isDraft: anyNamed('isDraft')));
|
||||
|
||||
verify(composerRepository.generateEmail(request, withIdentityHeader: true, isDraft: true)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
group('_updateDraftsEmail:', () {
|
||||
test(
|
||||
'should emit UpdateEmailDraftsSuccess with attachments from server response',
|
||||
() async {
|
||||
final attachment = EmailBodyPart(
|
||||
blobId: Id('blob-123'),
|
||||
name: 'file.png',
|
||||
type: MediaType('image', 'png'),
|
||||
);
|
||||
final serverEmail = Email(
|
||||
id: EmailId(Id('new-id')),
|
||||
attachments: {attachment},
|
||||
);
|
||||
|
||||
when(composerRepository.generateEmail(any, withIdentityHeader: anyNamed('withIdentityHeader'), isDraft: anyNamed('isDraft')))
|
||||
.thenAnswer((_) async => Email());
|
||||
when(emailRepository.updateEmailDrafts(any, any, any, any))
|
||||
.thenAnswer((_) async => serverEmail);
|
||||
|
||||
final results = await interactor
|
||||
.execute(createEmailRequest: buildRequest(draftsEmailId: draftEmailId))
|
||||
.toList();
|
||||
|
||||
final successState = results
|
||||
.whereType<Right>()
|
||||
.map((r) => r.value)
|
||||
.whereType<UpdateEmailDraftsSuccess>()
|
||||
.firstOrNull;
|
||||
|
||||
expect(successState, isNotNull);
|
||||
expect(successState!.emailId, EmailId(Id('new-id')));
|
||||
expect(successState.attachments, hasLength(1));
|
||||
expect(successState.attachments.first.blobId?.value, 'blob-123');
|
||||
});
|
||||
|
||||
test(
|
||||
'should emit UpdateEmailDraftsFailure(NotFoundEmailIdException) when server returns email with null id',
|
||||
() async {
|
||||
when(composerRepository.generateEmail(any, withIdentityHeader: anyNamed('withIdentityHeader'), isDraft: anyNamed('isDraft')))
|
||||
.thenAnswer((_) async => Email());
|
||||
when(emailRepository.updateEmailDrafts(any, any, any, any))
|
||||
.thenAnswer((_) async => Email()); // id is null
|
||||
|
||||
final results = await interactor
|
||||
.execute(createEmailRequest: buildRequest(draftsEmailId: draftEmailId))
|
||||
.toList();
|
||||
|
||||
final failure = results
|
||||
.whereType<Left>()
|
||||
.map((l) => l.value)
|
||||
.whereType<UpdateEmailDraftsFailure>()
|
||||
.firstOrNull;
|
||||
|
||||
expect(failure, isNotNull);
|
||||
expect(failure!.exception, isA<NotFoundEmailIdException>());
|
||||
});
|
||||
});
|
||||
|
||||
group('_handleFailure:', () {
|
||||
test(
|
||||
'should emit UpdateEmailDraftsFailure(SavingEmailToDraftsCanceledException) '
|
||||
'when UnknownRemoteException wraps a list of SavingEmailToDraftsCanceledException',
|
||||
() async {
|
||||
final wrappedException = UnknownRemoteException(
|
||||
error: [SavingEmailToDraftsCanceledException()],
|
||||
);
|
||||
when(composerRepository.generateEmail(any, withIdentityHeader: anyNamed('withIdentityHeader'), isDraft: anyNamed('isDraft')))
|
||||
.thenAnswer((_) async => Email());
|
||||
when(emailRepository.updateEmailDrafts(any, any, any, any))
|
||||
.thenThrow(wrappedException);
|
||||
|
||||
final results = await interactor
|
||||
.execute(createEmailRequest: buildRequest(draftsEmailId: draftEmailId))
|
||||
.toList();
|
||||
|
||||
final failure = results
|
||||
.whereType<Left>()
|
||||
.map((l) => l.value)
|
||||
.whereType<UpdateEmailDraftsFailure>()
|
||||
.firstOrNull;
|
||||
|
||||
expect(failure, isNotNull);
|
||||
expect(failure!.exception, isA<SavingEmailToDraftsCanceledException>());
|
||||
});
|
||||
|
||||
test(
|
||||
'should emit SaveEmailAsDraftsFailure(SavingEmailToDraftsCanceledException) '
|
||||
'when UnknownRemoteException wraps a list of SavingEmailToDraftsCanceledException '
|
||||
'and draftsEmailId is null',
|
||||
() async {
|
||||
final wrappedException = UnknownRemoteException(
|
||||
error: [SavingEmailToDraftsCanceledException()],
|
||||
);
|
||||
when(composerRepository.generateEmail(any, withIdentityHeader: anyNamed('withIdentityHeader'), isDraft: anyNamed('isDraft')))
|
||||
.thenAnswer((_) async => Email());
|
||||
when(emailRepository.saveEmailAsDrafts(any, any, any))
|
||||
.thenThrow(wrappedException);
|
||||
|
||||
final results = await interactor
|
||||
.execute(createEmailRequest: buildRequest())
|
||||
.toList();
|
||||
|
||||
final failure = results
|
||||
.whereType<Left>()
|
||||
.map((l) => l.value)
|
||||
.whereType<SaveEmailAsDraftsFailure>()
|
||||
.firstOrNull;
|
||||
|
||||
expect(failure, isNotNull);
|
||||
expect(failure!.exception, isA<SavingEmailToDraftsCanceledException>());
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import 'package:tmail_ui_user/features/caching/caching_manager.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/repository/composer_repository.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/save_email_as_drafts_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/update_email_drafts_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/update_template_email_state.dart' show UpdateTemplateEmailSuccess;
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/create_new_and_save_email_to_drafts_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/create_new_and_send_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/download_image_as_base64_interactor.dart';
|
||||
@@ -41,6 +42,7 @@ import 'package:tmail_ui_user/features/composer/presentation/composer_view_web.d
|
||||
import 'package:tmail_ui_user/features/composer/presentation/controller/rich_text_mobile_tablet_controller.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/controller/rich_text_web_controller.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/handle_mobile_auto_save_extension.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/refresh_composer_attachments_extension.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/setup_selected_identity_extension.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/formatting_options_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/saved_composing_email.dart';
|
||||
@@ -593,7 +595,7 @@ void main() {
|
||||
createEmailRequest: anyNamed('createEmailRequest'),
|
||||
cancelToken: anyNamed('cancelToken')))
|
||||
.thenAnswer((_) => Stream.value(
|
||||
Right(UpdateEmailDraftsSuccess(EmailId(Id('123'))))));
|
||||
Right(UpdateEmailDraftsSuccess(emailId: EmailId(Id('123')), attachments: [], htmlBodyAttachments: []))));
|
||||
|
||||
final savedEmailDraft = SavedComposingEmail(
|
||||
content: emailContent,
|
||||
@@ -1076,5 +1078,75 @@ void main() {
|
||||
verifyNever(mockHtmlEditorApi.getText());
|
||||
});
|
||||
});
|
||||
|
||||
group('autoRefreshAllAttachments:', () {
|
||||
setUp(() {
|
||||
when(mockUploadController.inlineAttachmentsUploaded).thenReturn([]);
|
||||
});
|
||||
|
||||
test(
|
||||
'should call uploadController.refreshAllAttachments '
|
||||
'when server returns non-empty attachments',
|
||||
() {
|
||||
final serverAttachment = Attachment(
|
||||
blobId: Id('blob-server-1'),
|
||||
name: 'file.png',
|
||||
);
|
||||
|
||||
composerController?.autoRefreshAllAttachments([serverAttachment], []);
|
||||
|
||||
verify(mockUploadController.refreshAllAttachments(
|
||||
[serverAttachment], [],
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test(
|
||||
'should call uploadController.refreshAllAttachments '
|
||||
'when server returns empty lists and composer has no existing attachments',
|
||||
() {
|
||||
composerController?.initialAttachments = [];
|
||||
|
||||
composerController?.autoRefreshAllAttachments([], []);
|
||||
|
||||
verify(mockUploadController.refreshAllAttachments([], [])).called(1);
|
||||
});
|
||||
|
||||
test(
|
||||
'should skip calling uploadController.refreshAllAttachments '
|
||||
'when server returns empty lists but composer has existing inline attachments',
|
||||
() {
|
||||
final existingInline = Attachment(blobId: Id('existing-inline'));
|
||||
when(mockUploadController.inlineAttachmentsUploaded).thenReturn([existingInline]);
|
||||
|
||||
composerController?.autoRefreshAllAttachments([], []);
|
||||
|
||||
verifyNever(mockUploadController.refreshAllAttachments(any, any));
|
||||
});
|
||||
|
||||
test(
|
||||
'should update currentTemplateEmailId '
|
||||
'when UpdateTemplateEmailSuccess is processed',
|
||||
() async {
|
||||
final newEmailId = EmailId(Id('new-template-id'));
|
||||
final success = UpdateTemplateEmailSuccess(
|
||||
emailId: newEmailId,
|
||||
attachments: [],
|
||||
htmlBodyAttachments: [],
|
||||
);
|
||||
|
||||
when(mockUploadController.inlineAttachmentsUploaded).thenReturn([]);
|
||||
composerController?.initialAttachments = [];
|
||||
|
||||
// Simulate what handleClickSaveAsTemplateButton does on success
|
||||
composerController?.currentTemplateEmailId = success.emailId;
|
||||
composerController?.autoRefreshAllAttachments(
|
||||
success.attachments,
|
||||
success.htmlBodyAttachments,
|
||||
);
|
||||
|
||||
expect(composerController?.currentTemplateEmailId, equals(newEmailId));
|
||||
verify(mockUploadController.refreshAllAttachments([], [])).called(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import 'package:core/data/network/download/download_manager.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:jmap_dart_client/http/http_client.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
@@ -13,6 +14,7 @@ import 'package:model/email/mark_star_action.dart';
|
||||
import 'package:model/email/read_actions.dart';
|
||||
import 'package:model/extensions/account_id_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/email/data/network/email_api.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/move_action.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/move_to_mailbox_request.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
@@ -1132,5 +1134,67 @@ void main() {
|
||||
expect(result.mapErrors.isEmpty, isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('getEmailMetadata:', () {
|
||||
final emailId = EmailId(Id('email-id-123'));
|
||||
final properties = Properties({'id'});
|
||||
|
||||
void stubHttpResponse(List<Map<String, dynamic>> emailList) {
|
||||
when(httpClient.post(
|
||||
'',
|
||||
data: anyNamed('data'),
|
||||
cancelToken: anyNamed('cancelToken'),
|
||||
)).thenAnswer((_) async => {
|
||||
'sessionState': 'some-state',
|
||||
'methodResponses': [
|
||||
[
|
||||
'Email/get',
|
||||
{
|
||||
'accountId': AccountFixtures.aliceAccountId.asString,
|
||||
'state': 'email-state',
|
||||
'list': emailList,
|
||||
'notFound': [],
|
||||
},
|
||||
'c0',
|
||||
]
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
test(
|
||||
'SHOULD return first email in the list '
|
||||
'WHEN server response contains the requested email',
|
||||
() async {
|
||||
stubHttpResponse([
|
||||
{'id': 'email-id-123'},
|
||||
]);
|
||||
|
||||
final result = await emailApi.getEmailMetadata(
|
||||
SessionFixtures.aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emailId,
|
||||
properties,
|
||||
);
|
||||
|
||||
expect(result.id, emailId);
|
||||
});
|
||||
|
||||
test(
|
||||
'SHOULD throw NotFoundEmailException '
|
||||
'WHEN server response returns an empty list',
|
||||
() async {
|
||||
stubHttpResponse([]);
|
||||
|
||||
await expectLater(
|
||||
emailApi.getEmailMetadata(
|
||||
SessionFixtures.aliceSession,
|
||||
AccountFixtures.aliceAccountId,
|
||||
emailId,
|
||||
properties,
|
||||
),
|
||||
throwsA(isA<NotFoundEmailException>()),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
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:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:model/email/email_action_type.dart';
|
||||
import 'package:model/extensions/session_extension.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/repository/composer_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/generate_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/create_email_request.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/save_template_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/update_template_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/save_template_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/mailbox_exception.dart';
|
||||
|
||||
import '../../../../fixtures/account_fixtures.dart';
|
||||
import '../../../../fixtures/session_fixtures.dart';
|
||||
import 'save_template_email_interactor_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([
|
||||
MockSpec<EmailRepository>(),
|
||||
MockSpec<ComposerRepository>(),
|
||||
])
|
||||
void main() {
|
||||
late MockEmailRepository emailRepository;
|
||||
late MockComposerRepository composerRepository;
|
||||
late SaveTemplateEmailInteractor interactor;
|
||||
|
||||
final templateEmailId = EmailId(Id('template-id'));
|
||||
|
||||
CreateEmailRequest buildRequest({EmailId? templateEmailId}) => CreateEmailRequest(
|
||||
session: SessionFixtures.aliceSession,
|
||||
accountId: AccountFixtures.aliceAccountId,
|
||||
emailActionType: EmailActionType.compose,
|
||||
ownEmailAddress: SessionFixtures.aliceSession.getOwnEmailAddressOrEmpty(),
|
||||
subject: 'subject',
|
||||
emailContent: 'emailContent',
|
||||
templateEmailId: templateEmailId,
|
||||
);
|
||||
|
||||
Future<List<dynamic>> executeInteractor({EmailId? templateEmailId}) =>
|
||||
interactor
|
||||
.execute(
|
||||
createEmailRequest: buildRequest(templateEmailId: templateEmailId),
|
||||
createNewMailboxRequest: null,
|
||||
)
|
||||
.toList();
|
||||
|
||||
T? firstSuccess<T>(List results) => results
|
||||
.whereType<Right>()
|
||||
.map((r) => r.value)
|
||||
.whereType<T>()
|
||||
.firstOrNull;
|
||||
|
||||
T? firstFailure<T>(List results) => results
|
||||
.whereType<Left>()
|
||||
.map((l) => l.value)
|
||||
.whereType<T>()
|
||||
.firstOrNull;
|
||||
|
||||
void expectNotFoundEmailIdException<T extends FeatureFailure>(List results) {
|
||||
final failure = firstFailure<T>(results);
|
||||
expect(failure, isNotNull);
|
||||
expect(failure!.exception, isA<NotFoundEmailIdException>());
|
||||
}
|
||||
|
||||
void stubGenerateEmailSuccess() {
|
||||
when(composerRepository.generateEmail(
|
||||
any,
|
||||
withIdentityHeader: anyNamed('withIdentityHeader'),
|
||||
isTemplate: anyNamed('isTemplate'),
|
||||
)).thenAnswer((_) async => Email());
|
||||
}
|
||||
|
||||
setUp(() {
|
||||
emailRepository = MockEmailRepository();
|
||||
composerRepository = MockComposerRepository();
|
||||
interactor = SaveTemplateEmailInteractor(composerRepository, emailRepository);
|
||||
});
|
||||
|
||||
group('SaveTemplateEmailInteractor:', () {
|
||||
group('_createEmailObject fails:', () {
|
||||
test(
|
||||
'should emit GenerateEmailFailure(CannotCreateEmailObjectException) when generateEmail throws',
|
||||
() async {
|
||||
when(composerRepository.generateEmail(
|
||||
any,
|
||||
withIdentityHeader: anyNamed('withIdentityHeader'),
|
||||
isTemplate: anyNamed('isTemplate'),
|
||||
)).thenThrow(Exception('generate failed'));
|
||||
|
||||
final results = await executeInteractor();
|
||||
|
||||
final failure = firstFailure<GenerateEmailFailure>(results);
|
||||
expect(failure, isNotNull);
|
||||
expect(failure!.exception, isA<CannotCreateEmailObjectException>());
|
||||
});
|
||||
});
|
||||
|
||||
group('_saveEmailAsTemplate (templateEmailId == null):', () {
|
||||
setUp(stubGenerateEmailSuccess);
|
||||
|
||||
test(
|
||||
'should emit SaveTemplateEmailSuccess with correct emailId',
|
||||
() async {
|
||||
when(emailRepository.saveEmailAsTemplate(any, any, any))
|
||||
.thenAnswer((_) async => Email(id: EmailId(Id('new-template-id'))));
|
||||
|
||||
final results = await executeInteractor();
|
||||
|
||||
final success = firstSuccess<SaveTemplateEmailSuccess>(results);
|
||||
expect(success, isNotNull);
|
||||
expect(success!.emailId, EmailId(Id('new-template-id')));
|
||||
});
|
||||
|
||||
test(
|
||||
'should emit SaveTemplateEmailFailure(NotFoundEmailIdException) when server returns email with null id',
|
||||
() async {
|
||||
when(emailRepository.saveEmailAsTemplate(any, any, any))
|
||||
.thenAnswer((_) async => Email()); // id is null
|
||||
|
||||
final results = await executeInteractor();
|
||||
|
||||
expectNotFoundEmailIdException<SaveTemplateEmailFailure>(results);
|
||||
});
|
||||
|
||||
test(
|
||||
'should emit SaveTemplateEmailFailure when repository throws',
|
||||
() async {
|
||||
when(emailRepository.saveEmailAsTemplate(any, any, any))
|
||||
.thenThrow(Exception('network error'));
|
||||
|
||||
final results = await executeInteractor();
|
||||
|
||||
final failure = firstFailure<SaveTemplateEmailFailure>(results);
|
||||
expect(failure, isNotNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('_updateTemplateEmail (templateEmailId != null):', () {
|
||||
setUp(stubGenerateEmailSuccess);
|
||||
|
||||
test(
|
||||
'should emit UpdateTemplateEmailSuccess with attachments from server response',
|
||||
() async {
|
||||
final attachment = EmailBodyPart(
|
||||
blobId: Id('blob-123'),
|
||||
name: 'file.png',
|
||||
type: MediaType('image', 'png'),
|
||||
);
|
||||
final inlinePart = EmailBodyPart(
|
||||
blobId: Id('blob-inline'),
|
||||
cid: 'cid-1',
|
||||
type: MediaType('image', 'png'),
|
||||
);
|
||||
final serverEmail = Email(
|
||||
id: EmailId(Id('updated-id')),
|
||||
attachments: {attachment},
|
||||
htmlBody: {inlinePart},
|
||||
);
|
||||
|
||||
when(emailRepository.updateEmailTemplate(any, any, any, any))
|
||||
.thenAnswer((_) async => serverEmail);
|
||||
|
||||
final results = await executeInteractor(templateEmailId: templateEmailId);
|
||||
|
||||
final success = firstSuccess<UpdateTemplateEmailSuccess>(results);
|
||||
expect(success, isNotNull);
|
||||
expect(success!.emailId, EmailId(Id('updated-id')));
|
||||
expect(success.attachments, hasLength(1));
|
||||
expect(success.attachments.first.blobId?.value, 'blob-123');
|
||||
expect(success.htmlBodyAttachments, hasLength(1));
|
||||
expect(success.htmlBodyAttachments.first.blobId?.value, 'blob-inline');
|
||||
});
|
||||
|
||||
test(
|
||||
'should emit UpdateTemplateEmailFailure(NotFoundEmailIdException) when server returns email with null id',
|
||||
() async {
|
||||
when(emailRepository.updateEmailTemplate(any, any, any, any))
|
||||
.thenAnswer((_) async => Email()); // id is null
|
||||
|
||||
final results = await executeInteractor(templateEmailId: templateEmailId);
|
||||
|
||||
expectNotFoundEmailIdException<UpdateTemplateEmailFailure>(results);
|
||||
});
|
||||
|
||||
test(
|
||||
'should emit UpdateTemplateEmailFailure when repository throws',
|
||||
() async {
|
||||
when(emailRepository.updateEmailTemplate(any, any, any, any))
|
||||
.thenThrow(Exception('network error'));
|
||||
|
||||
final results = await executeInteractor(templateEmailId: templateEmailId);
|
||||
|
||||
final failure = firstFailure<UpdateTemplateEmailFailure>(results);
|
||||
expect(failure, isNotNull);
|
||||
});
|
||||
|
||||
test(
|
||||
'should call updateEmailTemplate with correct templateEmailId',
|
||||
() async {
|
||||
when(emailRepository.updateEmailTemplate(any, any, any, any))
|
||||
.thenAnswer((_) async => Email(id: EmailId(Id('updated-id'))));
|
||||
|
||||
await executeInteractor(templateEmailId: templateEmailId);
|
||||
|
||||
verify(emailRepository.updateEmailTemplate(
|
||||
any, any, any, templateEmailId,
|
||||
)).called(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
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:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/model/upload_task_id.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/model/upload_file_state.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/model/upload_file_state_list.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/model/upload_file_status.dart';
|
||||
|
||||
void main() {
|
||||
group('UploadFileStateList', () {
|
||||
late UploadFileStateList uploadFileStateList;
|
||||
|
||||
Attachment createAttachment(String blobId, {String? cid}) {
|
||||
return Attachment(
|
||||
blobId: Id(blobId),
|
||||
name: 'file.png',
|
||||
size: UnsignedInt(100),
|
||||
type: MediaType('image', 'png'),
|
||||
cid: cid,
|
||||
);
|
||||
}
|
||||
|
||||
UploadFileState createUploadFileState({
|
||||
required String uploadTaskId,
|
||||
required String blobId,
|
||||
}) {
|
||||
return UploadFileState(
|
||||
UploadTaskId(uploadTaskId),
|
||||
uploadStatus: UploadFileStatus.succeed,
|
||||
attachment: createAttachment(blobId),
|
||||
);
|
||||
}
|
||||
|
||||
void populateWithTwoItems() {
|
||||
uploadFileStateList.addAll([
|
||||
createUploadFileState(uploadTaskId: 'task-1', blobId: 'blob-1'),
|
||||
createUploadFileState(uploadTaskId: 'task-2', blobId: 'blob-2'),
|
||||
]);
|
||||
}
|
||||
|
||||
setUp(() {
|
||||
uploadFileStateList = UploadFileStateList();
|
||||
});
|
||||
|
||||
group('add / addAll', () {
|
||||
test('should contain added element', () {
|
||||
uploadFileStateList.add(createUploadFileState(
|
||||
uploadTaskId: 'task-1',
|
||||
blobId: 'blob-1',
|
||||
));
|
||||
|
||||
expect(uploadFileStateList.uploadingStateFiles, hasLength(1));
|
||||
expect(
|
||||
uploadFileStateList.uploadingStateFiles.first?.attachment?.blobId?.value,
|
||||
'blob-1',
|
||||
);
|
||||
});
|
||||
|
||||
test('should contain all added elements', () {
|
||||
populateWithTwoItems();
|
||||
|
||||
expect(uploadFileStateList.uploadingStateFiles, hasLength(2));
|
||||
});
|
||||
});
|
||||
|
||||
group('clear', () {
|
||||
test('should be empty after clear', () {
|
||||
populateWithTwoItems();
|
||||
|
||||
uploadFileStateList.clear();
|
||||
|
||||
expect(uploadFileStateList.uploadingStateFiles, isEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
group('updateElementByUploadTaskId', () {
|
||||
late UploadFileState? Function(UploadFileState?) updater;
|
||||
|
||||
setUp(() {
|
||||
uploadFileStateList.add(createUploadFileState(
|
||||
uploadTaskId: 'task-1',
|
||||
blobId: 'blob-1',
|
||||
));
|
||||
updater = (state) => state?.copyWith(
|
||||
attachment: createAttachment('blob-updated'),
|
||||
);
|
||||
});
|
||||
|
||||
void actAndAssert({
|
||||
required String taskId,
|
||||
required String expectedBlobId,
|
||||
}) {
|
||||
uploadFileStateList.updateElementByUploadTaskId(
|
||||
UploadTaskId(taskId),
|
||||
updater,
|
||||
);
|
||||
expect(
|
||||
uploadFileStateList.uploadingStateFiles.first?.attachment?.blobId?.value,
|
||||
expectedBlobId,
|
||||
);
|
||||
}
|
||||
|
||||
test('should update element matching the given upload task id', () {
|
||||
actAndAssert(taskId: 'task-1', expectedBlobId: 'blob-updated');
|
||||
});
|
||||
|
||||
test('should not update element when task id does not match', () {
|
||||
actAndAssert(taskId: 'task-2', expectedBlobId: 'blob-1');
|
||||
});
|
||||
});
|
||||
|
||||
group('deleteElementByUploadTaskId', () {
|
||||
test('should remove element with matching task id', () {
|
||||
populateWithTwoItems();
|
||||
|
||||
uploadFileStateList.deleteElementByUploadTaskId(const UploadTaskId('task-1'));
|
||||
|
||||
expect(uploadFileStateList.uploadingStateFiles, hasLength(1));
|
||||
expect(
|
||||
uploadFileStateList.uploadingStateFiles.first?.attachment?.blobId?.value,
|
||||
'blob-2',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('allSuccess', () {
|
||||
test('should return true when all elements have succeed status', () {
|
||||
populateWithTwoItems();
|
||||
|
||||
expect(uploadFileStateList.allSuccess, isTrue);
|
||||
});
|
||||
|
||||
test('should return false when list is empty', () {
|
||||
expect(uploadFileStateList.allSuccess, isFalse);
|
||||
});
|
||||
|
||||
test('should return false when list contains a null element', () {
|
||||
uploadFileStateList.addNullableForTest(null);
|
||||
|
||||
expect(uploadFileStateList.allSuccess, isFalse);
|
||||
});
|
||||
});
|
||||
|
||||
group('getUploadFileStateById', () {
|
||||
setUp(() => populateWithTwoItems());
|
||||
|
||||
test('should return state matching the given task id', () {
|
||||
final result = uploadFileStateList.getUploadFileStateById(const UploadTaskId('task-1'));
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result?.attachment?.blobId?.value, 'blob-1');
|
||||
});
|
||||
|
||||
test('should return null when task id does not match any element', () {
|
||||
final result = uploadFileStateList.getUploadFileStateById(const UploadTaskId('task-99'));
|
||||
|
||||
expect(result, isNull);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user