Files
pipelines/app/test/features/settings/settings_notification_settings_section_test.dart
T
alan fc7dbb0ac0 Remove ntfy: notifications go only through the app notification stream
Server: drop ntfy publishing (stage hooks, run outbox, chat attention, chat
tool notify, auto-switch and schedule notices), the chat push outbox (its
table is dropped at startup), ntfy status/endpoints and PIPELINES_NTFY_*.
The app_notifications stream, subscribe/clear and kinds are unchanged.
Notification settings keep run_finished/chat_needs_you/chat_reply_finished;
ntfy_enabled is accepted and ignored and its stored row is never read.

Stage type=ntfy is rejected: "ntfy stages were removed; notifications go to
the Pipelines apps — use the stage notify hook". The notify hook remains.

Installer: no ntfy build, accounts, config or supervisor child; manifest
gets top-level "mode" (legacy ntfy.mode still read). Reinstall retires an
old ntfy (safe PID-file stop, deletes binary, config, data dir, token, log,
with a note in logs/install.log); uninstall cleans leftovers.

App: ntfy settings section replaced by "Notification events"; texts updated.
Docs: docs/ntfy.md folded into docs/notifications.md; install, docker, cli,
author skill references updated; security review M1 marked resolved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 23:24:24 +00:00

204 lines
7.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/core/transport/connection_state.dart';
import 'package:pipelines_app/features/settings/settings_notification_settings_section.dart';
/// A scripted gateway: records every request and answers from [respond].
class _Gateway implements ApiGateway {
_Gateway(this.respond);
final FutureOr<JsonMap> Function(String type, JsonMap fields) respond;
final calls = <(String, JsonMap)>[];
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
calls.add((type, fields));
return respond(type, fields);
}
@override
Stream<JsonMap> get frames => const Stream.empty();
}
JsonMap _reply(bool run, bool needs, bool reply) => {
'type': 'notification_settings',
'notification_settings': {
'run_finished': run,
'chat_needs_you': needs,
'chat_reply_finished': reply,
},
};
Widget _host(ApiGateway gateway, {bool connected = true}) {
final body = SingleChildScrollView(
child: SettingsNotificationSettingsSection(
gateway: gateway,
connected: connected,
),
);
return MaterialApp(home: Scaffold(body: body));
}
Finder _tile(String key) => find.byKey(notificationSettingKey(key));
bool _checked(WidgetTester tester, String key) =>
tester.widget<CheckboxListTile>(_tile(key)).value!;
void main() {
testWidgets('shows the three shared switches with stored values', (
tester,
) async {
final gateway = _Gateway((_, _) => _reply(true, false, true));
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(gateway.calls.single.$1, 'notification_settings');
expect(find.text(notificationEventsTitle), findsOneWidget);
expect(find.text(notificationEventsSubtitle), findsOneWidget);
expect(find.text('Notify when any run ends'), findsOneWidget);
expect(
find.text('Otherwise only runs started with Notify me'),
findsOneWidget,
);
expect(find.text('Chat needs your answer or approval'), findsOneWidget);
expect(find.text('Chat reply finished'), findsOneWidget);
expect(find.byType(CheckboxListTile), findsNWidgets(3));
expect(_checked(tester, 'run_finished'), isTrue);
expect(_checked(tester, 'chat_needs_you'), isFalse);
expect(_checked(tester, 'chat_reply_finished'), isTrue);
});
testWidgets('shows the server default: only marked runs', (tester) async {
final gateway = _Gateway((_, _) => _reply(false, true, false));
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(_checked(tester, 'run_finished'), isFalse);
expect(_checked(tester, 'chat_needs_you'), isTrue);
expect(_checked(tester, 'chat_reply_finished'), isFalse);
});
for (final key in ['run_finished', 'chat_needs_you', 'chat_reply_finished']) {
testWidgets('toggling $key writes only that setting', (tester) async {
final gateway = _Gateway((type, fields) {
if (type == 'set_notification_settings') {
return _reply(true, true, true);
}
return _reply(false, false, false);
});
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
await tester.tap(_tile(key));
await tester.pumpAndSettle();
expect(gateway.calls, hasLength(2));
expect(gateway.calls.last.$1, 'set_notification_settings');
expect(gateway.calls.last.$2, {
'notification_settings': {key: true},
});
expect(_checked(tester, key), isTrue);
expect(find.byKey(notificationSettingsErrorKey), findsNothing);
});
}
testWidgets('a legacy ntfy_enabled key in the reply is ignored', (
tester,
) async {
JsonMap legacy() => {
'type': 'notification_settings',
'notification_settings': {
...(_reply(true, true, false)['notification_settings'] as Map),
'ntfy_enabled': true,
},
};
final gateway = _Gateway((_, _) => legacy());
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(find.byType(CheckboxListTile), findsNWidgets(3));
expect(_tile('ntfy_enabled'), findsNothing);
expect(find.textContaining('ntfy'), findsNothing);
expect(find.byKey(notificationSettingsErrorKey), findsNothing);
// A write after such a reply still sends only the toggled key.
await tester.tap(_tile('chat_reply_finished'));
await tester.pumpAndSettle();
expect(gateway.calls.last.$2, {
'notification_settings': {'chat_reply_finished': true},
});
expect(find.byType(CheckboxListTile), findsNWidgets(3));
});
testWidgets('failure reverts and shows the refusal', (tester) async {
final pending = Completer<JsonMap>();
final gateway = _Gateway((type, _) {
if (type == 'set_notification_settings') return pending.future;
return _reply(true, true, false);
});
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
await tester.tap(_tile('run_finished'));
await tester.pump();
// The change shows at once and the group is disabled while it saves.
expect(_checked(tester, 'run_finished'), isFalse);
await tester.tap(_tile('chat_needs_you'));
await tester.pump();
expect(gateway.calls, hasLength(2));
pending.completeError(const ProtocolError('settings are read-only'));
await tester.pumpAndSettle();
expect(_checked(tester, 'run_finished'), isTrue);
expect(_checked(tester, 'chat_needs_you'), isTrue);
expect(find.text('Could not save: settings are read-only'), findsOneWidget);
});
testWidgets('disabled while loading', (tester) async {
final pending = Completer<JsonMap>();
final gateway = _Gateway((_, _) => pending.future);
await tester.pumpWidget(_host(gateway));
await tester.pump();
expect(find.text('Loading…'), findsOneWidget);
await tester.tap(_tile('run_finished'));
await tester.pump();
expect(gateway.calls, hasLength(1));
expect(
tester.widget<CheckboxListTile>(_tile('run_finished')).onChanged,
isNull,
);
pending.complete(_reply(true, true, false));
await tester.pumpAndSettle();
expect(find.text('Loading…'), findsNothing);
});
testWidgets('offline: no request, the offline text, switches disabled', (
tester,
) async {
final gateway = _Gateway((_, _) => _reply(true, true, false));
await tester.pumpWidget(_host(gateway, connected: false));
await tester.pumpAndSettle();
expect(gateway.calls, isEmpty);
expect(find.text(notificationEventsOfflineText), findsOneWidget);
expect(
tester.widget<CheckboxListTile>(_tile('chat_needs_you')).onChanged,
isNull,
);
});
testWidgets('a load failure is shown with a retry', (tester) async {
var fail = true;
final gateway = _Gateway((_, _) {
if (fail) throw const ProtocolError('no store');
return _reply(false, true, false);
});
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(
find.text('Could not load notification settings: no store'),
findsOneWidget,
);
fail = false;
await tester.tap(find.text('Retry'));
await tester.pumpAndSettle();
expect(find.byKey(notificationSettingsErrorKey), findsNothing);
expect(_checked(tester, 'run_finished'), isFalse);
});
}