94 lines
3.0 KiB
Dart
94 lines
3.0 KiB
Dart
import 'package:flutter/material.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_bell.dart';
|
|
import 'package:pipelines_app/features/attention/ui/needs_you_keys.dart';
|
|
|
|
import 'needs_you_test_support.dart';
|
|
|
|
/// The count badge paints outside the icon it decorates, so a bell placed flush
|
|
/// at the end of an app bar can have the badge sheared off by the viewport. The
|
|
/// integration puts the bell in `AppBar.actions`, which is where these tests put
|
|
/// it too, and measures the stadium the badge actually paints rather than just
|
|
/// finding its text.
|
|
void main() {
|
|
for (final narrow in [true, false]) {
|
|
final size = narrow ? const Size(320, 640) : const Size(390, 844);
|
|
final where = '${size.width.toInt()}x${size.height.toInt()}';
|
|
final entry = attentionFixture(
|
|
id: 8,
|
|
name: 'nightly-audit',
|
|
title: 'Nightly audit',
|
|
);
|
|
|
|
testWidgets('Material badge fits the viewport at $where and 2x', (
|
|
tester,
|
|
) async {
|
|
tester.view.devicePixelRatio = 2;
|
|
tester.view.physicalSize = size * 2;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
|
|
await tester.pumpWidget(
|
|
attentionApp(_BellInAppBar(entries: [entry]), dark: true, textScale: 2),
|
|
);
|
|
|
|
final badge = _paintedBadge(tester);
|
|
final icon = tester.getRect(find.byIcon(Icons.notifications_outlined));
|
|
expect(
|
|
badge.right,
|
|
greaterThan(icon.right),
|
|
reason:
|
|
'the measured box is the badge label, which paints past the icon',
|
|
);
|
|
expect(
|
|
badge.right,
|
|
lessThanOrEqualTo(size.width - 8),
|
|
reason:
|
|
'the count badge needs a visible margin at the trailing edge; '
|
|
'the action must reserve the badge overhang',
|
|
);
|
|
expect(badge.left, greaterThanOrEqualTo(0));
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|
|
}
|
|
|
|
/// The global rectangle of the stadium [Badge] paints for its label.
|
|
///
|
|
/// `Badge` lays the label out outside its own box, so `getRect` on the badge
|
|
/// key would only return the icon-sized box. The decorated stadium is the
|
|
/// painted label itself, positioned by the badge's render object.
|
|
Rect _paintedBadge(WidgetTester tester) {
|
|
final stadium = find.descendant(
|
|
of: find.byKey(attentionBadgeKey),
|
|
matching: find.byType(DecoratedBox),
|
|
);
|
|
expect(stadium, findsOneWidget);
|
|
return tester.getRect(stadium);
|
|
}
|
|
|
|
class _BellInAppBar extends StatelessWidget {
|
|
const _BellInAppBar({required this.entries});
|
|
|
|
final List<AttentionEntry> entries;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Runs'),
|
|
actions: [
|
|
NeedsYouBell(
|
|
entries: entries,
|
|
onOpen: (_) {},
|
|
onDismiss: (_) {},
|
|
onClearAll: (_) {},
|
|
),
|
|
],
|
|
),
|
|
body: const SizedBox.shrink(),
|
|
);
|
|
}
|
|
}
|