197 lines
6.5 KiB
Dart
197 lines
6.5 KiB
Dart
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/runtime/attention_store.dart';
|
|
import 'package:pipelines_app/features/attention/ui/needs_you_keys.dart';
|
|
|
|
import 'attention_runs_test_support.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
late AttentionRunsGateway gateway;
|
|
|
|
setUp(() => gateway = AttentionRunsGateway());
|
|
tearDown(() => gateway.framesController.close());
|
|
|
|
for (final native in [false, true]) {
|
|
final host = native ? 'Cupertino' : 'Material';
|
|
|
|
testWidgets(
|
|
'$host Runs list bell opens the native sheet and dismisses one',
|
|
(tester) async {
|
|
final semantics = tester.ensureSemantics();
|
|
final store = MemoryAttentionStore();
|
|
await mountAttentionRuns(
|
|
tester,
|
|
gateway,
|
|
cupertino: native,
|
|
store: store,
|
|
runs: [
|
|
attentionRun(1, 'waiting', title: 'Approve the release'),
|
|
attentionRun(
|
|
2,
|
|
'failed',
|
|
title: 'Ship the release',
|
|
diagnostic: 'Stage 2',
|
|
),
|
|
attentionRun(3, 'waiting', title: 'Machine export')
|
|
..['export_pending_sequence'] = 2,
|
|
attentionRun(4, 'running', title: 'Still running'),
|
|
],
|
|
);
|
|
|
|
expect(
|
|
find.bySemanticsLabel('Notifications, 2 needing attention'),
|
|
findsOneWidget,
|
|
);
|
|
await openAttentionSheet(tester);
|
|
expect(find.byKey(attentionSheetKey), findsOneWidget);
|
|
expect(find.byKey(attentionRowKey('3:Decision')), findsNothing);
|
|
expect(find.byKey(attentionRowKey('4:Failed')), findsNothing);
|
|
expect(find.byKey(attentionRowKey('2:Failed')), findsOneWidget);
|
|
|
|
await tester.tap(find.byKey(attentionDismissKey('2:Failed')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(attentionSheetKey), findsOneWidget);
|
|
expect(find.byKey(attentionRowKey('2:Failed')), findsNothing);
|
|
expect(store.stored, encodeAttentionDismissals({'2:Failed'}));
|
|
|
|
// Closing and rebuilding from the same store keeps the dismissal.
|
|
await tester.binding.handlePopRoute();
|
|
await tester.pumpAndSettle();
|
|
await tester.pumpWidget(const SizedBox());
|
|
await mountAttentionRuns(
|
|
tester,
|
|
gateway,
|
|
cupertino: native,
|
|
store: store,
|
|
runs: [
|
|
attentionRun(1, 'waiting', title: 'Approve the release'),
|
|
attentionRun(
|
|
2,
|
|
'failed',
|
|
title: 'Ship the release',
|
|
diagnostic: 'Stage 2',
|
|
),
|
|
],
|
|
request: 1,
|
|
key: const ValueKey('rebuilt'),
|
|
);
|
|
expect(
|
|
find.bySemanticsLabel('Notifications, 1 needing attention'),
|
|
findsOneWidget,
|
|
);
|
|
semantics.dispose();
|
|
},
|
|
);
|
|
|
|
testWidgets('$host rows follow the browser open/dismiss rules', (
|
|
tester,
|
|
) async {
|
|
final store = MemoryAttentionStore();
|
|
await mountAttentionRuns(
|
|
tester,
|
|
gateway,
|
|
cupertino: native,
|
|
store: store,
|
|
runs: [
|
|
attentionRun(1, 'waiting', title: 'Approve the release'),
|
|
attentionRun(2, 'failed', title: 'Ship the release'),
|
|
],
|
|
);
|
|
|
|
await openAttentionSheet(tester);
|
|
await tester.tap(find.byKey(attentionRowKey('1:Decision')));
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 400));
|
|
expect(gateway.detailRequests[1], hasLength(1));
|
|
expect(
|
|
store.stored,
|
|
isNull,
|
|
reason: 'a Decision opens without dismissing',
|
|
);
|
|
gateway.replyDetail(1, {'id': 1, 'title': 'Approve the release'});
|
|
await tester.pump();
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tap(find.text(native ? 'Back' : 'Back to list'));
|
|
await tester.pump();
|
|
await openAttentionSheet(tester);
|
|
await tester.tap(find.byKey(attentionRowKey('2:Failed')));
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 400));
|
|
expect(gateway.detailRequests[2], hasLength(1));
|
|
expect(store.stored, encodeAttentionDismissals({'2:Failed'}));
|
|
gateway.replyDetail(2, {'id': 2, 'title': 'Ship the release'});
|
|
await tester.pump();
|
|
});
|
|
|
|
testWidgets('$host live frame and Clear-all snapshot reach the bell', (
|
|
tester,
|
|
) async {
|
|
final semantics = tester.ensureSemantics();
|
|
final store = MemoryAttentionStore();
|
|
await mountAttentionRuns(
|
|
tester,
|
|
gateway,
|
|
cupertino: native,
|
|
store: store,
|
|
runs: [attentionRun(1, 'failed', title: 'First failure')],
|
|
);
|
|
expect(
|
|
find.bySemanticsLabel('Notifications, 1 needing attention'),
|
|
findsOneWidget,
|
|
);
|
|
|
|
await openAttentionSheet(tester);
|
|
gateway.framesController.add({
|
|
'type': 'run_event',
|
|
'run_id': 9,
|
|
'pipeline_id': 4,
|
|
'name': 'nightly',
|
|
'title': 'Arrived while open',
|
|
'status': 'waiting',
|
|
'created_at': attentionTestNow
|
|
.subtract(const Duration(minutes: 5))
|
|
.toIso8601String(),
|
|
});
|
|
await tester.pump();
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(attentionRowKey('9:Decision')), findsOneWidget);
|
|
|
|
await tester.tap(find.byKey(attentionClearAllKey));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(attentionRowKey('1:Failed')), findsNothing);
|
|
expect(
|
|
find.byKey(attentionRowKey('9:Decision')),
|
|
findsOneWidget,
|
|
reason: 'Clear all acts on the snapshot it opened with',
|
|
);
|
|
expect(store.stored, encodeAttentionDismissals({'1:Failed'}));
|
|
semantics.dispose();
|
|
});
|
|
|
|
testWidgets('$host empty runs hide the badge but keep the bell', (
|
|
tester,
|
|
) async {
|
|
final semantics = tester.ensureSemantics();
|
|
await mountAttentionRuns(
|
|
tester,
|
|
gateway,
|
|
cupertino: native,
|
|
store: MemoryAttentionStore(),
|
|
runs: const [],
|
|
);
|
|
|
|
expect(find.byKey(attentionBellKey), findsOneWidget);
|
|
expect(find.byKey(attentionBadgeKey), findsNothing);
|
|
expect(find.bySemanticsLabel('Notifications'), findsOneWidget);
|
|
await openAttentionSheet(tester);
|
|
expect(find.text('Nothing needs you right now.'), findsOneWidget);
|
|
expect(find.byKey(attentionClearAllKey), findsNothing);
|
|
semantics.dispose();
|
|
});
|
|
}
|
|
}
|