import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/attention/notify/notification_models.dart'; import 'package:pipelines_app/features/attention/ui/notification_permission_tile.dart'; import 'needs_you_test_support.dart'; /// The tile inside a normal page, so both native hosts can draw it. The page /// scrolls like the Settings list does, so the tile is never given a fixed /// height to overflow. Widget _page({ required NotificationPermissionState state, bool cupertino = false, bool asked = false, VoidCallback? onRequest, }) => attentionApp( Scaffold( body: SingleChildScrollView( child: NotificationPermissionTile( state: state, asked: asked, onRequest: onRequest, ), ), ), cupertino: cupertino, ); void _noop() {} void main() { for (final native in [false, true]) { final host = native ? 'Cupertino' : 'Material'; testWidgets('$host shows a compact row for each state', (tester) async { final cases = { NotificationPermissionState.unsupported: notificationUnsupportedCopy, NotificationPermissionState.needsSecureContext: notificationInsecureCopy, NotificationPermissionState.granted: notificationGrantedCopy, NotificationPermissionState.denied: notificationDeniedCopy, NotificationPermissionState.notRequested: notificationDefaultCopy, }; for (final entry in cases.entries) { await tester.pumpWidget( _page(state: entry.key, cupertino: native, onRequest: _noop), ); final view = notificationPermissionView(entry.key); // The Settings section owns the heading; the tile is one short row. expect(find.text(notificationSectionTitle), findsNothing); expect(find.text(notificationRationale), findsNothing); expect(find.text(view.headline), findsOneWidget); expect(find.text(view.helper), findsOneWidget); // The full honest sentence is what assistive technology reads. expect(view.body, entry.value); expect(find.bySemanticsLabel(entry.value), findsOneWidget); expect( find.byKey(notificationEnableKey), entry.key == NotificationPermissionState.notRequested ? findsOneWidget : findsNothing, reason: '${entry.key}', ); } }); testWidgets('$host shows the asked wording without an action', ( tester, ) async { await tester.pumpWidget( _page( state: NotificationPermissionState.notRequested, asked: true, cupertino: native, ), ); expect(find.text('Alerts are still off'), findsOneWidget); expect(find.bySemanticsLabel(notificationDefaultAskedCopy), findsOne); expect(find.bySemanticsLabel(notificationDefaultCopy), findsNothing); }); testWidgets('$host Enable runs the explicit request', (tester) async { var requested = 0; await tester.pumpWidget( _page( state: NotificationPermissionState.notRequested, cupertino: native, onRequest: () => requested++, ), ); await tester.tap(find.byKey(notificationEnableKey)); await tester.pump(); expect(requested, 1); }); testWidgets('$host tile wraps at 320 logical px and 2x in dark', ( tester, ) async { tester.view.devicePixelRatio = 2; tester.view.physicalSize = const Size(640, 1280); addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); // The undecided state is the hardest: it carries the Enable action as well // as the longest copy, so the section title must still have room to read. await tester.pumpWidget( attentionApp( Scaffold( body: SingleChildScrollView( child: NotificationPermissionTile( state: NotificationPermissionState.notRequested, onRequest: _noop, ), ), ), cupertino: native, dark: true, textScale: 2, ), ); expect(tester.takeException(), isNull); final view = notificationPermissionView( NotificationPermissionState.notRequested, ); final helper = tester.renderObject( find.text(view.helper), ); expect( helper.size.width, greaterThan(100), reason: 'the action must not squeeze the row copy', ); final body = tester.renderObject( find.text(view.headline), ); expect(body.didExceedMaxLines, isFalse); expect(find.byKey(notificationEnableKey), findsOneWidget); final rect = tester.getRect(find.byKey(notificationStateKey)); expect(rect.left, greaterThanOrEqualTo(0)); expect(rect.right, lessThanOrEqualTo(320)); expect(tester.takeException(), isNull); }); } }