π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Migrate photo dialogs to bottom sheet components
ashilkn95f2c294345e
diff --git a/mobile/apps/photos/lib/ui/components/action_sheet_widget.dart b/mobile/apps/photos/lib/ui/components/action_sheet_widget.dartindex 7bbbb95ee1..a78939197c 100644--- a/mobile/apps/photos/lib/ui/components/action_sheet_widget.dart+++ b/mobile/apps/photos/lib/ui/components/action_sheet_widget.dart@@ -1,14 +1,12 @@import "dart:io";+import "package:ente_components/ente_components.dart";import 'package:flutter/material.dart';import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';-import 'package:photos/core/constants.dart';import 'package:photos/models/button_result.dart';import 'package:photos/theme/colors.dart';-import 'package:photos/theme/effects.dart';-import 'package:photos/theme/ente_theme.dart';+import 'package:photos/ui/components/buttons/button_component_adapter.dart';import 'package:photos/ui/components/buttons/button_widget.dart';-import 'package:photos/utils/separators_util.dart';enum ActionSheetType { defaultActionSheet, iconOnly }@@ -30,7 +28,7 @@ Future<ButtonResult?> showActionSheet({barrierColor: backdropFaintDark,// On iOS setting it to false causes previous page to shift// So we're explicitly setting it to true- useRootNavigator: Platform.isIOS ? true : false,+ useRootNavigator: Platform.isIOS,context: context,isDismissible: isDismissible,enableDrag: enableDrag,@@ -70,148 +68,75 @@ class ActionSheetWidget extends StatelessWidget {@overrideWidget build(BuildContext context) {- final isTitleAndBodyNull =- title == null && bodyWidget == null && body == null;- final extraWidth = MediaQuery.of(context).size.width - restrictedMaxWidth;- final double? horizontalPadding = extraWidth > 0 ? extraWidth / 2 : null;- return SafeArea(- child: Padding(- padding: EdgeInsets.fromLTRB(- horizontalPadding ?? 12,- 12,- horizontalPadding ?? 12,- 32,- ),- child: Container(- decoration: BoxDecoration(boxShadow: shadowMenuLight),- child: ClipRRect(- borderRadius: const BorderRadius.all(Radius.circular(8)),- child: Container(- color: backgroundElevated2Dark,- child: Padding(- padding: EdgeInsets.fromLTRB(- 24,- 24,- 24,- isTitleAndBodyNull ? 24 : 28,- ),- child: Column(- mainAxisSize: MainAxisSize.min,- children: [- isTitleAndBodyNull- ? const SizedBox.shrink()- : Padding(- padding: const EdgeInsets.only(bottom: 36),- child: ContentContainerWidget(- title: title,- bodyWidget: bodyWidget,- body: body,- bodyHighlight: bodyHighlight,- actionSheetType: actionSheetType,- isCheckIconGreen: isCheckIconGreen,- ),- ),- ActionButtons(actionButtons),- ],- ),- ),- ),- ),- ),- ),+ final hasDefaultContent =+ actionSheetType == ActionSheetType.defaultActionSheet &&+ (bodyWidget != null || body != null || bodyHighlight != null);+ final hasContent =+ title != null ||+ hasDefaultContent ||+ actionSheetType == ActionSheetType.iconOnly;+ final colors = context.componentColors;++ return BottomSheetComponent(+ title: title,+ illustration: actionSheetType == ActionSheetType.iconOnly+ ? Icon(+ Icons.check_outlined,+ size: 48,+ color: isCheckIconGreen ? colors.primary : colors.iconColor,+ )+ : null,+ content: hasDefaultContent+ ? _ActionSheetContent(+ bodyWidget: bodyWidget,+ body: body,+ bodyHighlight: bodyHighlight,+ )+ : null,+ actions: [+ for (final button in actionButtons)+ ButtonComponentAdapter(button: button),+ ],+ showCloseButton: false,+ actionsTopSpacing: hasContent ? Spacing.lg : 0,);}}-class ContentContainerWidget extends StatelessWidget {- final String? title;+class _ActionSheetContent extends StatelessWidget {final Widget? bodyWidget;final String? body;final String? bodyHighlight;- final ActionSheetType actionSheetType;- final bool isCheckIconGreen;- const ContentContainerWidget({- required this.actionSheetType,- required this.isCheckIconGreen,- this.title,- this.bodyWidget,- this.body,- this.bodyHighlight,- super.key,- });+ const _ActionSheetContent({this.bodyWidget, this.body, this.bodyHighlight});@overrideWidget build(BuildContext context) {- final textTheme = getEnteTextTheme(context);- final bool bodyMissing = body == null && bodyWidget == null;- debugPrint("body missing $bodyMissing");+ final colors = context.componentColors;+ final hasBody = body != null || bodyWidget != null;++ if (!hasBody && bodyHighlight == null) {+ return const SizedBox.shrink();+ }+return Column(mainAxisSize: MainAxisSize.min,- //todo: set cross axis to center when icon should be shown in place of body- crossAxisAlignment: actionSheetType == ActionSheetType.defaultActionSheet- ? CrossAxisAlignment.stretch- : CrossAxisAlignment.center,+ crossAxisAlignment: CrossAxisAlignment.stretch,children: [- title == null- ? const SizedBox.shrink()- : Text(- title!,- style: textTheme.largeBold.copyWith(- color: textBaseDark,- ), //constant color- ),- title == null || bodyMissing- ? const SizedBox.shrink()- : const SizedBox(height: 19),- actionSheetType == ActionSheetType.defaultActionSheet- ? bodyMissing- ? const SizedBox.shrink()- : (bodyWidget != null- ? bodyWidget!- : Text(- body!,- style: textTheme.body.copyWith(- color: textMutedDark,- ), //constant color- ))- : Icon(- Icons.check_outlined,- size: 48,- color: isCheckIconGreen- ? getEnteColorScheme(context).primary700- : strokeBaseDark,+ if (hasBody)+ bodyWidget ??+ Text(+ body!,+ style: TextStyles.body.copyWith(color: colors.textLight),),- actionSheetType == ActionSheetType.defaultActionSheet &&- bodyHighlight != null- ? Padding(- padding: const EdgeInsets.only(top: 19.0),- child: Text(- bodyHighlight!,- style: textTheme.body.copyWith(- color: textBaseDark,- ), //constant color- ),- )- : const SizedBox.shrink(),+ if (bodyHighlight != null) ...[+ if (hasBody) const SizedBox(height: Spacing.lg),+ Text(+ bodyHighlight!,+ style: TextStyles.body.copyWith(color: colors.textBase),+ ),+ ],],);}}--class ActionButtons extends StatelessWidget {- final List<Widget> actionButtons;- const ActionButtons(this.actionButtons, {super.key});-- @override- Widget build(BuildContext context) {- final actionButtonsWithSeparators = actionButtons;- return Column(- children:- //Separator height is 8pts in figma. -2pts here as the action- //buttons are 2pts extra in height in code compared to figma because- //of the border(1pt top + 1pt bottom) of action buttons.- addSeparators(actionButtonsWithSeparators, const SizedBox(height: 6)),- );- }-}diff --git a/mobile/apps/photos/lib/ui/components/buttons/button_component_adapter.dart b/mobile/apps/photos/lib/ui/components/buttons/button_component_adapter.dartnew file mode 100644index 0000000000..df480792b8--- /dev/null+++ b/mobile/apps/photos/lib/ui/components/buttons/button_component_adapter.dart@@ -0,0 +1,116 @@+import "dart:async";++import "package:ente_components/ente_components.dart";+import "package:flutter/material.dart";+import "package:modal_bottom_sheet/modal_bottom_sheet.dart";+import "package:photos/models/button_result.dart";+import "package:photos/ui/components/buttons/button_widget.dart";+import "package:photos/ui/components/models/button_type.dart";++const _loadingSurfaceDelay = Duration(milliseconds: 300);+const _successDisplayDuration = Duration(seconds: 1);++class ButtonComponentAdapter extends StatelessWidget {+ const ButtonComponentAdapter({required this.button, super.key});++ final ButtonWidget button;++ @override+ Widget build(BuildContext context) {+ return ButtonComponent(+ label: button.labelText ?? '',+ leading: _icon,+ onTap: button.isDisabled ? null : () => _handleTap(context),+ variant: _variantFor(button.buttonType),+ size: _sizeFor(button.buttonSize),+ isDisabled: button.isDisabled,+ shouldSurfaceExecutionStates: button.shouldSurfaceExecutionStates,+ shouldShowSuccessConfirmation: button.shouldShowSuccessConfirmation,+ progressStatus: button.progressStatus,+ );+ }++ Widget? get _icon {+ if (button.iconWidget != null) {+ return button.iconWidget;+ }+ if (button.icon == null) {+ return null;+ }+ return Icon(button.icon, color: button.iconColor);+ }++ Future<void> _handleTap(BuildContext context) async {+ final stopwatch = Stopwatch()..start();+ try {+ await button.onTap?.call();+ } catch (error) {+ if (button.isInAlert && context.mounted) {+ _popWithResult(+ context,+ ButtonResult(ButtonAction.error, _toException(error)),+ );+ }+ rethrow;+ } finally {+ stopwatch.stop();+ }++ if (!button.isInAlert) {+ return;+ }++ final delay = _popDelay(button, stopwatch.elapsed);+ unawaited(+ Future<void>.delayed(delay, () {+ if (context.mounted) {+ _popWithResult(context, ButtonResult(button.buttonAction));+ }+ }),+ );+ }+}++ButtonComponentVariant _variantFor(ButtonType buttonType) {+ return switch (buttonType) {+ ButtonType.primary ||+ ButtonType.trailingIconPrimary => ButtonComponentVariant.primary,+ ButtonType.secondary ||+ ButtonType.trailingIconSecondary => ButtonComponentVariant.secondary,+ ButtonType.critical => ButtonComponentVariant.critical,+ ButtonType.tertiaryCritical => ButtonComponentVariant.tertiaryCritical,+ ButtonType.tertiary => ButtonComponentVariant.link,+ ButtonType.neutral ||+ ButtonType.trailingIcon => ButtonComponentVariant.neutral,+ };+}++ButtonComponentSize _sizeFor(ButtonSize buttonSize) {+ return switch (buttonSize) {+ ButtonSize.small => ButtonComponentSize.small,+ ButtonSize.large => ButtonComponentSize.large,+ };+}++Duration _popDelay(ButtonWidget button, Duration elapsed) {+ if (!button.shouldSurfaceExecutionStates) {+ return Duration.zero;+ }+ if (button.shouldShowSuccessConfirmation || elapsed >= _loadingSurfaceDelay) {+ return _successDisplayDuration;+ }+ return Duration.zero;+}++void _popWithResult(BuildContext context, ButtonResult result) {+ final route = ModalRoute.of(context);+ if (route != null &&+ route.isCurrent &&+ (route is PopupRoute || route is ModalSheetRoute)) {+ Navigator.of(context).pop(result);+ }+}++Exception _toException(Object error) {+ return error is Exception ? error : Exception(error.toString());+}diff --git a/mobile/apps/photos/lib/ui/components/dialog_widget.dart b/mobile/apps/photos/lib/ui/components/dialog_widget.dartindex 16b55471e6..2e57ddbeaa 100644--- a/mobile/apps/photos/lib/ui/components/dialog_widget.dart+++ b/mobile/apps/photos/lib/ui/components/dialog_widget.dart@@ -1,5 +1,6 @@import 'dart:math';+import "package:ente_components/ente_components.dart";import 'package:flutter/material.dart';import "package:flutter/services.dart";import 'package:photos/core/constants.dart';@@ -9,10 +10,10 @@ import 'package:photos/models/typedefs.dart';import 'package:photos/theme/colors.dart';import 'package:photos/theme/effects.dart';import 'package:photos/theme/ente_theme.dart';+import "package:photos/ui/components/buttons/button_component_adapter.dart";import 'package:photos/ui/components/buttons/button_widget.dart';import 'package:photos/ui/components/models/button_type.dart';import 'package:photos/ui/components/text_input_widget.dart';-import 'package:photos/utils/separators_util.dart';///Will return null if dismissed by tapping outsideFuture<ButtonResult?> showDialogWidget({@@ -24,25 +25,18 @@ Future<ButtonResult?> showDialogWidget({bool isDismissible = true,bool useRootNavigator = false,}) {- return showDialog(- barrierDismissible: isDismissible,+ return showBottomSheetComponent<ButtonResult>(barrierColor: backdropFaintDark,context: context,+ isDismissible: isDismissible,+ enableDrag: isDismissible,useRootNavigator: useRootNavigator,- builder: (context) {- final widthOfScreen = MediaQuery.of(context).size.width;- final isMobileSmall = widthOfScreen <= mobileSmallThreshold;- return Padding(- padding: EdgeInsets.symmetric(horizontal: isMobileSmall ? 8 : 0),- child: Dialog(- insetPadding: EdgeInsets.zero,- child: DialogWidget(- title: title,- body: body,- buttons: buttons,- icon: icon,- ),- ),+ builder: (_) {+ return DialogWidget(+ title: title,+ body: body,+ buttons: buttons,+ icon: icon,);},);@@ -63,46 +57,52 @@ class DialogWidget extends StatelessWidget {@overrideWidget build(BuildContext context) {- final widthOfScreen = MediaQuery.of(context).size.width;- final isMobileSmall = widthOfScreen <= mobileSmallThreshold;- final colorScheme = getEnteColorScheme(context);- return Container(- width: min(widthOfScreen, 320),- padding: isMobileSmall- ? const EdgeInsets.all(0)- : const EdgeInsets.fromLTRB(6, 8, 6, 6),- decoration: BoxDecoration(- color: colorScheme.backgroundElevated,- boxShadow: shadowFloatLight,- borderRadius: const BorderRadius.all(Radius.circular(8)),- ),- child: Padding(- padding: const EdgeInsets.all(16),- child: SingleChildScrollView(- child: Column(- mainAxisSize: MainAxisSize.min,- children: [- ContentContainer(title: title, body: body, icon: icon),- const SizedBox(height: 36),- Actions(buttons),- ],- ),+ final colors = context.componentColors;+ final hasTitle = title.isNotEmpty;+ final hasBody = body?.isNotEmpty == true;+ final hasContent = hasTitle || hasBody || icon != null;++ return BottomSheetComponent(+ title: hasTitle ? title : null,+ illustration: icon == null+ ? null+ : Icon(icon, size: 48, color: colors.iconColor),+ content: hasBody ? _DialogBody(body!) : null,+ actions: [+ for (final button in buttons) ButtonComponentAdapter(button: button),+ ],+ showCloseButton: false,+ actionsTopSpacing: hasContent ? Spacing.xl : 0,+ );+ }+}++class _DialogBody extends StatelessWidget {+ const _DialogBody(this.body);++ final String body;++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ final maxHeight = MediaQuery.sizeOf(context).height * 0.45;+ return ConstrainedBox(+ constraints: BoxConstraints(maxHeight: maxHeight),+ child: SingleChildScrollView(+ child: Text(+ body,+ style: TextStyles.body.copyWith(color: colors.textLight),),),);}}-class ContentContainer extends StatelessWidget {+class _ContentContainer extends StatelessWidget {final String title;final String? body;final IconData? icon;- const ContentContainer({- required this.title,- this.body,- this.icon,- super.key,- });+ const _ContentContainer({required this.title, this.body, this.icon});@overrideWidget build(BuildContext context) {@@ -129,28 +129,6 @@ class ContentContainer extends StatelessWidget {}}-class Actions extends StatelessWidget {- final List<ButtonWidget> buttons;- const Actions(this.buttons, {super.key});-- @override- Widget build(BuildContext context) {- return Column(- children: addSeparators(- buttons,- const SizedBox(- // In figma this white space is of height 8pts. But the Button- // component has 1pts of invisible border by default in code. So two- // 1pts borders will visually make the whitespace 8pts.- // Height of button component in figma = 48, in code = 50 (2pts for- // top + bottom border)- height: 6,- ),- ),- );- }-}-class TextInputDialog extends StatefulWidget {final String title;final String? body;@@ -256,7 +234,7 @@ class _TextInputDialogState extends State<TextInputDialog> {child: Column(mainAxisSize: MainAxisSize.min,children: [- ContentContainer(+ _ContentContainer(title: widget.title,body: widget.body,icon: widget.icon,diff --git a/mobile/apps/photos/lib/utils/delete_file_util.dart b/mobile/apps/photos/lib/utils/delete_file_util.dartindex 497d1b85e6..def016eab8 100644--- a/mobile/apps/photos/lib/utils/delete_file_util.dart+++ b/mobile/apps/photos/lib/utils/delete_file_util.dart@@ -756,8 +756,17 @@ Future<bool> shouldProceedWithDeletion(BuildContext context) async {Future<void> showDeleteSheet(BuildContext context,SelectedFiles selectedFiles,- FilesSplit filesSplit,-) async {+ FilesSplit filesSplit, {+ @visibleForTesting+ Future<void> Function(BuildContext context, List<EnteFile> files)?+ deleteFromRemoteOnlyOverride,+ @visibleForTesting+ Future<void> Function(BuildContext context, List<EnteFile> files)?+ deleteOnDeviceOnlyOverride,+ @visibleForTesting+ Future<void> Function(BuildContext context, List<EnteFile> files)?+ deleteFromEverywhereOverride,+}) async {if (selectedFiles.files.length != filesSplit.count) {throw AssertionError("Unexpected state, #{selectedFiles.files.length} != "@@ -766,6 +775,17 @@ Future<void> showDeleteSheet(}final List<EnteFile> deletableFiles =filesSplit.ownedByCurrentUser + filesSplit.pendingUploads;+ final Future<void> Function(BuildContext context, List<EnteFile> files)+ deleteFromRemoteOnlyAction =+ deleteFromRemoteOnlyOverride ?? deleteFilesFromRemoteOnly;+ final Future<void> Function(BuildContext context, List<EnteFile> files)+ deleteOnDeviceOnlyAction =+ deleteOnDeviceOnlyOverride ??+ (context, files) async => deleteFilesOnDeviceOnly(context, files);+ final Future<void> Function(BuildContext context, List<EnteFile> files)+ deleteFromEverywhereAction =+ deleteFromEverywhereOverride ?? deleteFilesFromEverywhere;+if (deletableFiles.isEmpty && filesSplit.ownedByOtherUsers.isNotEmpty) {showShortToast(context,@@ -784,14 +804,13 @@ Future<void> showDeleteSheet();return;}- await deleteFilesOnDeviceOnly(context, localGalleryDeletableFiles);+ await deleteOnDeviceOnlyAction(context, localGalleryDeletableFiles);selectedFiles.unSelectAll(localGalleryDeletableFiles.toSet());return;}final containsUploadedFile = deletableFiles.any((f) => f.isUploaded);final containsLocalFile = deletableFiles.any((f) => f.localID != null);- final List<ButtonWidget> buttons = [];final bool isBothLocalAndRemote = containsUploadedFile && containsLocalFile;final bool isLocalOnly = !containsUploadedFile;final bool isRemoteOnly = !containsLocalFile;@@ -810,7 +829,7 @@ Future<void> showDeleteSheet(} else {throw AssertionError("Unexpected state");}- // Add option to delete from ente+ final List<ButtonWidget> buttons = [];if (isBothLocalAndRemote || isRemoteOnly) {buttons.add(ButtonWidget(@@ -824,7 +843,7 @@ Future<void> showDeleteSheet(shouldSurfaceExecutionStates: true,isInAlert: true,onTap: () async {- await deleteFilesFromRemoteOnly(context, deletableFiles).then(+ await deleteFromRemoteOnlyAction(context, deletableFiles).then((value) {showShortToast(context,@@ -839,7 +858,6 @@ Future<void> showDeleteSheet(),);}- // Add option to delete from localif (isBothLocalAndRemote || isLocalOnly) {buttons.add(ButtonWidget(@@ -853,7 +871,7 @@ Future<void> showDeleteSheet(shouldSurfaceExecutionStates: false,isInAlert: true,onTap: () async {- await deleteFilesOnDeviceOnly(context, deletableFiles);+ await deleteOnDeviceOnlyAction(context, deletableFiles);},),);@@ -870,7 +888,7 @@ Future<void> showDeleteSheet(shouldSurfaceExecutionStates: true,isInAlert: true,onTap: () async {- await deleteFilesFromEverywhere(context, deletableFiles);+ await deleteFromEverywhereAction(context, deletableFiles);},),);diff --git a/mobile/apps/photos/lib/utils/dialog_util.dart b/mobile/apps/photos/lib/utils/dialog_util.dartindex fa404470ef..cccc372019 100644--- a/mobile/apps/photos/lib/utils/dialog_util.dart+++ b/mobile/apps/photos/lib/utils/dialog_util.dart@@ -18,8 +18,6 @@ import 'package:photos/ui/components/dialog_widget.dart';import 'package:photos/ui/components/models/button_type.dart';import "package:photos/utils/email_util.dart";-typedef DialogBuilder = DialogWidget Function(BuildContext context);-///Will return null if dismissed by tapping outsideFuture<ButtonResult?> showInfoDialog(BuildContext context, {@@ -235,40 +233,6 @@ Future<void> showGenericErrorBottomSheet({);}-DialogWidget choiceDialog({- required String title,- String? body,- required String firstButtonLabel,- String secondButtonLabel = "Cancel",- ButtonType firstButtonType = ButtonType.neutral,- ButtonType secondButtonType = ButtonType.secondary,- ButtonAction firstButtonAction = ButtonAction.first,- ButtonAction secondButtonAction = ButtonAction.cancel,- FutureVoidCallback? firstButtonOnTap,- FutureVoidCallback? secondButtonOnTap,- bool isCritical = false,- IconData? icon,-}) {- final buttons = [- ButtonWidget(- buttonType: isCritical ? ButtonType.critical : firstButtonType,- labelText: firstButtonLabel,- isInAlert: true,- onTap: firstButtonOnTap,- buttonAction: firstButtonAction,- ),- ButtonWidget(- buttonType: secondButtonType,- labelText: secondButtonLabel,- isInAlert: true,- onTap: secondButtonOnTap,- buttonAction: secondButtonAction,- ),- ];-- return DialogWidget(title: title, body: body, buttons: buttons, icon: icon);-}-///Will return null if dismissed by tapping outsideFuture<ButtonResult?> showChoiceDialog(BuildContext context, {diff --git a/mobile/apps/photos/test/ui/components/action_sheet_widget_test.dart b/mobile/apps/photos/test/ui/components/action_sheet_widget_test.dartnew file mode 100644index 0000000000..0d9767dd86--- /dev/null+++ b/mobile/apps/photos/test/ui/components/action_sheet_widget_test.dart@@ -0,0 +1,216 @@+import "package:ente_components/ente_components.dart";+import "package:flutter/material.dart";+import "package:flutter_test/flutter_test.dart";+import "package:photos/ente_theme_data.dart";+import "package:photos/models/button_result.dart";+import "package:photos/ui/components/action_sheet_widget.dart";+import "package:photos/ui/components/buttons/button_widget.dart";+import "package:photos/ui/components/models/button_type.dart";++void main() {+ group("showActionSheet", () {+ testWidgets("renders the compatibility sheet with ente components", (+ tester,+ ) async {+ await _pumpLauncher(+ tester,+ (context) => showActionSheet(+ context: context,+ title: "Delete files?",+ body: "Files will be moved to trash.",+ bodyHighlight: "This applies to all albums.",+ buttons: const [+ ButtonWidget(+ buttonType: ButtonType.neutral,+ labelText: "Delete",+ isInAlert: true,+ buttonAction: ButtonAction.first,+ ),+ ButtonWidget(+ buttonType: ButtonType.secondary,+ labelText: "Cancel",+ isInAlert: true,+ buttonAction: ButtonAction.cancel,+ ),+ ],+ ),+ );++ await _openLauncher(tester);++ expect(find.byType(BottomSheetComponent), findsOneWidget);+ expect(find.byType(ButtonComponent), findsNWidgets(2));+ expect(find.byType(ButtonWidget), findsNothing);+ final buttonComponents = tester+ .widgetList<ButtonComponent>(find.byType(ButtonComponent))+ .toList();+ expect(buttonComponents[0].variant, ButtonComponentVariant.neutral);+ expect(buttonComponents[0].size, ButtonComponentSize.large);+ expect(buttonComponents[1].variant, ButtonComponentVariant.secondary);+ expect(find.text("Delete files?"), findsOneWidget);+ expect(find.text("Files will be moved to trash."), findsOneWidget);+ expect(find.text("This applies to all albums."), findsOneWidget);+ expect(find.byTooltip("Close"), findsNothing);+ });++ testWidgets("returns the tapped button action", (tester) async {+ ButtonResult? result;++ await _pumpLauncher(tester, (context) async {+ result = await showActionSheet(+ context: context,+ buttons: const [+ ButtonWidget(+ buttonType: ButtonType.neutral,+ labelText: "Confirm",+ isInAlert: true,+ buttonAction: ButtonAction.first,+ ),+ ButtonWidget(+ buttonType: ButtonType.secondary,+ labelText: "Cancel",+ isInAlert: true,+ buttonAction: ButtonAction.cancel,+ ),+ ],+ );+ });++ await _openLauncher(tester);+ await tester.tap(find.text("Confirm"));+ await tester.pumpAndSettle();++ expect(result?.action, ButtonAction.first);+ expect(result?.exception, isNull);+ expect(find.byType(BottomSheetComponent), findsNothing);+ });++ testWidgets("preserves the legacy success confirmation delay", (+ tester,+ ) async {+ ButtonResult? result;++ await _pumpLauncher(tester, (context) async {+ result = await showActionSheet(+ context: context,+ buttons: [+ ButtonWidget(+ buttonType: ButtonType.neutral,+ labelText: "Save",+ isInAlert: true,+ buttonAction: ButtonAction.first,+ shouldShowSuccessConfirmation: true,+ onTap: () async {},+ ),+ ],+ );+ });++ await _openLauncher(tester);+ await tester.tap(find.text("Save"));+ await tester.pump();++ expect(result, isNull);+ expect(find.byType(BottomSheetComponent), findsOneWidget);++ await tester.pump(const Duration(milliseconds: 999));++ expect(result, isNull);+ expect(find.byType(BottomSheetComponent), findsOneWidget);++ await tester.pump(const Duration(milliseconds: 1));+ await tester.pumpAndSettle();++ expect(result?.action, ButtonAction.first);+ expect(find.byType(BottomSheetComponent), findsNothing);+ });++ testWidgets("returns an error result when a button callback throws", (+ tester,+ ) async {+ ButtonResult? result;++ await _pumpLauncher(tester, (context) async {+ result = await showActionSheet(+ context: context,+ buttons: [+ ButtonWidget(+ buttonType: ButtonType.neutral,+ labelText: "Fail",+ isInAlert: true,+ buttonAction: ButtonAction.first,+ onTap: () async {+ throw StateError("boom");+ },+ ),+ ],+ );+ });++ await _openLauncher(tester);+ await tester.tap(find.text("Fail"));+ await tester.pumpAndSettle();++ expect(result?.action, ButtonAction.error);+ expect(result?.exception, isA<Exception>());+ expect(find.byType(BottomSheetComponent), findsNothing);+ });++ testWidgets("renders custom body widgets and icon-only sheets", (+ tester,+ ) async {+ await _pumpLauncher(+ tester,+ (context) => showActionSheet(+ context: context,+ title: "Done",+ bodyWidget: const Text("Custom body"),+ actionSheetType: ActionSheetType.iconOnly,+ isCheckIconGreen: true,+ buttons: const [+ ButtonWidget(+ buttonType: ButtonType.secondary,+ labelText: "Close",+ isInAlert: true,+ buttonAction: ButtonAction.cancel,+ ),+ ],+ ),+ );++ await _openLauncher(tester);++ expect(find.byType(BottomSheetComponent), findsOneWidget);+ expect(find.byIcon(Icons.check_outlined), findsOneWidget);+ expect(find.text("Done"), findsOneWidget);+ expect(find.text("Custom body"), findsNothing);+ expect(find.text("Close"), findsOneWidget);+ });+ });+}++Future<void> _pumpLauncher(+ WidgetTester tester,+ Future<void> Function(BuildContext context) onOpen,+) async {+ await tester.pumpWidget(+ MaterialApp(+ theme: darkThemeData,+ home: Scaffold(+ body: Builder(+ builder: (context) {+ return TextButton(+ onPressed: () async => onOpen(context),+ child: const Text("Open sheet"),+ );+ },+ ),+ ),+ ),+ );+}++Future<void> _openLauncher(WidgetTester tester) async {+ await tester.tap(find.text("Open sheet"));+ await tester.pumpAndSettle();+}diff --git a/mobile/apps/photos/test/ui/components/dialog_widget_test.dart b/mobile/apps/photos/test/ui/components/dialog_widget_test.dartnew file mode 100644index 0000000000..88d41d1314--- /dev/null+++ b/mobile/apps/photos/test/ui/components/dialog_widget_test.dart@@ -0,0 +1,232 @@+import "package:ente_components/ente_components.dart";+import "package:flutter/material.dart";+import "package:flutter_test/flutter_test.dart";+import "package:photos/ente_theme_data.dart";+import "package:photos/models/button_result.dart";+import "package:photos/ui/components/buttons/button_widget.dart";+import "package:photos/ui/components/dialog_widget.dart";+import "package:photos/ui/components/models/button_type.dart";+import "package:photos/utils/dialog_util.dart";++void main() {+ group("showDialogWidget", () {+ testWidgets("renders the compatibility sheet with ente components", (+ tester,+ ) async {+ await _pumpLauncher(+ tester,+ (context) => showDialogWidget(+ context: context,+ title: "Invite",+ body: "Share this invite with a friend.",+ icon: Icons.info_outline,+ buttons: const [+ ButtonWidget(+ buttonType: ButtonType.neutral,+ labelText: "Send invite",+ icon: Icons.share_outlined,+ isInAlert: true,+ buttonAction: ButtonAction.first,+ ),+ ButtonWidget(+ buttonType: ButtonType.secondary,+ labelText: "Cancel",+ isInAlert: true,+ buttonAction: ButtonAction.cancel,+ ),+ ],+ ),+ );++ await _openLauncher(tester);++ expect(find.byType(BottomSheetComponent), findsOneWidget);+ expect(find.byType(ButtonComponent), findsNWidgets(2));+ expect(find.byType(ButtonWidget), findsNothing);+ expect(find.byType(Dialog), findsNothing);+ expect(find.text("Invite"), findsOneWidget);+ expect(find.text("Share this invite with a friend."), findsOneWidget);+ expect(find.byIcon(Icons.info_outline), findsOneWidget);+ expect(find.byIcon(Icons.share_outlined), findsOneWidget);+ final button = tester.widget<ButtonComponent>(+ find.widgetWithText(ButtonComponent, "Send invite"),+ );+ expect(button.variant, ButtonComponentVariant.neutral);+ expect(button.leading, isNotNull);+ });++ testWidgets("returns the tapped button action", (tester) async {+ ButtonResult? result;++ await _pumpLauncher(tester, (context) async {+ result = await showDialogWidget(+ context: context,+ title: "Confirm",+ buttons: const [+ ButtonWidget(+ buttonType: ButtonType.neutral,+ labelText: "Continue",+ isInAlert: true,+ buttonAction: ButtonAction.first,+ ),+ ],+ );+ });++ await _openLauncher(tester);+ await tester.tap(find.text("Continue"));+ await tester.pumpAndSettle();++ expect(result?.action, ButtonAction.first);+ expect(result?.exception, isNull);+ expect(find.byType(BottomSheetComponent), findsNothing);+ });++ testWidgets("returns null when dismissed", (tester) async {+ ButtonResult? result;+ var completed = false;++ await _pumpLauncher(tester, (context) async {+ result = await showDialogWidget(+ context: context,+ title: "Dismissible",+ buttons: const [+ ButtonWidget(+ buttonType: ButtonType.secondary,+ labelText: "Cancel",+ isInAlert: true,+ buttonAction: ButtonAction.cancel,+ ),+ ],+ );+ completed = true;+ });++ await _openLauncher(tester);+ await tester.tapAt(const Offset(10, 10));+ await tester.pumpAndSettle();++ expect(completed, isTrue);+ expect(result, isNull);+ expect(find.byType(BottomSheetComponent), findsNothing);+ });++ testWidgets("honors non-dismissible sheets", (tester) async {+ await _pumpLauncher(+ tester,+ (context) => showDialogWidget(+ context: context,+ title: "Required",+ isDismissible: false,+ buttons: const [+ ButtonWidget(+ buttonType: ButtonType.secondary,+ labelText: "OK",+ isInAlert: true,+ buttonAction: ButtonAction.first,+ ),+ ],+ ),+ );++ await _openLauncher(tester);+ await tester.tapAt(const Offset(10, 10));+ await tester.pumpAndSettle();++ expect(find.byType(BottomSheetComponent), findsOneWidget);++ await tester.tap(find.text("OK"));+ await tester.pumpAndSettle();+ expect(find.byType(BottomSheetComponent), findsNothing);+ });++ testWidgets("returns an error result when a button callback throws", (+ tester,+ ) async {+ ButtonResult? result;++ await _pumpLauncher(tester, (context) async {+ result = await showDialogWidget(+ context: context,+ title: "Failure",+ buttons: [+ ButtonWidget(+ buttonType: ButtonType.neutral,+ labelText: "Fail",+ isInAlert: true,+ buttonAction: ButtonAction.first,+ onTap: () async {+ throw StateError("boom");+ },+ ),+ ],+ );+ });++ await _openLauncher(tester);+ await tester.tap(find.text("Fail"));+ await tester.pumpAndSettle();++ expect(result?.action, ButtonAction.error);+ expect(result?.exception, isA<Exception>());+ expect(find.byType(BottomSheetComponent), findsNothing);+ });+ });++ testWidgets("showChoiceDialog uses the migrated dialog sheet", (+ tester,+ ) async {+ ButtonResult? result;++ await _pumpLauncher(tester, (context) async {+ result = await showChoiceDialog(+ context,+ title: "Remove item?",+ body: "This can be restored later.",+ firstButtonLabel: "Remove",+ secondButtonLabel: "Keep",+ isCritical: true,+ );+ });++ await _openLauncher(tester);++ expect(find.byType(BottomSheetComponent), findsOneWidget);+ final removeButton = tester.widget<ButtonComponent>(+ find.widgetWithText(ButtonComponent, "Remove"),+ );+ expect(removeButton.variant, ButtonComponentVariant.critical);++ await tester.tap(find.text("Keep"));+ await tester.pumpAndSettle();++ expect(result?.action, ButtonAction.cancel);+ expect(find.byType(BottomSheetComponent), findsNothing);+ });+}++Future<void> _pumpLauncher(+ WidgetTester tester,+ Future<dynamic> Function(BuildContext context) onOpen,+) async {+ await tester.pumpWidget(+ MaterialApp(+ theme: darkThemeData,+ home: Scaffold(+ body: Builder(+ builder: (context) {+ return TextButton(+ onPressed: () async => onOpen(context),+ child: const Text("Open dialog"),+ );+ },+ ),+ ),+ ),+ );+}++Future<void> _openLauncher(WidgetTester tester) async {+ await tester.tap(find.text("Open dialog"));+ await tester.pumpAndSettle();+}diff --git a/mobile/apps/photos/test/utils/delete_file_util_test.dart b/mobile/apps/photos/test/utils/delete_file_util_test.dartnew file mode 100644index 0000000000..0ea3ebaad2--- /dev/null+++ b/mobile/apps/photos/test/utils/delete_file_util_test.dart@@ -0,0 +1,488 @@+import 'package:dio/dio.dart';+import 'package:ente_components/ente_components.dart';+import 'package:flutter/material.dart';+import 'package:flutter_easyloading/flutter_easyloading.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:package_info_plus/package_info_plus.dart';+import 'package:photos/app_mode.dart';+import 'package:photos/ente_theme_data.dart';+import 'package:photos/generated/intl/app_localizations.dart';+import 'package:photos/models/file/file.dart';+import 'package:photos/models/files_split.dart';+import 'package:photos/models/selected_files.dart';+import 'package:photos/service_locator.dart';+import 'package:photos/utils/delete_file_util.dart';+import 'package:shared_preferences/shared_preferences.dart';++void main() {+ setUpAll(() async {+ SharedPreferences.setMockInitialValues({});+ final prefs = await SharedPreferences.getInstance();+ ServiceLocator.instance.init(+ prefs,+ Dio(),+ Dio(),+ PackageInfo(+ appName: 'Photos',+ packageName: 'photos',+ version: '1.0.0',+ buildNumber: '1',+ ),+ );+ });++ setUp(() async {+ await localSettings.setAppMode(AppMode.enteGallery);+ });++ group('showDeleteSheet', () {+ testWidgets(+ 'matches the legacy mixed local and remote delete action sheet',+ (tester) async {+ final file = _file(generatedID: 1, uploadedID: 11, localID: 'local-1');+ final selectedFiles = SelectedFiles()..selectAll({file});++ await _pumpDeleteSheet(+ tester,+ selectedFiles: selectedFiles,+ split: FilesSplit(+ pendingUploads: const [],+ ownedByCurrentUser: [file],+ ownedByOtherUsers: const [],+ ),+ );++ expect(find.byType(BottomSheetComponent), findsOneWidget);+ expect(+ find.text('Some items are in both Ente and your device.'),+ findsOneWidget,+ );+ expect(+ find.text('They will be deleted from all albums.'),+ findsOneWidget,+ );+ expect(find.byType(ButtonComponent), findsNWidgets(4));+ expect(find.byTooltip('Close'), findsNothing);+ _expectVisibleButtonsInOrder(tester, [+ 'Delete from Ente',+ 'Delete from device',+ 'Delete from both',+ 'Cancel',+ ]);+ },+ );++ testWidgets('matches the legacy remote-only delete action sheet', (+ tester,+ ) async {+ final file = _file(generatedID: 2, uploadedID: 12);+ final selectedFiles = SelectedFiles()..selectAll({file});++ await _pumpDeleteSheet(+ tester,+ selectedFiles: selectedFiles,+ split: FilesSplit(+ pendingUploads: const [],+ ownedByCurrentUser: [file],+ ownedByOtherUsers: const [],+ ),+ );++ expect(+ find.text(+ 'Selected items will be deleted from all albums and moved to trash.',+ ),+ findsOneWidget,+ );+ expect(find.text('They will be deleted from all albums.'), findsNothing);+ expect(find.byType(ButtonComponent), findsNWidgets(2));+ expect(find.text('Delete from Ente'), findsNothing);+ expect(find.text('Delete from device'), findsNothing);+ expect(find.text('Delete from both'), findsNothing);+ _expectVisibleButtonsInOrder(tester, ['Yes, delete', 'Cancel']);+ });++ testWidgets('matches the legacy local-only delete action sheet', (+ tester,+ ) async {+ final file = _file(generatedID: 3, localID: 'local-3');+ final selectedFiles = SelectedFiles()..selectAll({file});++ await _pumpDeleteSheet(+ tester,+ selectedFiles: selectedFiles,+ split: FilesSplit(+ pendingUploads: [file],+ ownedByCurrentUser: const [],+ ownedByOtherUsers: const [],+ ),+ );++ expect(+ find.text('These items will be deleted from your device.'),+ findsOneWidget,+ );+ expect(find.text('They will be deleted from all albums.'), findsNothing);+ expect(find.byType(ButtonComponent), findsNWidgets(2));+ expect(find.text('Delete from Ente'), findsNothing);+ expect(find.text('Delete from device'), findsNothing);+ expect(find.text('Delete from both'), findsNothing);+ _expectVisibleButtonsInOrder(tester, ['Yes, delete', 'Cancel']);+ });++ testWidgets('cancel clears the selection like the legacy action sheet', (+ tester,+ ) async {+ final file = _file(generatedID: 4, uploadedID: 14);+ final selectedFiles = SelectedFiles()..selectAll({file});++ await _pumpDeleteSheet(+ tester,+ selectedFiles: selectedFiles,+ split: FilesSplit(+ pendingUploads: const [],+ ownedByCurrentUser: [file],+ ownedByOtherUsers: const [],+ ),+ );++ await tester.tap(find.text('Cancel'));+ await tester.pumpAndSettle();++ expect(find.byType(BottomSheetComponent), findsNothing);+ expect(selectedFiles.files, isEmpty);+ });++ testWidgets(+ 'remote delete action uses the legacy remote delete path and clears selection',+ (tester) async {+ final file = _file(generatedID: 7, uploadedID: 17);+ final selectedFiles = SelectedFiles()..selectAll({file});+ var remoteDeleteCalls = 0;+ List<EnteFile>? remoteDeleteFiles;++ await _pumpDeleteSheet(+ tester,+ selectedFiles: selectedFiles,+ split: FilesSplit(+ pendingUploads: const [],+ ownedByCurrentUser: [file],+ ownedByOtherUsers: const [],+ ),+ deleteFromRemoteOnlyOverride: (context, files) async {+ remoteDeleteCalls++;+ remoteDeleteFiles = List.of(files);+ },+ );++ await tester.tap(find.text('Yes, delete'));+ await tester.pumpAndSettle();++ expect(remoteDeleteCalls, 1);+ expect(remoteDeleteFiles, [file]);+ expect(find.byType(BottomSheetComponent), findsNothing);+ expect(selectedFiles.files, isEmpty);++ await _settleToast(tester);+ },+ );++ testWidgets(+ 'device delete action uses the legacy device delete path and clears selection',+ (tester) async {+ final file = _file(generatedID: 8, localID: 'local-8');+ final selectedFiles = SelectedFiles()..selectAll({file});+ var deviceDeleteCalls = 0;+ List<EnteFile>? deviceDeleteFiles;++ await _pumpDeleteSheet(+ tester,+ selectedFiles: selectedFiles,+ split: FilesSplit(+ pendingUploads: [file],+ ownedByCurrentUser: const [],+ ownedByOtherUsers: const [],+ ),+ deleteOnDeviceOnlyOverride: (context, files) async {+ deviceDeleteCalls++;+ deviceDeleteFiles = List.of(files);+ },+ );++ await tester.tap(find.text('Yes, delete'));+ await tester.pumpAndSettle();++ expect(deviceDeleteCalls, 1);+ expect(deviceDeleteFiles, [file]);+ expect(find.byType(BottomSheetComponent), findsNothing);+ expect(selectedFiles.files, isEmpty);+ },+ );++ testWidgets(+ 'delete from both uses the legacy everywhere delete path and clears selection',+ (tester) async {+ final file = _file(generatedID: 9, uploadedID: 19, localID: 'local-9');+ final selectedFiles = SelectedFiles()..selectAll({file});+ var everywhereDeleteCalls = 0;+ List<EnteFile>? everywhereDeleteFiles;++ await _pumpDeleteSheet(+ tester,+ selectedFiles: selectedFiles,+ split: FilesSplit(+ pendingUploads: const [],+ ownedByCurrentUser: [file],+ ownedByOtherUsers: const [],+ ),+ deleteFromEverywhereOverride: (context, files) async {+ everywhereDeleteCalls++;+ everywhereDeleteFiles = List.of(files);+ },+ );++ await tester.tap(find.text('Delete from both'));+ await tester.pumpAndSettle();++ expect(everywhereDeleteCalls, 1);+ expect(everywhereDeleteFiles, [file]);+ expect(find.byType(BottomSheetComponent), findsNothing);+ expect(selectedFiles.files, isEmpty);+ },+ );++ testWidgets(+ 'barrier dismissal clears the selection like the legacy null result',+ (tester) async {+ final file = _file(generatedID: 5, uploadedID: 15);+ final selectedFiles = SelectedFiles()..selectAll({file});++ await _pumpDeleteSheet(+ tester,+ selectedFiles: selectedFiles,+ split: FilesSplit(+ pendingUploads: const [],+ ownedByCurrentUser: [file],+ ownedByOtherUsers: const [],+ ),+ );++ await tester.tapAt(const Offset(10, 10));+ await tester.pumpAndSettle();++ expect(find.byType(BottomSheetComponent), findsNothing);+ expect(selectedFiles.files, isEmpty);+ },+ );++ testWidgets('only other-user files keep the legacy no-sheet behavior', (+ tester,+ ) async {+ final file = _file(generatedID: 6, uploadedID: 16, ownerID: 2);+ final selectedFiles = SelectedFiles()..selectAll({file});++ await _pumpDeleteSheet(+ tester,+ selectedFiles: selectedFiles,+ split: FilesSplit(+ pendingUploads: const [],+ ownedByCurrentUser: const [],+ ownedByOtherUsers: [file],+ ),+ );++ expect(find.byType(BottomSheetComponent), findsNothing);+ expect(selectedFiles.files, contains(file));++ await _settleToast(tester);+ });++ testWidgets(+ 'local gallery mode deletes device files without showing a confirmation sheet',+ (tester) async {+ await localSettings.setAppMode(AppMode.localGallery);+ final file = _file(generatedID: 10, localID: 'local-10');+ final selectedFiles = SelectedFiles()..selectAll({file});+ var deviceDeleteCalls = 0;+ List<EnteFile>? deviceDeleteFiles;++ await _pumpDeleteSheet(+ tester,+ selectedFiles: selectedFiles,+ split: FilesSplit(+ pendingUploads: [file],+ ownedByCurrentUser: const [],+ ownedByOtherUsers: const [],+ ),+ deleteOnDeviceOnlyOverride: (context, files) async {+ deviceDeleteCalls++;+ deviceDeleteFiles = List.of(files);+ },+ );++ expect(find.byType(BottomSheetComponent), findsNothing);+ expect(deviceDeleteCalls, 1);+ expect(deviceDeleteFiles, [file]);+ expect(selectedFiles.files, isEmpty);+ },+ );++ testWidgets(+ 'local gallery mode with no device files keeps the legacy no-sheet behavior',+ (tester) async {+ await localSettings.setAppMode(AppMode.localGallery);+ final file = _file(generatedID: 11, uploadedID: 21);+ final selectedFiles = SelectedFiles()..selectAll({file});+ var deviceDeleteCalls = 0;++ await _pumpDeleteSheet(+ tester,+ selectedFiles: selectedFiles,+ split: FilesSplit(+ pendingUploads: const [],+ ownedByCurrentUser: [file],+ ownedByOtherUsers: const [],+ ),+ deleteOnDeviceOnlyOverride: (context, files) async {+ deviceDeleteCalls++;+ },+ );++ expect(find.byType(BottomSheetComponent), findsNothing);+ expect(deviceDeleteCalls, 0);+ expect(selectedFiles.files, contains(file));++ await _settleToast(tester);+ },+ );++ testWidgets('mismatched selection and split counts still assert', (+ tester,+ ) async {+ final selectedFile = _file(generatedID: 12, uploadedID: 22);+ final splitFile = _file(generatedID: 13, uploadedID: 23);+ final selectedFiles = SelectedFiles()..selectAll({selectedFile});+ late BuildContext context;++ await tester.pumpWidget(+ MaterialApp(+ theme: darkThemeData,+ localizationsDelegates: AppLocalizations.localizationsDelegates,+ supportedLocales: AppLocalizations.supportedLocales,+ home: Builder(+ builder: (builderContext) {+ context = builderContext;+ return const SizedBox.shrink();+ },+ ),+ ),+ );++ await expectLater(+ showDeleteSheet(+ context,+ selectedFiles,+ FilesSplit(+ pendingUploads: const [],+ ownedByCurrentUser: [selectedFile, splitFile],+ ownedByOtherUsers: const [],+ ),+ ),+ throwsA(isA<AssertionError>()),+ );+ });+ });+}++Future<void> _pumpDeleteSheet(+ WidgetTester tester, {+ required SelectedFiles selectedFiles,+ required FilesSplit split,+ Future<void> Function(BuildContext context, List<EnteFile> files)?+ deleteFromRemoteOnlyOverride,+ Future<void> Function(BuildContext context, List<EnteFile> files)?+ deleteOnDeviceOnlyOverride,+ Future<void> Function(BuildContext context, List<EnteFile> files)?+ deleteFromEverywhereOverride,+}) async {+ await tester.pumpWidget(+ _TestApp(+ onOpen: (context) async {+ await showDeleteSheet(+ context,+ selectedFiles,+ split,+ deleteFromRemoteOnlyOverride: deleteFromRemoteOnlyOverride,+ deleteOnDeviceOnlyOverride: deleteOnDeviceOnlyOverride,+ deleteFromEverywhereOverride: deleteFromEverywhereOverride,+ );+ },+ ),+ );++ await tester.tap(find.text('Open delete sheet'));+ await tester.pumpAndSettle();+}++EnteFile _file({+ required int generatedID,+ int? uploadedID,+ int ownerID = 1,+ String? localID,+}) {+ return EnteFile()+ ..generatedID = generatedID+ ..uploadedFileID = uploadedID+ ..ownerID = ownerID+ ..collectionID = uploadedID == null ? null : 100+ ..localID = localID;+}++Future<void> _settleToast(WidgetTester tester) async {+ await tester.pump(const Duration(seconds: 1));+ await tester.pumpAndSettle();+}++void _expectVisibleButtonsInOrder(WidgetTester tester, List<String> labels) {+ for (final label in labels) {+ expect(find.text(label), findsOneWidget);+ }++ for (var i = 0; i < labels.length - 1; i++) {+ final firstTop = tester.getTopLeft(find.text(labels[i])).dy;+ final secondTop = tester.getTopLeft(find.text(labels[i + 1])).dy;+ expect(+ firstTop,+ lessThan(secondTop),+ reason: '${labels[i]} should appear above ${labels[i + 1]}',+ );+ }+}++class _TestApp extends StatelessWidget {+ const _TestApp({required this.onOpen});++ final Future<void> Function(BuildContext context) onOpen;++ @override+ Widget build(BuildContext context) {+ return MaterialApp(+ theme: darkThemeData,+ localizationsDelegates: AppLocalizations.localizationsDelegates,+ supportedLocales: AppLocalizations.supportedLocales,+ builder: EasyLoading.init(),+ home: Scaffold(+ body: Builder(+ builder: (context) {+ return TextButton(+ onPressed: () async {+ await onOpen(context);+ },+ child: const Text('Open delete sheet'),+ );+ },+ ),+ ),+ );+ }+}diff --git a/mobile/packages/ente_components/lib/components/buttons/button_component.dart b/mobile/packages/ente_components/lib/components/buttons/button_component.dartindex 55a6154dcc..2770157e4c 100644--- a/mobile/packages/ente_components/lib/components/buttons/button_component.dart+++ b/mobile/packages/ente_components/lib/components/buttons/button_component.dart@@ -38,6 +38,7 @@ class ButtonComponent extends StatefulWidget {this.shouldSurfaceExecutionStates = true,this.shouldShowSuccessConfirmation = false,this.progressStatus,+ this.leading,});final String label;@@ -48,6 +49,7 @@ class ButtonComponent extends StatefulWidget {final bool shouldSurfaceExecutionStates;final bool shouldShowSuccessConfirmation;final ValueListenable<String>? progressStatus;+ final Widget? leading;@overrideState<ButtonComponent> createState() => _ButtonComponentState();@@ -247,6 +249,13 @@ class _ButtonComponentState extends State<ButtonComponent>: MainAxisSize.min,mainAxisAlignment: MainAxisAlignment.center,children: [+ if (widget.leading != null) ...[+ IconTheme.merge(+ data: IconThemeData(color: foreground, size: IconSizes.small),+ child: widget.leading!,+ ),+ const SizedBox(width: Spacing.sm),+ ],if (widget.variant != ButtonComponentVariant.link)Flexible(child: label)elsediff --git a/mobile/packages/ente_components/test/components/button_test.dart b/mobile/packages/ente_components/test/components/button_test.dartindex abee6f8a63..8c46f8447e 100644--- a/mobile/packages/ente_components/test/components/button_test.dart+++ b/mobile/packages/ente_components/test/components/button_test.dart@@ -30,6 +30,21 @@ void main() {expect(tapCount, 1);});+ testWidgets("ButtonComponent renders leading content", (tester) async {+ await tester.pumpWidget(+ _wrap(+ ButtonComponent(+ label: "Share",+ leading: const Icon(Icons.share_outlined),+ onTap: () {},+ ),+ ),+ );++ expect(find.text("Share"), findsOneWidget);+ expect(find.byIcon(Icons.share_outlined), findsOneWidget);+ });+testWidgets("Small ButtonComponent shrink-wraps content without a minimum width",(tester) async {