import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/attention/domain/attention_models.dart'; import 'package:pipelines_app/features/attention/ui/needs_you_keys.dart'; import 'package:pipelines_app/ui/status/run_status_icon.dart'; import 'needs_you_test_support.dart'; void main() { for (final native in [false, true]) { final host = native ? 'Cupertino' : 'Material'; testWidgets('$host sheet names every row and every dismiss action', ( tester, ) async { final a = attentionFixture(id: 1, title: 'Ship the release'); final b = attentionFixture( id: 2, name: 'Nightly audit', status: 'waiting', ); await tester.pumpWidget( attentionApp( NeedsYouPage(entries: [a, b], cupertino: native), cupertino: native, ), ); await tester.tap(find.byKey(attentionBellKey)); await tester.pumpAndSettle(); expect(find.byKey(attentionSheetKey), findsOneWidget); expect(find.text('Needs you'), findsOneWidget); expect(find.byKey(attentionRowKey(a.key)), findsOneWidget); expect(find.byKey(attentionRowKey(b.key)), findsOneWidget); expect(find.text('Ship the release'), findsOneWidget); expect(find.text('Release · Run failed'), findsOneWidget); expect(find.text('Nightly audit'), findsOneWidget); expect( find.text('Nightly audit · Waiting for your decision'), findsOneWidget, ); expect(find.byKey(attentionClearAllKey), findsOneWidget); // Each row leads with the shared run status glyph, as the web's rows. expect( tester .widgetList(find.byType(RunStatusIcon)) .map((icon) => icon.state), unorderedEquals(['failed', 'waiting']), ); // The browser names each destructive control after the row it removes. expect(attentionDismissName(tester, a), 'Dismiss Ship the release'); expect(attentionDismissName(tester, b), 'Dismiss Nightly audit'); expect(find.text('Dismiss'), findsNothing); }); testWidgets('$host repeated labels add the run id to the dismiss name', ( tester, ) async { final first = attentionFixture(id: 11, title: 'Nightly audit'); final second = attentionFixture(id: 12, title: 'Nightly audit'); await tester.pumpWidget( attentionApp( NeedsYouPage(entries: [first, second], cupertino: native), cupertino: native, ), ); await tester.tap(find.byKey(attentionBellKey)); await tester.pumpAndSettle(); expect( attentionDismissName(tester, first), 'Dismiss Nightly audit (run 11)', ); expect( attentionDismissName(tester, second), 'Dismiss Nightly audit (run 12)', ); }); testWidgets('$host row Dismiss names its identity and stays open', ( tester, ) async { final a = attentionFixture(id: 1, title: 'Ship the release'); final b = attentionFixture(id: 2, title: 'Fix the export'); final source = ValueNotifier>([a, b]); addTearDown(source.dispose); final opened = []; final dismissed = []; await tester.pumpWidget( attentionApp( AttentionHarness( source: source, opened: opened, dismissed: dismissed, cleared: >[], cupertino: native, ), cupertino: native, ), ); await tester.tap(find.byKey(attentionBellKey)); await tester.pumpAndSettle(); await tester.tap(find.byKey(attentionDismissKey(b.key))); await tester.pumpAndSettle(); expect(dismissed.map((entry) => entry.key), [b.key]); expect(opened, isEmpty); // The browser keeps the sheet open and redraws it; the caller removed the // dismissed identity, so the remaining row is still there for a second one. expect(find.byKey(attentionSheetKey), findsOneWidget); expect(find.byKey(attentionRowKey(b.key)), findsNothing); expect(find.byKey(attentionRowKey(a.key)), findsOneWidget); }); testWidgets('$host row opens its run and only a Failed row is dismissed', ( tester, ) async { final failed = attentionFixture(id: 1, title: 'Ship the release'); final decision = attentionFixture( id: 2, title: 'Approve the release', status: 'waiting', ); final source = ValueNotifier>([failed, decision]); addTearDown(source.dispose); final opened = []; final dismissed = []; await tester.pumpWidget( attentionApp( AttentionHarness( source: source, opened: opened, dismissed: dismissed, cleared: >[], cupertino: native, ), cupertino: native, ), ); await tester.tap(find.byKey(attentionBellKey)); await tester.pumpAndSettle(); await tester.tap(find.byKey(attentionRowKey(failed.key))); await tester.pumpAndSettle(); expect(opened.map((entry) => entry.key), [failed.key]); expect( dismissed.map((entry) => entry.key), [failed.key], reason: 'opening a failed run is the operator dealing with it', ); expect(find.byKey(attentionSheetKey), findsNothing); await tester.tap(find.byKey(attentionBellKey)); await tester.pumpAndSettle(); await tester.tap(find.byKey(attentionRowKey(decision.key))); await tester.pumpAndSettle(); expect(opened.map((entry) => entry.key), [failed.key, decision.key]); expect( dismissed.map((entry) => entry.key), [failed.key], reason: 'a decision stays until the operator answers it', ); expect(find.byKey(attentionSheetKey), findsNothing); }); } }