immich/mobile/test/modules/activity/dismissible_activity_test.dart
idubnori 5e6087ea28
feat(mobile): chat-style album activities timeline (#23185)
* feat(mobile): open assetviewer via album activities page

* adjust ui behavior: keep current asset & disable initial forcus

* init of v2...

* refactoring...

* refactor: remove _DismissibleWrapper

* feat: initial scrolling to bottom

* refactor: use feature toggle

* refactor: new route page

* fix: file name, dcm analyze

* fix: test failure

* fix: remove toggle and the exisitng style based on review feedback

* refactorr: rename methods for clarity in comment bubble widget

* chore: styling

---------

Co-authored-by: Alex <alex.tran1502@gmail.com>
2025-10-29 13:45:28 +00:00

100 lines
3.5 KiB
Dart

@Tags(['widget'])
library;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:immich_mobile/models/activities/activity.model.dart';
import 'package:immich_mobile/widgets/activities/activity_tile.dart';
import 'package:immich_mobile/widgets/activities/dismissible_activity.dart';
import 'package:immich_mobile/providers/asset_viewer/current_asset.provider.dart';
import 'package:immich_mobile/widgets/common/confirm_dialog.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../../fixtures/user.stub.dart';
import '../../test_utils.dart';
import '../../widget_tester_extensions.dart';
import '../asset_viewer/asset_viewer_mocks.dart';
final activity = Activity(id: '1', createdAt: DateTime(100), type: ActivityType.like, user: UserStub.admin);
void main() {
late MockCurrentAssetProvider assetProvider;
late List<Override> overrides;
setUpAll(() => TestUtils.init());
setUp(() {
assetProvider = MockCurrentAssetProvider();
overrides = [currentAssetProvider.overrideWith(() => assetProvider)];
});
testWidgets('Returns a Dismissible', (tester) async {
await tester.pumpConsumerWidget(
DismissibleActivity('1', ActivityTile(activity), onDismiss: (_) {}),
overrides: overrides,
);
expect(find.byType(Dismissible), findsOneWidget);
});
testWidgets('Dialog displayed when onDismiss is set', (tester) async {
await tester.pumpConsumerWidget(
DismissibleActivity('1', ActivityTile(activity), onDismiss: (_) {}),
overrides: overrides,
);
final dismissible = find.byType(Dismissible);
await tester.drag(dismissible, const Offset(500, 0));
await tester.pumpAndSettle();
expect(find.byType(ConfirmDialog), findsOneWidget);
});
testWidgets('Ok action in ConfirmDialog should call onDismiss with activityId', (tester) async {
String? receivedActivityId;
await tester.pumpConsumerWidget(
DismissibleActivity('1', ActivityTile(activity), onDismiss: (id) => receivedActivityId = id),
overrides: overrides,
);
final dismissible = find.byType(Dismissible);
await tester.drag(dismissible, const Offset(-500, 0));
await tester.pumpAndSettle();
final okButton = find.text('delete');
await tester.tap(okButton);
await tester.pumpAndSettle();
expect(receivedActivityId, '1');
});
testWidgets('Delete icon for background if onDismiss is set', (tester) async {
await tester.pumpConsumerWidget(
DismissibleActivity('1', ActivityTile(activity), onDismiss: (_) {}),
overrides: overrides,
);
final dismissible = find.byType(Dismissible);
await tester.drag(dismissible, const Offset(500, 0));
await tester.pumpAndSettle();
expect(find.byIcon(Icons.delete_sweep_rounded), findsOneWidget);
});
testWidgets('No delete dialog if onDismiss is not set', (tester) async {
await tester.pumpConsumerWidget(DismissibleActivity('1', ActivityTile(activity)), overrides: overrides);
// When onDismiss is not set, the widget should not be wrapped by a Dismissible
expect(find.byType(Dismissible), findsNothing);
expect(find.byType(ConfirmDialog), findsNothing);
});
testWidgets('No icon for background if onDismiss is not set', (tester) async {
await tester.pumpConsumerWidget(DismissibleActivity('1', ActivityTile(activity)), overrides: overrides);
// No Dismissible should exist when onDismiss is not provided, so no delete icon either
expect(find.byType(Dismissible), findsNothing);
expect(find.byIcon(Icons.delete_sweep_rounded), findsNothing);
});
}