fix: compass-app bug in dismissable homescreen item (#2449)

compass-app
Miguel Beltran 1 month ago committed by GitHub
parent 0ab945f163
commit 6dc8abefd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -100,10 +100,20 @@ class _HomeScreenState extends State<HomeScreen> {
booking: widget.viewModel.bookings[index],
onTap: () => context.push(Routes.bookingWithId(
widget.viewModel.bookings[index].id)),
onDismissed: (_) =>
widget.viewModel.deleteBooking.execute(
widget.viewModel.bookings[index].id,
),
confirmDismiss: (_) async {
// wait for command to complete
await widget.viewModel.deleteBooking.execute(
widget.viewModel.bookings[index].id,
);
// if command completed successfully, return true
if (widget.viewModel.deleteBooking.completed) {
// removes the dismissable from the list
return true;
} else {
// the dismissable stays in the list
return false;
}
},
),
)
],
@ -141,19 +151,19 @@ class _Booking extends StatelessWidget {
super.key,
required this.booking,
required this.onTap,
required this.onDismissed,
required this.confirmDismiss,
});
final BookingSummary booking;
final GestureTapCallback onTap;
final DismissDirectionCallback onDismissed;
final ConfirmDismissCallback confirmDismiss;
@override
Widget build(BuildContext context) {
return Dismissible(
key: ValueKey(booking.id),
direction: DismissDirection.endToStart,
onDismissed: onDismissed,
confirmDismiss: confirmDismiss,
child: InkWell(
onTap: onTap,
child: Padding(

@ -7,6 +7,7 @@ import 'package:compass_app/data/repositories/itinerary_config/itinerary_config_
import 'package:compass_app/routing/routes.dart';
import 'package:compass_app/ui/home/view_models/home_viewmodel.dart';
import 'package:compass_app/ui/home/widgets/home_screen.dart';
import 'package:compass_app/utils/result.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
@ -102,5 +103,29 @@ void main() {
// Booking should be deleted from repository
expect(bookingRepository.bookings, isEmpty);
});
testWidgets('fail to delete booking', (tester) async {
// Create a ViewModel with a repository that will fail to delete
viewModel = HomeViewModel(
bookingRepository: _BadFakeBookingRepository()..createBooking(kBooking),
userRepository: FakeUserRepository(),
);
await loadWidget(tester);
await tester.pumpAndSettle();
// Swipe on booking (created from kBooking)
await tester.drag(find.text('name1, Europe'), const Offset(-1000, 0));
await tester.pumpAndSettle();
// Existing booking should be there
expect(find.text('name1, Europe'), findsOneWidget);
});
});
}
class _BadFakeBookingRepository extends FakeBookingRepository {
@override
Future<Result<void>> delete(int id) async {
return Result.error(Exception('Failed to delete booking'));
}
}

Loading…
Cancel
Save