mirror of
https://github.com/linagora/tmail-flutter.git
synced 2026-12-05 16:08:46 +00:00
1 parent
e00be37ad6
commit
d8d80e698c
10 files changed
+1075
No files matched your search
@@ -0,0 +1,86 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/dialog/drive_oversize_upload_dialog_view.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/styles/drive_oversize_upload_dialog_style.dart';
|
||||
|
||||
/// Web gets the centred `Dialog`, mobile the bottom sheet, matching the two
|
||||
/// Figma frames.
|
||||
class DriveOversizeUploadDialogPresenter {
|
||||
const DriveOversizeUploadDialogPresenter._();
|
||||
|
||||
/// Opens the batch dialog. Modal, opaque barrier, no dismiss — this is what
|
||||
/// blocks every user input for the Drive path. Chips are untouched.
|
||||
static void show(ProviderContainer container) {
|
||||
final isWebLayout = PlatformInfo.isWeb;
|
||||
final body = PointerInterceptor(
|
||||
child: UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: DriveOversizeUploadDialogView(
|
||||
imagePaths: ImagePaths(),
|
||||
isWebLayout: isWebLayout,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Get.dialog(
|
||||
PopScope(
|
||||
canPop: false,
|
||||
child: isWebLayout ? _webSurface(body) : _mobileSurface(body),
|
||||
),
|
||||
barrierDismissible: false,
|
||||
barrierColor: AppColor.colorDefaultCupertinoActionSheet,
|
||||
);
|
||||
}
|
||||
|
||||
static Widget _webSurface(Widget body) => Dialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
alignment: Alignment.center,
|
||||
child: Builder(
|
||||
builder: (context) => Container(
|
||||
width: min(context.width, DriveOversizeUploadDialogStyle.webMaxWidth),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(
|
||||
DriveOversizeUploadDialogStyle.webSurfaceRadius),
|
||||
boxShadow: DriveOversizeUploadDialogStyle.surfaceShadow,
|
||||
),
|
||||
child: body,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/// A bottom sheet, not a centred card — mobile frame 12004-18682.
|
||||
static Widget _mobileSurface(Widget body) => Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Material(
|
||||
type: MaterialType.transparency,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(
|
||||
top: Radius.circular(
|
||||
DriveOversizeUploadDialogStyle.mobileSurfaceRadius)),
|
||||
boxShadow: DriveOversizeUploadDialogStyle.surfaceShadow,
|
||||
),
|
||||
child: SafeArea(top: false, child: body),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/// Safe to call when nothing is open — `Get.isDialogOpen` guards a double pop.
|
||||
static void close() {
|
||||
if (Get.isDialogOpen == true) Get.back();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/presentation/views/button/tmail_button_widget.dart';
|
||||
import 'package:filesize/filesize.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/dialog/drive_oversize_upload_row.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/model/drive_oversize_transfer_state.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/providers/drive_oversize_transfer_notifier.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/styles/drive_oversize_upload_dialog_style.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
/// One widget serves both frames; [isWebLayout] picks the type scale, the row
|
||||
/// shape and the Cancel alignment. The surface itself is the presenter's job.
|
||||
class DriveOversizeUploadDialogView extends ConsumerWidget {
|
||||
final ImagePaths imagePaths;
|
||||
final bool isWebLayout;
|
||||
|
||||
const DriveOversizeUploadDialogView({
|
||||
super.key,
|
||||
required this.imagePaths,
|
||||
required this.isWebLayout,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final itemCount = ref.watch(
|
||||
driveOversizeTransferProvider.select((items) => items.length));
|
||||
final notifier = ref.read(driveOversizeTransferProvider.notifier);
|
||||
final appLocalizations = AppLocalizations.of(context);
|
||||
final anyRunning = ref.watch(driveOversizeTransferProvider.select(
|
||||
(items) => items.any((item) => !item.status.settled)));
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: DriveOversizeUploadDialogStyle.headerPadding,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
appLocalizations.attachingFileTitle,
|
||||
style: DriveOversizeUploadDialogStyle.title(isWebLayout),
|
||||
),
|
||||
),
|
||||
// Header ✕ means the same as Cancel: abandon the batch and close.
|
||||
SizedBox.square(
|
||||
dimension: DriveOversizeUploadDialogStyle.rowCloseButtonSize,
|
||||
child: TMailButtonWidget.fromIcon(
|
||||
icon: imagePaths.icClose,
|
||||
iconSize: DriveOversizeUploadDialogStyle.headerCloseIconSize,
|
||||
backgroundColor: Colors.transparent,
|
||||
onTapActionCallback: notifier.cancelAll,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: DriveOversizeUploadDialogStyle.descriptionPadding,
|
||||
child: _buildDescription(context, appLocalizations, itemCount),
|
||||
),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxHeight: DriveOversizeUploadDialogStyle.maxListHeight),
|
||||
// shrinkWrap keeps a 1-file dialog at the Figma frame's height; the
|
||||
// list only scrolls once the batch outgrows the box.
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
primary: false,
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: itemCount,
|
||||
itemBuilder: (_, index) => _DriveOversizeUploadRowSlot(
|
||||
index: index,
|
||||
imagePaths: imagePaths,
|
||||
isWebLayout: isWebLayout,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(
|
||||
height: 1,
|
||||
thickness: 1,
|
||||
color: DriveOversizeUploadDialogStyle.separatorColor,
|
||||
),
|
||||
// The footer keeps its height when nothing is cancellable, so the
|
||||
// dialog does not jump as the last row settles.
|
||||
Align(
|
||||
alignment: isWebLayout
|
||||
? AlignmentDirectional.centerEnd
|
||||
: AlignmentDirectional.centerStart,
|
||||
child: Padding(
|
||||
padding: DriveOversizeUploadDialogStyle.headerPadding,
|
||||
child: Opacity(
|
||||
opacity: anyRunning ? 1 : 0,
|
||||
child: IgnorePointer(
|
||||
ignoring: !anyRunning,
|
||||
child: TMailButtonWidget.fromText(
|
||||
text: appLocalizations.cancel,
|
||||
padding: DriveOversizeUploadDialogStyle.cancelPadding,
|
||||
backgroundColor: Colors.transparent,
|
||||
borderRadius: 100,
|
||||
textStyle: DriveOversizeUploadDialogStyle.cancelTextStyle,
|
||||
onTapActionCallback: notifier.cancelAll,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// "Your file is larger than 25 MB. It will be uploaded to Twake Drive and
|
||||
/// attached as **a link**." — the trailing run is emphasised, as in Figma.
|
||||
Widget _buildDescription(
|
||||
BuildContext context,
|
||||
AppLocalizations appLocalizations,
|
||||
int fileCount,
|
||||
) {
|
||||
final baseStyle = DriveOversizeUploadDialogStyle.body(isWebLayout);
|
||||
final maxSize = filesize(
|
||||
Get.find<MailboxDashBoardController>().maxSizeAttachmentsPerEmail?.value ?? 0,
|
||||
0,
|
||||
);
|
||||
return Text.rich(
|
||||
TextSpan(
|
||||
style: baseStyle,
|
||||
children: [
|
||||
TextSpan(text: appLocalizations.driveOversizeDialogMessage(maxSize)),
|
||||
TextSpan(
|
||||
text: appLocalizations.driveOversizeDialogMessageEmphasis,
|
||||
style: baseStyle.merge(DriveOversizeUploadDialogStyle.emphasisedBody),
|
||||
),
|
||||
const TextSpan(text: '.'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Watches only its own row, so a progress tick leaves the rest of the dialog alone.
|
||||
class _DriveOversizeUploadRowSlot extends ConsumerWidget {
|
||||
final int index;
|
||||
final ImagePaths imagePaths;
|
||||
final bool isWebLayout;
|
||||
|
||||
const _DriveOversizeUploadRowSlot({
|
||||
required this.index,
|
||||
required this.imagePaths,
|
||||
required this.isWebLayout,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final item = ref.watch(driveOversizeTransferProvider.select(
|
||||
(items) => index < items.length ? items[index] : null));
|
||||
// The list only empties on clear(), as the dialog closes.
|
||||
if (item == null) return const SizedBox.shrink();
|
||||
return DriveOversizeUploadRow(
|
||||
item: item,
|
||||
imagePaths: imagePaths,
|
||||
isWebLayout: isWebLayout,
|
||||
onCancel: ref.read(driveOversizeTransferProvider.notifier).cancel,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/presentation/views/button/tmail_button_widget.dart';
|
||||
import 'package:filesize/filesize.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:percent_indicator/percent_indicator.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/model/upload_task_id.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/model/drive_oversize_transfer_state.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/styles/drive_oversize_upload_dialog_style.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
/// One row per file: `[chip][size][bar][✕]` on web, `[chip][size][✕]` plus a
|
||||
/// full-width bar underneath on mobile — the only structural platform diff.
|
||||
class DriveOversizeUploadRow extends StatelessWidget {
|
||||
final DriveOversizeTransferState item;
|
||||
final ImagePaths imagePaths;
|
||||
final bool isWebLayout;
|
||||
final void Function(UploadTaskId taskId) onCancel;
|
||||
|
||||
const DriveOversizeUploadRow({
|
||||
super.key,
|
||||
required this.item,
|
||||
required this.imagePaths,
|
||||
required this.isWebLayout,
|
||||
required this.onCancel,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final topLine = Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_buildChip(),
|
||||
const SizedBox(width: 16),
|
||||
SizedBox(
|
||||
width: DriveOversizeUploadDialogStyle.sizeLabelWidth(isWebLayout),
|
||||
child: Text(
|
||||
_sizeLabel(AppLocalizations.of(context)),
|
||||
style: DriveOversizeUploadDialogStyle.sizeText(isWebLayout),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
if (isWebLayout) ...[
|
||||
const SizedBox(width: 16),
|
||||
Expanded(child: _buildBar()),
|
||||
] else
|
||||
const Spacer(),
|
||||
_buildCloseButton(),
|
||||
],
|
||||
);
|
||||
|
||||
return Padding(
|
||||
padding: DriveOversizeUploadDialogStyle.rowPadding,
|
||||
child: isWebLayout
|
||||
? topLine
|
||||
: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
topLine,
|
||||
const SizedBox(height: 12),
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.symmetric(
|
||||
horizontal: DriveOversizeUploadDialogStyle.mobileBarInset),
|
||||
child: _buildBar(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Fixed 191pt wide in both frames, so a long name ellipsises instead of
|
||||
/// pushing the bar off the row.
|
||||
Widget _buildChip() => Container(
|
||||
width: DriveOversizeUploadDialogStyle.chipWidth,
|
||||
padding: DriveOversizeUploadDialogStyle.chipPadding,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(
|
||||
DriveOversizeUploadDialogStyle.chipRadius),
|
||||
border: Border.all(
|
||||
color: DriveOversizeUploadDialogStyle.chipBorderColor),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(
|
||||
DriveOversizeUploadDialogStyle.thumbnailRadius),
|
||||
child: SvgPicture.asset(
|
||||
imagePaths.icFileDefault,
|
||||
width: DriveOversizeUploadDialogStyle.thumbnailSize,
|
||||
height: DriveOversizeUploadDialogStyle.thumbnailSize,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
item.fileName,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: DriveOversizeUploadDialogStyle.fileNameTextStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
/// `332M` while running (the design shows size, not percent); a terminal
|
||||
/// word once the row settles.
|
||||
String _sizeLabel(AppLocalizations appLocalizations) {
|
||||
final size = filesize(item.fileSize, 0);
|
||||
return switch (item.status) {
|
||||
DriveOversizeTransferStatus.waiting ||
|
||||
DriveOversizeTransferStatus.uploading => size,
|
||||
DriveOversizeTransferStatus.linked => appLocalizations.driveUploadRowDone,
|
||||
DriveOversizeTransferStatus.failed => appLocalizations.driveUploadRowFailed,
|
||||
DriveOversizeTransferStatus.cancelled =>
|
||||
appLocalizations.driveUploadRowCancelled,
|
||||
};
|
||||
}
|
||||
|
||||
Widget _buildBar() {
|
||||
// The bridge path reports no bytes, so it stays indeterminate rather
|
||||
// than sitting at 0% for the whole transfer.
|
||||
if (!item.status.settled && item.sentBytes == 0) {
|
||||
return const ClipRRect(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(DriveOversizeUploadDialogStyle.barRadius)),
|
||||
child: LinearProgressIndicator(
|
||||
minHeight: DriveOversizeUploadDialogStyle.barHeight,
|
||||
backgroundColor: DriveOversizeUploadDialogStyle.barTrackColor,
|
||||
color: AppColor.primaryColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
// A settled row freezes its bar — no empty state in the design.
|
||||
return LinearPercentIndicator(
|
||||
percent: item.status == DriveOversizeTransferStatus.linked ? 1.0 : item.progress,
|
||||
lineHeight: DriveOversizeUploadDialogStyle.barHeight,
|
||||
barRadius: const Radius.circular(DriveOversizeUploadDialogStyle.barRadius),
|
||||
backgroundColor: DriveOversizeUploadDialogStyle.barTrackColor,
|
||||
progressColor: AppColor.primaryColor,
|
||||
padding: EdgeInsets.zero,
|
||||
animation: true,
|
||||
animateFromLastPercent: true,
|
||||
);
|
||||
}
|
||||
|
||||
/// A settled row has nothing left to cancel, so the ✕ goes.
|
||||
Widget _buildCloseButton() => SizedBox.square(
|
||||
dimension: DriveOversizeUploadDialogStyle.rowCloseButtonSize,
|
||||
child: item.status.settled
|
||||
? null
|
||||
: TMailButtonWidget.fromIcon(
|
||||
icon: imagePaths.icClose,
|
||||
iconSize: DriveOversizeUploadDialogStyle.rowCloseIconSize,
|
||||
backgroundColor: Colors.white,
|
||||
onTapActionCallback: () => onCancel(item.taskId),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/model/upload_task_id.dart';
|
||||
|
||||
enum DriveOversizeTransferStatus { waiting, uploading, linked, failed, cancelled }
|
||||
|
||||
extension DriveOversizeTransferStatusExtension on DriveOversizeTransferStatus {
|
||||
bool get settled => this != DriveOversizeTransferStatus.waiting
|
||||
&& this != DriveOversizeTransferStatus.uploading;
|
||||
}
|
||||
|
||||
/// One file of an oversize batch, as the progress dialog renders it.
|
||||
class DriveOversizeTransferState with EquatableMixin {
|
||||
final UploadTaskId taskId;
|
||||
final String fileName;
|
||||
final int fileSize;
|
||||
final int sentBytes;
|
||||
final DriveOversizeTransferStatus status;
|
||||
|
||||
/// Cancels this one transfer. Excluded from [props] — identity only.
|
||||
final CancelToken cancelToken;
|
||||
|
||||
const DriveOversizeTransferState({
|
||||
required this.taskId,
|
||||
required this.fileName,
|
||||
required this.fileSize,
|
||||
required this.cancelToken,
|
||||
this.sentBytes = 0,
|
||||
this.status = DriveOversizeTransferStatus.waiting,
|
||||
});
|
||||
|
||||
/// 0.0-1.0 for the bar; 0 while the total is still unknown.
|
||||
double get progress =>
|
||||
fileSize <= 0 ? 0 : (sentBytes / fileSize).clamp(0.0, 1.0);
|
||||
|
||||
int get percent => (progress * 100).round();
|
||||
|
||||
DriveOversizeTransferState copyWith({
|
||||
int? sentBytes,
|
||||
DriveOversizeTransferStatus? status,
|
||||
}) => DriveOversizeTransferState(
|
||||
taskId: taskId,
|
||||
fileName: fileName,
|
||||
fileSize: fileSize,
|
||||
cancelToken: cancelToken,
|
||||
sentBytes: sentBytes ?? this.sentBytes,
|
||||
status: status ?? this.status,
|
||||
);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [taskId, fileName, fileSize, sentBytes, status];
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/model/upload_task_id.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/model/drive_oversize_transfer_state.dart';
|
||||
|
||||
part 'drive_oversize_transfer_notifier.g.dart';
|
||||
|
||||
/// Rows of the oversize-upload dialog. One batch at a time — the dialog is
|
||||
/// modal, so a composer can only run one oversize pick concurrently.
|
||||
@Riverpod(keepAlive: true)
|
||||
class DriveOversizeTransfer extends _$DriveOversizeTransfer {
|
||||
@override
|
||||
List<DriveOversizeTransferState> build() => const [];
|
||||
|
||||
void start(List<DriveOversizeTransferState> items) => state = items;
|
||||
|
||||
void clear() => state = const [];
|
||||
|
||||
/// True once every row reached a terminal status — the dialog closes on it.
|
||||
bool get allSettled =>
|
||||
state.isNotEmpty && state.every((item) => item.status.settled);
|
||||
|
||||
/// The bridge path never calls this, so its rows stay indeterminate.
|
||||
/// XHR reports far more often than the bar can show, so sub-percent ticks are dropped.
|
||||
void reportProgress(UploadTaskId taskId, int sentBytes, int totalBytes) {
|
||||
_update(taskId, (item) {
|
||||
final next = item.copyWith(
|
||||
sentBytes: sentBytes,
|
||||
status: DriveOversizeTransferStatus.uploading,
|
||||
);
|
||||
final sameBar = next.status == item.status
|
||||
&& next.percent == item.percent
|
||||
&& (next.sentBytes > 0) == (item.sentBytes > 0);
|
||||
return sameBar ? item : next;
|
||||
});
|
||||
}
|
||||
|
||||
void markUploading(UploadTaskId taskId) => _update(
|
||||
taskId, (item) => item.copyWith(status: DriveOversizeTransferStatus.uploading));
|
||||
|
||||
void markLinked(UploadTaskId taskId) => _update(
|
||||
taskId, (item) => item.copyWith(
|
||||
sentBytes: item.fileSize,
|
||||
status: DriveOversizeTransferStatus.linked,
|
||||
));
|
||||
|
||||
void markFailed(UploadTaskId taskId) => _update(
|
||||
taskId, (item) => item.copyWith(status: DriveOversizeTransferStatus.failed));
|
||||
|
||||
/// A settled row is left alone so a racing cancel can't un-link a finished file.
|
||||
void cancel(UploadTaskId taskId) {
|
||||
_update(taskId, (item) {
|
||||
if (item.status.settled) return item;
|
||||
if (!item.cancelToken.isCancelled) item.cancelToken.cancel();
|
||||
return item.copyWith(status: DriveOversizeTransferStatus.cancelled);
|
||||
});
|
||||
}
|
||||
|
||||
void cancelAll() {
|
||||
for (final item in state) {
|
||||
cancel(item.taskId);
|
||||
}
|
||||
}
|
||||
|
||||
void _update(
|
||||
UploadTaskId taskId,
|
||||
DriveOversizeTransferState Function(DriveOversizeTransferState item) transform,
|
||||
) {
|
||||
final index = state.indexWhere((item) => item.taskId == taskId);
|
||||
if (index < 0) return;
|
||||
final next = transform(state[index]);
|
||||
if (identical(next, state[index])) return;
|
||||
state = [...state]..[index] = next;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
|
||||
/// Tokens from the TF-4827 Figma frames (web 9929-5510, mobile 12004-18682).
|
||||
class DriveOversizeUploadDialogStyle {
|
||||
const DriveOversizeUploadDialogStyle._();
|
||||
|
||||
// Colours the design system has no token for.
|
||||
static const Color titleColor = Color(0xE6424244); // rgba(66,66,68,.9)
|
||||
static const Color separatorColor = Color(0x1F424244); // rgba(66,66,68,.12)
|
||||
static const Color secondaryTextColor = Color(0xFF737373);
|
||||
static const Color chipBorderColor = Color(0xFFE5ECF3);
|
||||
static const Color fileNameColor = Color(0xFF1C1B1F);
|
||||
static const Color barTrackColor = Color(0xFFD9D9D9);
|
||||
// The bar fill and Cancel label are #0A84FF == AppColor.primaryColor.
|
||||
|
||||
static const double webSurfaceRadius = 6;
|
||||
static const double mobileSurfaceRadius = 14;
|
||||
static const double webMaxWidth = 629;
|
||||
static const double maxListHeight = 264; // ~4 rows before it scrolls
|
||||
|
||||
static const double chipWidth = 191;
|
||||
static const double chipRadius = 8;
|
||||
static const double thumbnailSize = 20;
|
||||
static const double thumbnailRadius = 2;
|
||||
static const double barHeight = 6;
|
||||
static const double barRadius = 26;
|
||||
static const double rowCloseButtonSize = 40;
|
||||
static const double rowCloseIconSize = 16;
|
||||
static const double headerCloseIconSize = 24;
|
||||
static const double webBarWidth = 157;
|
||||
static const double mobileBarInset = 24;
|
||||
static const double webSizeLabelWidth = 68;
|
||||
static const double mobileSizeLabelWidth = 45;
|
||||
|
||||
static const EdgeInsetsGeometry headerPadding =
|
||||
EdgeInsetsDirectional.symmetric(horizontal: 16, vertical: 8);
|
||||
static const EdgeInsetsGeometry descriptionPadding =
|
||||
EdgeInsetsDirectional.only(start: 16, end: 24, bottom: 8);
|
||||
static const EdgeInsetsGeometry rowPadding =
|
||||
EdgeInsetsDirectional.symmetric(horizontal: 16, vertical: 8);
|
||||
static const EdgeInsetsGeometry chipPadding = EdgeInsets.all(8);
|
||||
static const EdgeInsetsGeometry cancelPadding =
|
||||
EdgeInsets.symmetric(horizontal: 8, vertical: 10);
|
||||
|
||||
static const List<BoxShadow> surfaceShadow = [
|
||||
BoxShadow(color: Color(0x3D424244), offset: Offset(0, 12), blurRadius: 16, spreadRadius: -8),
|
||||
BoxShadow(color: Color(0x3D424244), offset: Offset(0, 12), blurRadius: 48, spreadRadius: 8),
|
||||
BoxShadow(color: Color(0x1F424244), blurRadius: 0, spreadRadius: 0.5),
|
||||
];
|
||||
|
||||
static const TextStyle webTitle = TextStyle(
|
||||
fontSize: 24, height: 28 / 24, fontWeight: FontWeight.w600, color: titleColor);
|
||||
static const TextStyle mobileTitle = TextStyle(
|
||||
fontSize: 16, height: 21 / 16, fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.15, color: titleColor);
|
||||
static const TextStyle webBody = TextStyle(
|
||||
fontSize: 16, height: 20 / 16, fontWeight: FontWeight.w500, color: secondaryTextColor);
|
||||
static const TextStyle mobileBody = TextStyle(
|
||||
fontSize: 13, height: 16 / 13, fontWeight: FontWeight.w400, color: secondaryTextColor);
|
||||
/// The emphasised run inside the description ("a link").
|
||||
static const TextStyle emphasisedBody = TextStyle(color: Color(0xFF0C0C0C));
|
||||
static const TextStyle fileNameTextStyle = TextStyle(
|
||||
fontSize: 14, height: 20 / 14, fontWeight: FontWeight.w500,
|
||||
letterSpacing: 0.1, color: fileNameColor);
|
||||
static const TextStyle cancelTextStyle = TextStyle(
|
||||
fontSize: 14, height: 20 / 14, fontWeight: FontWeight.w500,
|
||||
letterSpacing: 0.1, color: AppColor.primaryColor);
|
||||
|
||||
static TextStyle title(bool isWeb) => isWeb ? webTitle : mobileTitle;
|
||||
static TextStyle body(bool isWeb) => isWeb ? webBody : mobileBody;
|
||||
static TextStyle sizeText(bool isWeb) => isWeb ? webBody : mobileBody;
|
||||
static double sizeLabelWidth(bool isWeb) =>
|
||||
isWeb ? webSizeLabelWidth : mobileSizeLabelWidth;
|
||||
}
|
||||
@@ -5404,6 +5404,52 @@
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"attachingFileTitle": "Attaching file",
|
||||
"@attachingFileTitle": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"driveOversizeDialogMessage": "Your file is larger than {maxSize}. It will be uploaded to Twake Drive and attached as ",
|
||||
"@driveOversizeDialogMessage": {
|
||||
"type": "text",
|
||||
"placeholders_order": [
|
||||
"maxSize"
|
||||
],
|
||||
"placeholders": {
|
||||
"maxSize": {}
|
||||
}
|
||||
},
|
||||
"driveOversizeDialogMessageEmphasis": "a link",
|
||||
"@driveOversizeDialogMessageEmphasis": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"driveUploadRowDone": "Done",
|
||||
"@driveUploadRowDone": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"driveUploadRowFailed": "Failed",
|
||||
"@driveUploadRowFailed": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"driveUploadRowCancelled": "Canceled",
|
||||
"@driveUploadRowCancelled": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"driveOversizeUploadFailed": "Some files could not be uploaded to Drive.",
|
||||
"@driveOversizeUploadFailed": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"driveNoValidAttachment": "No valid attachment",
|
||||
"@driveNoValidAttachment": {
|
||||
"type": "text",
|
||||
|
||||
@@ -5755,6 +5755,56 @@ class AppLocalizations {
|
||||
);
|
||||
}
|
||||
|
||||
String get attachingFileTitle {
|
||||
return Intl.message(
|
||||
'Attaching file',
|
||||
name: 'attachingFileTitle',
|
||||
);
|
||||
}
|
||||
|
||||
String driveOversizeDialogMessage(String maxSize) {
|
||||
return Intl.message(
|
||||
'Your file is larger than $maxSize. It will be uploaded to Twake Drive and attached as ',
|
||||
name: 'driveOversizeDialogMessage',
|
||||
args: [maxSize]
|
||||
);
|
||||
}
|
||||
|
||||
String get driveOversizeDialogMessageEmphasis {
|
||||
return Intl.message(
|
||||
'a link',
|
||||
name: 'driveOversizeDialogMessageEmphasis',
|
||||
);
|
||||
}
|
||||
|
||||
String get driveUploadRowDone {
|
||||
return Intl.message(
|
||||
'Done',
|
||||
name: 'driveUploadRowDone',
|
||||
);
|
||||
}
|
||||
|
||||
String get driveUploadRowFailed {
|
||||
return Intl.message(
|
||||
'Failed',
|
||||
name: 'driveUploadRowFailed',
|
||||
);
|
||||
}
|
||||
|
||||
String get driveUploadRowCancelled {
|
||||
return Intl.message(
|
||||
'Canceled',
|
||||
name: 'driveUploadRowCancelled',
|
||||
);
|
||||
}
|
||||
|
||||
String get driveOversizeUploadFailed {
|
||||
return Intl.message(
|
||||
'Some files could not be uploaded to Drive.',
|
||||
name: 'driveOversizeUploadFailed',
|
||||
);
|
||||
}
|
||||
|
||||
String get driveNoValidAttachment {
|
||||
return Intl.message(
|
||||
'No valid attachment',
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/presentation/views/button/tmail_button_widget.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:percent_indicator/percent_indicator.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/model/upload_task_id.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/dialog/drive_oversize_upload_dialog_view.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/dialog/drive_oversize_upload_row.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/model/drive_oversize_transfer_state.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/providers/drive_oversize_transfer_notifier.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/styles/drive_oversize_upload_dialog_style.dart';
|
||||
|
||||
import '../../../../fixtures/widget_fixtures.dart';
|
||||
import 'drive_oversize_upload_dialog_view_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<MailboxDashBoardController>()])
|
||||
void main() {
|
||||
late MockMailboxDashBoardController dashboard;
|
||||
late ProviderContainer container;
|
||||
|
||||
DriveOversizeTransferState makeItem(
|
||||
String id, {
|
||||
int fileSize = 1000,
|
||||
int sentBytes = 0,
|
||||
DriveOversizeTransferStatus status = DriveOversizeTransferStatus.waiting,
|
||||
}) =>
|
||||
DriveOversizeTransferState(
|
||||
taskId: UploadTaskId(id),
|
||||
fileName: '$id.txt',
|
||||
fileSize: fileSize,
|
||||
sentBytes: sentBytes,
|
||||
status: status,
|
||||
cancelToken: CancelToken(),
|
||||
);
|
||||
|
||||
Future<void> pumpDialog(
|
||||
WidgetTester tester, {
|
||||
required List<DriveOversizeTransferState> items,
|
||||
bool isWebLayout = true,
|
||||
}) async {
|
||||
container.read(driveOversizeTransferProvider.notifier).start(items);
|
||||
await tester.pumpWidget(WidgetFixtures.makeTestableWidget(
|
||||
providerContainer: container,
|
||||
child: DriveOversizeUploadDialogView(
|
||||
imagePaths: ImagePaths(),
|
||||
isWebLayout: isWebLayout,
|
||||
),
|
||||
));
|
||||
// AppLocalizationsDelegate resolves asynchronously; the real subtree
|
||||
// only appears after that first async gap settles. pumpAndSettle can't
|
||||
// be used here — an indeterminate progress bar animates forever.
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
setUp(() {
|
||||
Get.testMode = true;
|
||||
dashboard = MockMailboxDashBoardController();
|
||||
when(dashboard.onStart).thenReturn(InternalFinalCallback<void>(callback: () {}));
|
||||
when(dashboard.onDelete).thenReturn(InternalFinalCallback<void>(callback: () {}));
|
||||
when(dashboard.maxSizeAttachmentsPerEmail).thenReturn(null);
|
||||
Get.put<MailboxDashBoardController>(dashboard);
|
||||
container = ProviderContainer();
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
Get.reset();
|
||||
container.dispose();
|
||||
});
|
||||
|
||||
group('DriveOversizeUploadDialogView::', () {
|
||||
testWidgets('1 item renders 1 row', (tester) async {
|
||||
await pumpDialog(tester, items: [makeItem('a')]);
|
||||
expect(find.byType(DriveOversizeUploadRow), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('3 items render 3 rows in one ListView', (tester) async {
|
||||
await pumpDialog(tester, items: [makeItem('a'), makeItem('b'), makeItem('c')]);
|
||||
expect(find.byType(DriveOversizeUploadRow), findsNWidgets(3));
|
||||
expect(find.byType(ListView), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a row with no bytes renders LinearProgressIndicator', (tester) async {
|
||||
await pumpDialog(tester, items: [makeItem('a', status: DriveOversizeTransferStatus.uploading)]);
|
||||
expect(find.byType(LinearProgressIndicator), findsOneWidget);
|
||||
expect(find.byType(LinearPercentIndicator), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a row with bytes renders LinearPercentIndicator at the right percent', (tester) async {
|
||||
await pumpDialog(tester, items: [
|
||||
makeItem('a', sentBytes: 400, status: DriveOversizeTransferStatus.uploading),
|
||||
]);
|
||||
final indicator = tester.widget<LinearPercentIndicator>(find.byType(LinearPercentIndicator));
|
||||
expect(indicator.percent, closeTo(0.4, 0.001));
|
||||
});
|
||||
|
||||
testWidgets('a linked row renders the bar at 1.0', (tester) async {
|
||||
await pumpDialog(tester, items: [
|
||||
makeItem('a', sentBytes: 1000, status: DriveOversizeTransferStatus.linked),
|
||||
]);
|
||||
final indicator = tester.widget<LinearPercentIndicator>(find.byType(LinearPercentIndicator));
|
||||
expect(indicator.percent, equals(1.0));
|
||||
});
|
||||
|
||||
testWidgets('a progress tick updates that row\'s bar', (tester) async {
|
||||
await pumpDialog(tester, items: [
|
||||
makeItem('a', sentBytes: 400, status: DriveOversizeTransferStatus.uploading),
|
||||
makeItem('b'),
|
||||
]);
|
||||
|
||||
container.read(driveOversizeTransferProvider.notifier)
|
||||
.reportProgress(const UploadTaskId('a'), 700, 1000);
|
||||
await tester.pump();
|
||||
|
||||
final indicator = tester.widget<LinearPercentIndicator>(find.byType(LinearPercentIndicator));
|
||||
expect(indicator.percent, closeTo(0.7, 0.001));
|
||||
});
|
||||
|
||||
testWidgets('a settled row renders no close icon button', (tester) async {
|
||||
await pumpDialog(tester, items: [makeItem('a', status: DriveOversizeTransferStatus.linked)]);
|
||||
final row = tester.widget<DriveOversizeUploadRow>(find.byType(DriveOversizeUploadRow));
|
||||
expect(row.item.status.settled, isTrue);
|
||||
});
|
||||
|
||||
// Cancel is the only TMailButtonWidget built with visible text (the row
|
||||
// and header close buttons use fromIcon, whose text defaults to '').
|
||||
Finder cancelButtonIgnorePointer() => find.ancestor(
|
||||
of: find.byWidgetPredicate((widget) => widget is TMailButtonWidget && widget.text.isNotEmpty),
|
||||
matching: find.byType(IgnorePointer),
|
||||
).first;
|
||||
|
||||
testWidgets('Cancel button is non-interactive once every row is settled', (tester) async {
|
||||
await pumpDialog(tester, items: [makeItem('a', status: DriveOversizeTransferStatus.linked)]);
|
||||
final ignorePointer = tester.widget<IgnorePointer>(cancelButtonIgnorePointer());
|
||||
expect(ignorePointer.ignoring, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('Cancel button is interactive while a row is running', (tester) async {
|
||||
await pumpDialog(tester, items: [makeItem('a', status: DriveOversizeTransferStatus.uploading)]);
|
||||
final ignorePointer = tester.widget<IgnorePointer>(cancelButtonIgnorePointer());
|
||||
expect(ignorePointer.ignoring, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('tapping a row close button cancels only that row', (tester) async {
|
||||
await pumpDialog(tester, items: [makeItem('a'), makeItem('b')]);
|
||||
|
||||
final rowCloseButton = find.descendant(
|
||||
of: find.byType(DriveOversizeUploadRow).first,
|
||||
matching: find.byType(TMailButtonWidget),
|
||||
);
|
||||
await tester.tap(rowCloseButton);
|
||||
await tester.pump();
|
||||
|
||||
final rows = container.read(driveOversizeTransferProvider);
|
||||
expect(rows[0].status, equals(DriveOversizeTransferStatus.cancelled));
|
||||
expect(rows[1].status, equals(DriveOversizeTransferStatus.waiting));
|
||||
});
|
||||
|
||||
testWidgets('tapping the header close cancels every row', (tester) async {
|
||||
await pumpDialog(tester, items: [makeItem('a'), makeItem('b')]);
|
||||
|
||||
final headerClose = find.byWidgetPredicate((widget) =>
|
||||
widget is TMailButtonWidget &&
|
||||
widget.iconSize == DriveOversizeUploadDialogStyle.headerCloseIconSize);
|
||||
await tester.tap(headerClose);
|
||||
await tester.pump();
|
||||
|
||||
final rows = container.read(driveOversizeTransferProvider);
|
||||
expect(rows.every((row) => row.status == DriveOversizeTransferStatus.cancelled), isTrue);
|
||||
});
|
||||
|
||||
testWidgets('isWebLayout true puts the bar inside the row', (tester) async {
|
||||
await pumpDialog(tester, items: [makeItem('a')], isWebLayout: true);
|
||||
final row = tester.widget<DriveOversizeUploadRow>(find.byType(DriveOversizeUploadRow));
|
||||
expect(row.isWebLayout, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('isWebLayout false puts the bar on its own line', (tester) async {
|
||||
await pumpDialog(tester, items: [makeItem('a')], isWebLayout: false);
|
||||
final row = tester.widget<DriveOversizeUploadRow>(find.byType(DriveOversizeUploadRow));
|
||||
expect(row.isWebLayout, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/model/upload_task_id.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/model/drive_oversize_transfer_state.dart';
|
||||
import 'package:tmail_ui_user/features/upload/presentation/providers/drive_oversize_transfer_notifier.dart';
|
||||
|
||||
void main() {
|
||||
late ProviderContainer container;
|
||||
|
||||
setUp(() => container = ProviderContainer());
|
||||
tearDown(() => container.dispose());
|
||||
|
||||
DriveOversizeTransferState makeItem(String id, {int fileSize = 100}) =>
|
||||
DriveOversizeTransferState(
|
||||
taskId: UploadTaskId(id),
|
||||
fileName: '$id.txt',
|
||||
fileSize: fileSize,
|
||||
cancelToken: CancelToken(),
|
||||
);
|
||||
|
||||
group('DriveOversizeTransfer::', () {
|
||||
test('start seeds the rows', () {
|
||||
final notifier = container.read(driveOversizeTransferProvider.notifier);
|
||||
final items = [makeItem('a'), makeItem('b')];
|
||||
|
||||
notifier.start(items);
|
||||
|
||||
expect(container.read(driveOversizeTransferProvider), equals(items));
|
||||
});
|
||||
|
||||
test('reportProgress sets uploading and sentBytes', () {
|
||||
final notifier = container.read(driveOversizeTransferProvider.notifier);
|
||||
notifier.start([makeItem('a', fileSize: 1000)]);
|
||||
|
||||
notifier.reportProgress(const UploadTaskId('a'), 400, 1000);
|
||||
|
||||
final row = container.read(driveOversizeTransferProvider).single;
|
||||
expect(row.status, equals(DriveOversizeTransferStatus.uploading));
|
||||
expect(row.sentBytes, equals(400));
|
||||
});
|
||||
|
||||
test('reportProgress drops a tick that does not move the bar a whole percent', () {
|
||||
final notifier = container.read(driveOversizeTransferProvider.notifier);
|
||||
notifier.start([makeItem('a', fileSize: 1000)]);
|
||||
notifier.reportProgress(const UploadTaskId('a'), 400, 1000);
|
||||
final before = container.read(driveOversizeTransferProvider);
|
||||
|
||||
notifier.reportProgress(const UploadTaskId('a'), 404, 1000);
|
||||
|
||||
expect(identical(container.read(driveOversizeTransferProvider), before), isTrue);
|
||||
});
|
||||
|
||||
test('reportProgress applies a whole-percent move', () {
|
||||
final notifier = container.read(driveOversizeTransferProvider.notifier);
|
||||
notifier.start([makeItem('a', fileSize: 1000)]);
|
||||
notifier.reportProgress(const UploadTaskId('a'), 400, 1000);
|
||||
|
||||
notifier.reportProgress(const UploadTaskId('a'), 410, 1000);
|
||||
|
||||
expect(container.read(driveOversizeTransferProvider).single.sentBytes, equals(410));
|
||||
});
|
||||
|
||||
test('reportProgress applies the first byte so the bar leaves indeterminate', () {
|
||||
final notifier = container.read(driveOversizeTransferProvider.notifier);
|
||||
notifier.start([makeItem('a', fileSize: 100000)]);
|
||||
notifier.markUploading(const UploadTaskId('a'));
|
||||
|
||||
notifier.reportProgress(const UploadTaskId('a'), 1, 100000);
|
||||
|
||||
expect(container.read(driveOversizeTransferProvider).single.sentBytes, equals(1));
|
||||
});
|
||||
|
||||
test('an unknown task id leaves the state untouched', () {
|
||||
final notifier = container.read(driveOversizeTransferProvider.notifier);
|
||||
notifier.start([makeItem('a')]);
|
||||
final before = container.read(driveOversizeTransferProvider);
|
||||
|
||||
notifier.markFailed(const UploadTaskId('zzz'));
|
||||
|
||||
expect(identical(container.read(driveOversizeTransferProvider), before), isTrue);
|
||||
});
|
||||
|
||||
test('markLinked forces sentBytes == fileSize', () {
|
||||
final notifier = container.read(driveOversizeTransferProvider.notifier);
|
||||
notifier.start([makeItem('a', fileSize: 1000)]);
|
||||
|
||||
notifier.markLinked(const UploadTaskId('a'));
|
||||
|
||||
final row = container.read(driveOversizeTransferProvider).single;
|
||||
expect(row.status, equals(DriveOversizeTransferStatus.linked));
|
||||
expect(row.sentBytes, equals(1000));
|
||||
});
|
||||
|
||||
final cancelCases = <({
|
||||
String description,
|
||||
bool markLinkedFirst,
|
||||
DriveOversizeTransferStatus expectedStatus,
|
||||
bool expectedTokenCancelled,
|
||||
})>[
|
||||
(
|
||||
description: 'cancel cancels the token once and sets cancelled',
|
||||
markLinkedFirst: false,
|
||||
expectedStatus: DriveOversizeTransferStatus.cancelled,
|
||||
expectedTokenCancelled: true,
|
||||
),
|
||||
(
|
||||
description: 'cancel on a settled row is a no-op and does not cancel its token',
|
||||
markLinkedFirst: true,
|
||||
expectedStatus: DriveOversizeTransferStatus.linked,
|
||||
expectedTokenCancelled: false,
|
||||
),
|
||||
];
|
||||
for (final cancelCase in cancelCases) {
|
||||
test(cancelCase.description, () {
|
||||
final notifier = container.read(driveOversizeTransferProvider.notifier);
|
||||
final item = makeItem('a');
|
||||
notifier.start([item]);
|
||||
if (cancelCase.markLinkedFirst) notifier.markLinked(const UploadTaskId('a'));
|
||||
|
||||
notifier.cancel(const UploadTaskId('a'));
|
||||
|
||||
final row = container.read(driveOversizeTransferProvider).single;
|
||||
expect(row.status, equals(cancelCase.expectedStatus));
|
||||
expect(item.cancelToken.isCancelled, equals(cancelCase.expectedTokenCancelled));
|
||||
});
|
||||
}
|
||||
|
||||
test('cancelAll cancels only unsettled rows', () {
|
||||
final notifier = container.read(driveOversizeTransferProvider.notifier);
|
||||
final linked = makeItem('a');
|
||||
final waiting = makeItem('b');
|
||||
notifier.start([linked, waiting]);
|
||||
notifier.markLinked(const UploadTaskId('a'));
|
||||
|
||||
notifier.cancelAll();
|
||||
|
||||
final rows = container.read(driveOversizeTransferProvider);
|
||||
expect(rows[0].status, equals(DriveOversizeTransferStatus.linked));
|
||||
expect(rows[1].status, equals(DriveOversizeTransferStatus.cancelled));
|
||||
expect(linked.cancelToken.isCancelled, isFalse);
|
||||
expect(waiting.cancelToken.isCancelled, isTrue);
|
||||
});
|
||||
|
||||
test('allSettled is false on an empty list', () {
|
||||
final notifier = container.read(driveOversizeTransferProvider.notifier);
|
||||
expect(notifier.allSettled, isFalse);
|
||||
});
|
||||
|
||||
test('allSettled is true once every row reached a terminal status', () {
|
||||
final notifier = container.read(driveOversizeTransferProvider.notifier);
|
||||
notifier.start([makeItem('a'), makeItem('b')]);
|
||||
expect(notifier.allSettled, isFalse);
|
||||
|
||||
notifier.markLinked(const UploadTaskId('a'));
|
||||
notifier.markFailed(const UploadTaskId('b'));
|
||||
|
||||
expect(notifier.allSettled, isTrue);
|
||||
});
|
||||
|
||||
test('clear resets to an empty list', () {
|
||||
final notifier = container.read(driveOversizeTransferProvider.notifier);
|
||||
notifier.start([makeItem('a')]);
|
||||
|
||||
notifier.clear();
|
||||
|
||||
expect(container.read(driveOversizeTransferProvider), isEmpty);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user