feat(app): add native Needs-you bell and sheet over the attention model
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'package:flutter/rendering.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';
|
||||
|
||||
/// Layout evidence for the hardest case: a narrow phone at a doubled text scale.
|
||||
void main() {
|
||||
for (final native in [false, true]) {
|
||||
final host = native ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('$host sheet 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);
|
||||
const longTitle =
|
||||
'Implementer-with-an-unshortened-stage-label that the operator sees';
|
||||
const longDetail =
|
||||
'Stage 3 stopped at the export archive step because the credential '
|
||||
'it needs is no longer configured on this server.';
|
||||
final entry = attentionFixture(
|
||||
id: 1,
|
||||
name: 'Release',
|
||||
title: longTitle,
|
||||
diagnostic: longDetail,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
attentionApp(
|
||||
NeedsYouPage(entries: [entry], cupertino: native),
|
||||
cupertino: native,
|
||||
dark: true,
|
||||
textScale: 2,
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(attentionBellKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
final label = find.text(longTitle);
|
||||
final description = find.text('Release · $longDetail');
|
||||
expect(label, findsOneWidget);
|
||||
expect(description, findsOneWidget);
|
||||
await tester.ensureVisible(label);
|
||||
final paragraph = tester.renderObject<RenderParagraph>(label);
|
||||
expect(paragraph.didExceedMaxLines, isFalse);
|
||||
final unscaled = TextPainter(
|
||||
text: paragraph.text,
|
||||
textDirection: paragraph.textDirection,
|
||||
textScaler: TextScaler.noScaling,
|
||||
)..layout();
|
||||
expect(
|
||||
unscaled.width,
|
||||
greaterThan(paragraph.size.width),
|
||||
reason: 'the long label wraps instead of shrinking to one line',
|
||||
);
|
||||
unscaled.dispose();
|
||||
|
||||
final sheet = tester.getRect(find.byKey(attentionSheetKey));
|
||||
expect(sheet.left, greaterThanOrEqualTo(0));
|
||||
expect(sheet.right, lessThanOrEqualTo(320));
|
||||
expect(sheet.top, greaterThanOrEqualTo(0));
|
||||
expect(sheet.bottom, lessThanOrEqualTo(640));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
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 'needs_you_test_support.dart';
|
||||
|
||||
/// The open sheet is a view of the caller's list, not a copy of it: rows that
|
||||
/// arrive, disappear or change text must redraw, while Clear all stays limited
|
||||
/// to the snapshot the route opened with.
|
||||
void main() {
|
||||
for (final native in [false, true]) {
|
||||
final host = native ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets(
|
||||
'$host same-identity content change reaches the open and reopened sheet',
|
||||
(tester) async {
|
||||
final before = attentionFixture(id: 1, title: 'Old title');
|
||||
final changed = attentionFixture(
|
||||
id: 1,
|
||||
title: 'New title',
|
||||
diagnostic: 'Stage 3 failed',
|
||||
);
|
||||
final reopened = attentionFixture(id: 1, title: 'Newest title');
|
||||
expect(changed.key, before.key);
|
||||
final source = ValueNotifier<List<AttentionEntry>>([before]);
|
||||
addTearDown(source.dispose);
|
||||
await tester.pumpWidget(
|
||||
attentionApp(
|
||||
AttentionHarness(
|
||||
source: source,
|
||||
opened: <AttentionEntry>[],
|
||||
dismissed: <AttentionEntry>[],
|
||||
cleared: <List<AttentionEntry>>[],
|
||||
cupertino: native,
|
||||
),
|
||||
cupertino: native,
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(attentionBellKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Old title'), findsOneWidget);
|
||||
|
||||
// Same run and kind, new title and diagnostic: the open sheet must
|
||||
// redraw from the caller's list, as the browser does.
|
||||
source.value = [changed];
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('New title'), findsOneWidget);
|
||||
expect(find.text('Old title'), findsNothing);
|
||||
expect(find.text('Release · Stage 3 failed'), findsOneWidget);
|
||||
expect(
|
||||
attentionDismissName(tester, changed),
|
||||
'Dismiss New title',
|
||||
reason: 'the row action is named from the row it now shows',
|
||||
);
|
||||
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(attentionSheetKey), findsNothing);
|
||||
|
||||
// A closed sheet must not keep the list it was last opened with either.
|
||||
source.value = [reopened];
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(attentionBellKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Newest title'), findsOneWidget);
|
||||
expect(find.text('New title'), findsNothing);
|
||||
expect(attentionDismissName(tester, reopened), 'Dismiss Newest title');
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'$host Clear all uses the open snapshot and leaves later arrivals',
|
||||
(tester) async {
|
||||
final a = attentionFixture(id: 1, title: 'Ship the release');
|
||||
final b = attentionFixture(id: 2, title: 'Arrived while open');
|
||||
final source = ValueNotifier<List<AttentionEntry>>([a]);
|
||||
addTearDown(source.dispose);
|
||||
final cleared = <List<AttentionEntry>>[];
|
||||
await tester.pumpWidget(
|
||||
attentionApp(
|
||||
AttentionHarness(
|
||||
source: source,
|
||||
opened: <AttentionEntry>[],
|
||||
dismissed: <AttentionEntry>[],
|
||||
cleared: cleared,
|
||||
cupertino: native,
|
||||
),
|
||||
cupertino: native,
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(attentionBellKey));
|
||||
await tester.pumpAndSettle();
|
||||
source.value = [a, b];
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.byKey(attentionRowKey(b.key)),
|
||||
findsOneWidget,
|
||||
reason: 'the open sheet shows the live list, as the browser does',
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(attentionClearAllKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(cleared, hasLength(1));
|
||||
expect(cleared.single.map((entry) => entry.key), [a.key]);
|
||||
expect(source.value.map((entry) => entry.key), [b.key]);
|
||||
// Clearing keeps the sheet open; only the snapshot it opened with is gone.
|
||||
expect(find.byKey(attentionSheetKey), findsOneWidget);
|
||||
expect(find.byKey(attentionRowKey(b.key)), findsOneWidget);
|
||||
expect(find.byKey(attentionRowKey(a.key)), findsNothing);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
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 '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);
|
||||
|
||||
// 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<List<AttentionEntry>>([a, b]);
|
||||
addTearDown(source.dispose);
|
||||
final opened = <AttentionEntry>[];
|
||||
final dismissed = <AttentionEntry>[];
|
||||
await tester.pumpWidget(
|
||||
attentionApp(
|
||||
AttentionHarness(
|
||||
source: source,
|
||||
opened: opened,
|
||||
dismissed: dismissed,
|
||||
cleared: <List<AttentionEntry>>[],
|
||||
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<List<AttentionEntry>>([failed, decision]);
|
||||
addTearDown(source.dispose);
|
||||
final opened = <AttentionEntry>[];
|
||||
final dismissed = <AttentionEntry>[];
|
||||
await tester.pumpWidget(
|
||||
attentionApp(
|
||||
AttentionHarness(
|
||||
source: source,
|
||||
opened: opened,
|
||||
dismissed: dismissed,
|
||||
cleared: <List<AttentionEntry>>[],
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import 'package:flutter/cupertino.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';
|
||||
|
||||
/// One qualifying run summary, built through the real pure model so the tests
|
||||
/// exercise the same label/detail/identity wording the app renders.
|
||||
AttentionEntry attentionFixture({
|
||||
int id = 1,
|
||||
String name = 'Release',
|
||||
String? title,
|
||||
String status = 'failed',
|
||||
String diagnostic = '',
|
||||
String createdAt = '2026-10-21T09:00:00Z',
|
||||
String finishedAt = '2026-10-21T09:10:00Z',
|
||||
}) {
|
||||
return attentionEntryFor({
|
||||
'id': id,
|
||||
'name': name,
|
||||
'title': title,
|
||||
'status': status,
|
||||
'diagnostic': diagnostic,
|
||||
'created_at': createdAt,
|
||||
'finished_at': finishedAt,
|
||||
})!;
|
||||
}
|
||||
|
||||
Widget attentionApp(
|
||||
Widget home, {
|
||||
bool cupertino = false,
|
||||
bool dark = false,
|
||||
double textScale = 1,
|
||||
}) {
|
||||
Widget scaled(BuildContext context, Widget? app) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: app!,
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(
|
||||
theme: CupertinoThemeData(
|
||||
brightness: dark ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
builder: scaled,
|
||||
home: home,
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
platform: TargetPlatform.android,
|
||||
brightness: dark ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
builder: scaled,
|
||||
home: home,
|
||||
);
|
||||
}
|
||||
|
||||
/// A normal page whose whole body is the reusable bell.
|
||||
class NeedsYouPage extends StatelessWidget {
|
||||
const NeedsYouPage({
|
||||
super.key,
|
||||
required this.entries,
|
||||
this.cupertino = false,
|
||||
this.onOpen,
|
||||
this.onDismiss,
|
||||
this.onClearAll,
|
||||
});
|
||||
|
||||
final List<AttentionEntry> entries;
|
||||
final bool cupertino;
|
||||
final ValueChanged<AttentionEntry>? onOpen;
|
||||
final ValueChanged<AttentionEntry>? onDismiss;
|
||||
final ValueChanged<List<AttentionEntry>>? onClearAll;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bell = NeedsYouBell(
|
||||
entries: entries,
|
||||
cupertino: cupertino,
|
||||
onOpen: onOpen ?? (_) {},
|
||||
onDismiss: onDismiss ?? (_) {},
|
||||
onClearAll: onClearAll ?? (_) {},
|
||||
);
|
||||
final body = Center(child: bell);
|
||||
return cupertino
|
||||
? CupertinoPageScaffold(child: SafeArea(child: body))
|
||||
: Scaffold(body: SafeArea(child: body));
|
||||
}
|
||||
}
|
||||
|
||||
/// A page that behaves like the real integration: [source] is the live list,
|
||||
/// dismissing removes that one identity at once, and Clear all removes exactly
|
||||
/// the snapshot the sheet reports. Callbacks are recorded for the assertions.
|
||||
class AttentionHarness extends StatelessWidget {
|
||||
const AttentionHarness({
|
||||
super.key,
|
||||
required this.source,
|
||||
required this.opened,
|
||||
required this.dismissed,
|
||||
required this.cleared,
|
||||
this.cupertino = false,
|
||||
});
|
||||
|
||||
final ValueNotifier<List<AttentionEntry>> source;
|
||||
final List<AttentionEntry> opened;
|
||||
final List<AttentionEntry> dismissed;
|
||||
final List<List<AttentionEntry>> cleared;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ValueListenableBuilder<List<AttentionEntry>>(
|
||||
valueListenable: source,
|
||||
builder: (context, entries, _) => NeedsYouPage(
|
||||
entries: entries,
|
||||
cupertino: cupertino,
|
||||
onOpen: opened.add,
|
||||
onDismiss: (entry) {
|
||||
dismissed.add(entry);
|
||||
source.value = [
|
||||
for (final item in source.value)
|
||||
if (item.key != entry.key) item,
|
||||
];
|
||||
},
|
||||
onClearAll: (snapshot) {
|
||||
cleared.add(snapshot);
|
||||
final keys = snapshot.map((entry) => entry.key).toSet();
|
||||
source.value = [
|
||||
for (final item in source.value)
|
||||
if (!keys.contains(item.key)) item,
|
||||
];
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// True when the bell action currently holds keyboard focus.
|
||||
bool bellHasFocus(WidgetTester tester) {
|
||||
final widget = tester.widget(find.byKey(attentionBellKey));
|
||||
final node = switch (widget) {
|
||||
IconButton() => widget.focusNode,
|
||||
CupertinoButton() => widget.focusNode,
|
||||
_ => null,
|
||||
};
|
||||
return node?.hasPrimaryFocus ?? false;
|
||||
}
|
||||
|
||||
/// The accessible name of one row's Dismiss action, whichever host drew it.
|
||||
///
|
||||
/// Material exposes it as the button tooltip, Cupertino as the xmark icon's
|
||||
/// semantic label; both must name the row they remove.
|
||||
String attentionDismissName(WidgetTester tester, AttentionEntry entry) {
|
||||
final key = attentionDismissKey(entry.key);
|
||||
final xmark = find.descendant(
|
||||
of: find.byKey(key),
|
||||
matching: find.byIcon(CupertinoIcons.xmark),
|
||||
);
|
||||
if (xmark.evaluate().isNotEmpty) {
|
||||
return tester.widget<Icon>(xmark).semanticLabel ?? '';
|
||||
}
|
||||
return tester.widget<IconButton>(find.byKey(key)).tooltip ?? '';
|
||||
}
|
||||
Reference in New Issue
Block a user