968e3e908a
Keep the reviewed attention surfaces on their Material implementations while preserving public cupertino parameters for remaining callers. Remove the unreachable Cupertino sheet and narrow tests to the Material path.
153 lines
5.1 KiB
Dart
153 lines
5.1 KiB
Dart
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 it is drawn the way Settings draws 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 asked = false,
|
|
VoidCallback? onRequest,
|
|
}) => attentionApp(
|
|
Scaffold(
|
|
body: SingleChildScrollView(
|
|
child: NotificationPermissionTile(
|
|
state: state,
|
|
asked: asked,
|
|
onRequest: onRequest,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
void _noop() {}
|
|
|
|
void main() {
|
|
testWidgets('Material shows a compact row for each state', (tester) async {
|
|
final cases = <NotificationPermissionState, String>{
|
|
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, 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('Material shows the asked wording without an action', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
_page(state: NotificationPermissionState.notRequested, asked: true),
|
|
);
|
|
expect(find.text('Alerts are still off'), findsOneWidget);
|
|
expect(find.bySemanticsLabel(notificationDefaultAskedCopy), findsOne);
|
|
expect(find.bySemanticsLabel(notificationDefaultCopy), findsNothing);
|
|
});
|
|
|
|
testWidgets('Material Enable runs the explicit request', (tester) async {
|
|
var requested = 0;
|
|
await tester.pumpWidget(
|
|
_page(
|
|
state: NotificationPermissionState.notRequested,
|
|
onRequest: () => requested++,
|
|
),
|
|
);
|
|
await tester.tap(find.byKey(notificationEnableKey));
|
|
await tester.pump();
|
|
expect(requested, 1);
|
|
});
|
|
|
|
testWidgets('a stale cupertino flag still draws the Material row', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
attentionApp(
|
|
Scaffold(
|
|
body: SingleChildScrollView(
|
|
child: NotificationPermissionTile(
|
|
state: NotificationPermissionState.notRequested,
|
|
cupertino: true,
|
|
onRequest: _noop,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(
|
|
tester.widget(find.byKey(notificationEnableKey)),
|
|
isA<FilledButton>(),
|
|
);
|
|
expect(find.text(notificationEnableShortLabel), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('Material 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,
|
|
),
|
|
),
|
|
),
|
|
dark: true,
|
|
textScale: 2,
|
|
),
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
|
|
final view = notificationPermissionView(
|
|
NotificationPermissionState.notRequested,
|
|
);
|
|
final helper = tester.renderObject<RenderParagraph>(find.text(view.helper));
|
|
expect(
|
|
helper.size.width,
|
|
greaterThan(100),
|
|
reason: 'the action must not squeeze the row copy',
|
|
);
|
|
final body = tester.renderObject<RenderParagraph>(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);
|
|
});
|
|
}
|