98 lines
3.3 KiB
Dart
98 lines
3.3 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/attention/notify/notification_controller.dart';
|
|
import 'package:pipelines_app/features/attention/notify/notification_models.dart';
|
|
import 'package:pipelines_app/features/attention/notify/notification_store.dart';
|
|
import 'package:pipelines_app/features/attention/ui/needs_you_runs_heading.dart';
|
|
import 'package:pipelines_app/features/settings/settings_notifications_section.dart';
|
|
|
|
import 'notification_test_support.dart';
|
|
|
|
/// The manager-owned wiring: the bell surface publishes live transitions and
|
|
/// Settings renders the same controller's permission.
|
|
void main() {
|
|
testWidgets('a seed never notifies and one live transition notifies once', (
|
|
tester,
|
|
) async {
|
|
final bridge = FakeNotificationBridge(permission: 'granted');
|
|
final notify = NotificationController(
|
|
store: MemoryNotificationStore(),
|
|
bridge: bridge,
|
|
);
|
|
final frames = StreamController<JsonMap>.broadcast();
|
|
addTearDown(frames.close);
|
|
addTearDown(notify.dispose);
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: NeedsYouRunsHeading(
|
|
rows: <JsonMap>[runSummary(1, 'failed'), runSummary(2, 'running')],
|
|
frames: frames.stream,
|
|
onOpen: (_) {},
|
|
now: () => attentionNow,
|
|
notifications: notify,
|
|
cupertino: false,
|
|
),
|
|
),
|
|
);
|
|
// Let the persisted ledger read and the seed publish settle. A plain
|
|
// `Future.delayed` would deadlock inside the widget test's fake clock.
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 20));
|
|
expect(bridge.shown, isEmpty, reason: 'the initial list is a seed');
|
|
expect(notify.permission.name, 'granted');
|
|
|
|
frames.add(runFrame(2, 'failed'));
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 20));
|
|
expect(bridge.shown, hasLength(1));
|
|
expect(bridge.shown.single.runId, 2);
|
|
|
|
// The same transition instance again (a reconnect reseed of that frame)
|
|
// must not announce twice.
|
|
frames.add(runFrame(2, 'failed'));
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 20));
|
|
expect(bridge.shown, hasLength(1));
|
|
});
|
|
|
|
testWidgets('Settings renders the platform permission from the controller', (
|
|
tester,
|
|
) async {
|
|
final notify = NotificationController(
|
|
store: MemoryNotificationStore(),
|
|
bridge: FakeNotificationBridge(permission: 'granted'),
|
|
);
|
|
addTearDown(notify.dispose);
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: SettingsNotificationsSection(controller: notify),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
expect(find.text(notificationRationale), findsOneWidget);
|
|
|
|
// A denied platform answer shows its own words and no Enable action.
|
|
final denied = NotificationController(
|
|
store: MemoryNotificationStore(),
|
|
bridge: FakeNotificationBridge(permission: 'denied'),
|
|
);
|
|
addTearDown(denied.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: SettingsNotificationsSection(controller: denied),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
expect(find.text(notificationRationale), findsOneWidget);
|
|
});
|
|
}
|