import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/attention/ui/needs_you_keys.dart'; import 'needs_you_test_support.dart'; void main() { for (final native in [false, true]) { final host = native ? 'Cupertino' : 'Material'; testWidgets('$host bell is plain and announced when nothing needs you', ( tester, ) async { final semantics = tester.ensureSemantics(); await tester.pumpWidget( attentionApp(NeedsYouPage(entries: const [], cupertino: native)), ); expect(find.bySemanticsLabel('Notifications'), findsOneWidget); expect(find.byKey(attentionBadgeKey), findsNothing); expect(find.text('0'), findsNothing); semantics.dispose(); }); testWidgets('$host bell announces the count and shows one badge', ( tester, ) async { final semantics = tester.ensureSemantics(); final entries = [ attentionFixture(id: 1), attentionFixture(id: 2, status: 'waiting', title: 'Approve release'), attentionFixture(id: 3, diagnostic: 'Stage 2 failed'), ]; await tester.pumpWidget( attentionApp( NeedsYouPage(entries: entries, cupertino: native), cupertino: native, ), ); expect( find.bySemanticsLabel('Notifications, 3 needing attention'), findsOneWidget, ); expect(find.byKey(attentionBadgeKey), findsOneWidget); expect(find.text('3'), findsOneWidget); semantics.dispose(); }); testWidgets('$host bell opens the honest empty sheet and back closes it', ( tester, ) async { await tester.pumpWidget( attentionApp(NeedsYouPage(entries: const [], cupertino: native)), ); await tester.tap(find.byKey(attentionBellKey)); await tester.pumpAndSettle(); expect(find.byKey(attentionSheetKey), findsOneWidget); expect(find.text('Needs you'), findsOneWidget); expect(find.text('Nothing needs you right now.'), findsOneWidget); expect(find.byKey(attentionEmptyKey), findsOneWidget); expect(find.byKey(attentionClearAllKey), findsNothing); expect(find.text('Dismiss'), findsNothing); await tester.binding.handlePopRoute(); await tester.pumpAndSettle(); expect(find.byKey(attentionSheetKey), findsNothing); }); testWidgets('$host sheet is a named heading and Escape closes it', ( tester, ) async { final semantics = tester.ensureSemantics(); await tester.pumpWidget( attentionApp(NeedsYouPage(entries: const [], cupertino: native)), ); await tester.tap(find.byKey(attentionBellKey)); await tester.pumpAndSettle(); final title = tester.getSemantics(find.text('Needs you')); expect( title.getSemanticsData().flagsCollection.isHeader, isTrue, reason: 'the sheet title must reach assistive tech as a heading', ); await tester.sendKeyEvent(LogicalKeyboardKey.escape); await tester.pumpAndSettle(); expect(find.byKey(attentionSheetKey), findsNothing); semantics.dispose(); }); testWidgets('$host sheet closes on a barrier tap', (tester) async { await tester.pumpWidget( attentionApp(NeedsYouPage(entries: const [], cupertino: native)), ); await tester.tap(find.byKey(attentionBellKey)); await tester.pumpAndSettle(); expect(find.byKey(attentionSheetKey), findsOneWidget); // Above the sheet body: only the native modal barrier is there. await tester.tapAt(const Offset(20, 20)); await tester.pumpAndSettle(); expect(find.byKey(attentionSheetKey), findsNothing); }); testWidgets('$host closing the sheet returns focus to the bell', ( tester, ) async { await tester.pumpWidget( attentionApp(NeedsYouPage(entries: const [], cupertino: native)), ); await tester.tap(find.byKey(attentionBellKey)); await tester.pumpAndSettle(); await tester.binding.handlePopRoute(); await tester.pumpAndSettle(); expect(find.byKey(attentionSheetKey), findsNothing); expect(bellHasFocus(tester), isTrue); }); } }