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/onboarding_store.dart'; import 'package:tane/services/sharing_switch.dart'; import 'package:tane/ui/sharing_invite_sheet.dart'; import '../support/test_support.dart'; void main() { Widget host(OnboardingStore store, SharingSwitch sharing) => TranslationProvider( child: MaterialApp( localizationsDelegates: GlobalMaterialLocalizations.delegates, home: Builder( builder: (context) => Center( child: ElevatedButton( onPressed: () => showSharingInvite( context, onboarding: store, sharing: sharing, ), child: const Text('tap a locked entry'), ), ), ), ), ); testWidgets('the invite says what lights up and that it needs a connection', (tester) async { LocaleSettings.setLocaleSync(AppLocale.en); await tester.pumpWidget( TranslationProvider( child: const MaterialApp( localizationsDelegates: GlobalMaterialLocalizations.delegates, home: Scaffold(body: SharingInviteSheet()), ), ), ); await tester.pump(); expect(find.text('This wakes up when you start sharing'), findsOneWidget); expect(find.text('Write to whoever has seeds near you'), findsOneWidget); expect(find.text('Keep the offers you like'), findsOneWidget); expect(find.text('Your circle of people you trust'), findsOneWidget); // The honest part: it is not free of consequences. expect(find.textContaining('go online'), findsOneWidget); }); testWidgets('"Not now" leaves the app exactly as offline as it was', (tester) async { LocaleSettings.setLocaleSync(AppLocale.en); final store = OnboardingStore(InMemorySecretStore()); final sharing = newTestSharingSwitch(enabled: false); await tester.pumpWidget(host(store, sharing)); await tester.tap(find.text('tap a locked entry')); await tester.pumpAndSettle(); await tester.tap(find.byKey(const Key('sharingInvite.notNow'))); await tester.pumpAndSettle(); expect(sharing.on.value, isFalse); expect(await store.marketRulesAccepted(), isFalse); }); testWidgets('accepting the invite goes through the community rules once', (tester) async { LocaleSettings.setLocaleSync(AppLocale.en); final store = OnboardingStore(InMemorySecretStore()); final sharing = newTestSharingSwitch(enabled: false); await tester.pumpWidget(host(store, sharing)); await tester.tap(find.text('tap a locked entry')); await tester.pumpAndSettle(); await tester.tap(find.byKey(const Key('sharingInvite.start'))); await tester.pumpAndSettle(); // Same single consent surface the market uses — not a second one. expect(find.text('Before you join the market'), findsOneWidget); expect(sharing.on.value, isFalse, reason: 'not online until they agree'); await tester.tap(find.text('I agree')); await tester.pumpAndSettle(); expect(sharing.on.value, isTrue); expect(await store.marketRulesAccepted(), isTrue); }); }