import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart'; import 'package:pipelines_app/features/settings/settings_chat_navigation_section.dart'; class _Store implements MobileChatNavigationStore { String? saved; bool success = true; @override Future load() async => saved; @override Future save(String value) async { saved = value; return success; } } void main() { testWidgets('chooses, saves and restores the phone chat navigation', ( tester, ) async { final store = _Store(); final controller = MobileChatNavigationController(store: store); addTearDown(controller.dispose); await tester.pumpWidget( MaterialApp( home: Scaffold( body: SingleChildScrollView( child: SettingsChatNavigationSection(controller: controller), ), ), ), ); expect(find.text(SettingsChatNavigationSection.title), findsOneWidget); expect(controller.value, MobileChatNavigation.quickSwitch); expect( find.text(MobileChatNavigation.quickSwitch.description), findsOneWidget, ); await tester.tap( find.byKey(const ValueKey('settings-chat-navigation-chatStack')), ); await tester.pumpAndSettle(); expect(controller.value, MobileChatNavigation.chatStack); expect(store.saved, 'chatStack'); expect( find.text(MobileChatNavigation.chatStack.description), findsOneWidget, ); // A new controller (the next launch) restores the saved choice. final next = MobileChatNavigationController(store: store); addTearDown(next.dispose); await next.restore(); expect(next.value, MobileChatNavigation.chatStack); store.success = false; await tester.tap( find.byKey(const ValueKey('settings-chat-navigation-quickSwitch')), ); await tester.pumpAndSettle(); expect(find.text('Could not save; applies until reload.'), findsOneWidget); }); }