feat(market): save others' offers as favorites (Wallapop-style)
Adds a Favorites feature: a heart on the offer detail saves another person's listing to an encrypted, per-identity SavedOffersStore (keystore JSON snapshot, no plaintext at rest). A new /favorites screen (wired from the drawer) lists saved offers offline-first and, when a relay is reachable, flags ones that are gone as "no longer available". i18n en/es/pt/ast; store + screen + detail-heart tests.
This commit is contained in:
parent
f6967e8cbb
commit
d6225eed38
19 changed files with 806 additions and 3 deletions
77
apps/app_seeds/test/ui/favorites_screen_test.dart
Normal file
77
apps/app_seeds/test/ui/favorites_screen_test.dart
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
import 'package:commons_core/commons_core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/i18n/strings.g.dart';
|
||||
import 'package:tane/services/saved_offers_store.dart';
|
||||
import 'package:tane/ui/favorites_screen.dart';
|
||||
|
||||
import '../support/test_support.dart';
|
||||
|
||||
Widget _wrap(Widget child) {
|
||||
LocaleSettings.setLocaleSync(AppLocale.en);
|
||||
return TranslationProvider(
|
||||
child: MaterialApp(
|
||||
locale: AppLocale.en.flutterLocale,
|
||||
supportedLocales: AppLocaleUtils.supportedLocales,
|
||||
localizationsDelegates: const [
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
home: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Offer _offer(String id) => Offer(
|
||||
id: id,
|
||||
authorPubkeyHex: 'ab',
|
||||
summary: 'Tomate $id',
|
||||
type: OfferType.gift,
|
||||
approxGeohash: 'u09',
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets('shows the empty state when nothing is saved', (tester) async {
|
||||
final store = SavedOffersStore(InMemorySecretStore());
|
||||
// No connection → no relay check, just the local snapshots.
|
||||
await tester.pumpWidget(_wrap(FavoritesScreen(savedOffers: store)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.text('No favorites yet. Save offers you like from the market.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('lists saved offers newest-first', (tester) async {
|
||||
final store = SavedOffersStore(InMemorySecretStore());
|
||||
await store.save(_offer('old'), savedAt: 100);
|
||||
await store.save(_offer('new'), savedAt: 200);
|
||||
|
||||
await tester.pumpWidget(_wrap(FavoritesScreen(savedOffers: store)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Tomate new'), findsOneWidget);
|
||||
expect(find.text('Tomate old'), findsOneWidget);
|
||||
final newY = tester.getTopLeft(find.text('Tomate new')).dy;
|
||||
final oldY = tester.getTopLeft(find.text('Tomate old')).dy;
|
||||
expect(newY, lessThan(oldY)); // newest on top
|
||||
});
|
||||
|
||||
testWidgets('the heart removes a favorite', (tester) async {
|
||||
final store = SavedOffersStore(InMemorySecretStore());
|
||||
await store.save(_offer('1'), savedAt: 100);
|
||||
|
||||
await tester.pumpWidget(_wrap(FavoritesScreen(savedOffers: store)));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Tomate 1'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('favorites.remove.ab.1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Tomate 1'), findsNothing);
|
||||
expect(await store.isSaved('ab:1'), isFalse);
|
||||
});
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/i18n/strings.g.dart';
|
||||
import 'package:tane/services/saved_offers_store.dart';
|
||||
import 'package:tane/services/social_connection.dart';
|
||||
import 'package:tane/services/social_service.dart';
|
||||
import 'package:tane/services/social_settings.dart';
|
||||
|
|
@ -103,4 +104,50 @@ void main() {
|
|||
|
||||
expect(find.byType(OfferHeroImage), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the heart saves and unsaves a stranger\'s offer',
|
||||
(tester) async {
|
||||
final social = await SocialService.fromRootSeedHex('00' * 32);
|
||||
final settings = SocialSettings(InMemorySecretStore());
|
||||
await settings.setRelayUrls(const []);
|
||||
final connection = SocialConnection(social: social, settings: settings);
|
||||
final saved = SavedOffersStore(InMemorySecretStore());
|
||||
|
||||
await tester.pumpWidget(_wrap(MarketOfferDetailScreen(
|
||||
offer: _offer(),
|
||||
connection: connection,
|
||||
savedOffers: saved,
|
||||
)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final heart = find.byKey(const Key('offerDetail.save'));
|
||||
expect(heart, findsOneWidget);
|
||||
expect(await saved.isSaved('${'ab' * 32}:lot-1'), isFalse);
|
||||
|
||||
await tester.tap(heart);
|
||||
await tester.pumpAndSettle();
|
||||
expect(await saved.isSaved('${'ab' * 32}:lot-1'), isTrue);
|
||||
|
||||
await tester.tap(heart);
|
||||
await tester.pumpAndSettle();
|
||||
expect(await saved.isSaved('${'ab' * 32}:lot-1'), isFalse);
|
||||
});
|
||||
|
||||
testWidgets('no heart on my own listing', (tester) async {
|
||||
final social = await SocialService.fromRootSeedHex('00' * 32);
|
||||
final settings = SocialSettings(InMemorySecretStore());
|
||||
await settings.setRelayUrls(const []);
|
||||
final connection = SocialConnection(social: social, settings: settings);
|
||||
final saved = SavedOffersStore(InMemorySecretStore());
|
||||
|
||||
await tester.pumpWidget(_wrap(MarketOfferDetailScreen(
|
||||
offer: _offer(),
|
||||
connection: connection,
|
||||
mine: true,
|
||||
savedOffers: saved,
|
||||
)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('offerDetail.save')), findsNothing);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue