Merge main: ntfy removed, first-run messages kept

Resolved docs/install.md, internal/cli/app.go, internal/statusview and
scripts/setup-native.py: no ntfy anywhere (connection, status, installer
constants, troubleshooting ports), keeping the first-run next steps, the
unreachable-server and tool/Docker install hints. README drops the C
compiler (ntfy was its only user). The installer summary's password
wording is now per run (a reinstall in the same process no longer says
"you just chose"), and its test checks the URLs then the next steps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 23:54:57 +00:00
337 changed files with 14221 additions and 5709 deletions
@@ -0,0 +1,287 @@
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/servers/server_scope.dart';
import 'package:pipelines_app/features/chat/chat_runtime.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
import 'package:pipelines_app/features/chat/windows/chat_windows.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/shell/windows/window_host.dart';
import 'package:pipelines_app/shell/windows/window_kind.dart';
import 'package:pipelines_app/shell/windows/window_manager.dart';
import 'package:pipelines_app/shell/windows/window_store.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'conversation/chat_thread_fixtures.dart';
/// A chat server with an open-chat set whose entries may float.
class _Server extends FakeChatGateway {
_Server(this.open, this.floating);
List<String> open;
Set<String> floating;
int revision = 1;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final id in ['a', 'b', 'c'])
{'id': id, 'title': 'Chat $id', 'directory': '/home/$id'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
if (type == 'chat_open_workspace') {
final request = fields['chat_open_workspace_request'] as Map?;
var rejected = false;
if (request != null && request['seed'] != true) {
if (request['base_revision'] != revision) {
rejected = true;
} else {
final entries = (request['entries'] as List).cast<Map>();
open = [for (final e in entries) '${e['session_id']}'];
floating = {
for (final e in entries)
if (e['floating'] == true) '${e['session_id']}',
};
revision++;
}
}
return Future.value({
'type': 'chat_open_workspace',
'chat_open_workspace': _body(rejected),
});
}
return super.call(type, fields);
}
JsonMap _body([bool rejected = false]) => {
'revision': revision,
'entries': [
for (final id in open)
{'session_id': id, if (floating.contains(id)) 'floating': true},
],
if (rejected) 'rejected': true,
};
void change(List<String> ids, Set<String> floats) {
open = ids;
floating = floats;
revision++;
emitRaw({
'type': 'chat_open_workspace_changed',
'chat_open_workspace': _body(),
});
}
}
class _Store implements WindowStore {
String? value;
@override
Future<String?> read() async => value;
@override
Future<bool> write(String record) async {
value = record;
return true;
}
}
const _wide = Size(1800, 1000);
const _phone = Size(390, 844);
class _App {
late final _Server server;
late final ChatRuntime runtime;
late final WindowManager manager;
late final ChatWindows windows;
Future<void> start(WidgetTester tester, {Size size = _wide}) async {
SharedPreferences.setMockInitialValues({});
_resize(tester, size);
addTearDown(tester.view.reset);
server = _Server(['a', 'b'], {'b'})..history = (_) async => chatPage([]);
bindServerIdentity(server, 'server-a');
runtime = ChatRuntime(gateway: server, serverKey: 'server-a');
manager = WindowManager(
kinds: WindowKinds(),
store: _Store(),
server: 'server-a',
);
windows = ChatWindows(
manager: manager,
runtime: runtime,
openInChat: (_) {},
)..start();
await manager.restore();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Stack(
fit: StackFit.expand,
children: [
ChatScreen(
gateway: server,
persistWorkspace: true,
runtime: runtime,
windows: windows,
),
Positioned.fill(child: WindowHost(manager: manager)),
],
),
),
),
);
await tester.pumpAndSettle();
}
Future<void> stop(WidgetTester tester) async {
await tester.pumpWidget(const SizedBox.shrink());
windows.dispose();
runtime.dispose();
manager.dispose();
server.close();
}
List<String> get floatingWindows => [
for (final w in windows.windows) w.contentId,
];
}
void _resize(WidgetTester tester, Size size) {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
}
List<String> _panes(WidgetTester tester) {
final workspace = find.byType(ChatWorkspace, skipOffstage: false);
if (workspace.evaluate().isEmpty) return const [];
return tester
.widget<ChatWorkspace>(workspace)
.controller
.panes
.map((pane) => pane.sessionId)
.toList();
}
Finder _shownThread(String id) => find
.byWidgetPredicate((w) => w is ChatThreadView && w.sessionId == id)
.hitTestable();
void main() {
final navigation = MobileChatNavigationController.instance;
tearDown(() {
unawaited(navigation.setValue(MobileChatNavigation.quickSwitch));
});
testWidgets('a phone tiles a floating chat; a wide layout floats it again', (
tester,
) async {
final app = _App();
await app.start(tester);
expect(app.floatingWindows, ['b']);
_resize(tester, _phone);
await tester.pumpAndSettle();
// No window at phone width: the chat is an open chat like the others,
// and the server still has it floating.
expect(app.floatingWindows, isEmpty);
expect(app.server.floating, {'b'});
// The list opens it full screen.
await tester.tap(find.byKey(const Key('chat-row-b')));
await tester.pumpAndSettle();
expect(_shownThread('b'), findsOneWidget);
expect(_panes(tester), ['a', 'b']);
_resize(tester, _wide);
await tester.pumpAndSettle();
expect(app.floatingWindows, ['b']);
expect(_panes(tester), ['a']);
expect(_shownThread('a'), findsOneWidget);
expect(app.server.floating, {'b'});
expect(app.server.open, ['a', 'b']);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('a floating chat opens from the list on a phone from the start', (
tester,
) async {
final app = _App();
await app.start(tester, size: _phone);
expect(app.floatingWindows, isEmpty);
await tester.tap(find.byKey(const Key('chat-row-b')));
await tester.pumpAndSettle();
expect(_shownThread('b'), findsOneWidget);
expect(_panes(tester), ['a', 'b']);
expect(app.server.floating, {'b'});
await app.stop(tester);
});
testWidgets('quick switch reaches a floating chat on a phone', (
tester,
) async {
final app = _App();
await app.start(tester, size: _phone);
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
expect(_shownThread('a'), findsOneWidget);
final controller = tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
.controller;
final b = controller.panes.firstWhere((pane) => pane.sessionId == 'b');
await tester.tap(find.byKey(ValueKey('chat-peek-${b.id}')));
await tester.pumpAndSettle();
expect(_shownThread('b'), findsOneWidget);
expect(app.floatingWindows, isEmpty);
await app.stop(tester);
});
testWidgets('the chat stack reaches a floating chat on a phone', (
tester,
) async {
unawaited(navigation.setValue(MobileChatNavigation.chatStack));
final app = _App();
await app.start(tester, size: _phone);
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-stack')));
await tester.pumpAndSettle();
final controller = tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
.controller;
final b = controller.panes.firstWhere((pane) => pane.sessionId == 'b');
await tester.tap(find.byKey(ValueKey('chat-stack-button-${b.id}')));
await tester.pumpAndSettle();
expect(_shownThread('b'), findsOneWidget);
await app.stop(tester);
});
testWidgets('a chat another device floats stays tiled on a phone', (
tester,
) async {
final app = _App();
await app.start(tester, size: _phone);
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
app.server.change(['a', 'b', 'c'], {'b', 'c'});
await tester.pumpAndSettle();
expect(app.floatingWindows, isEmpty);
expect(_panes(tester), ['a', 'b', 'c']);
// Removing a held chat on the phone drops it from the open chats.
final controller = tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace, skipOffstage: false))
.controller;
controller.close(controller.panes.last.id);
await tester.pumpAndSettle();
expect(app.server.open, ['a', 'b']);
expect(app.server.floating, {'b'});
await app.stop(tester);
});
}
@@ -0,0 +1,329 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/servers/server_scope.dart';
import 'package:pipelines_app/features/chat/chat_runtime.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/windows/chat_windows.dart';
import 'package:pipelines_app/features/chat/workspace/chat_pane_focus_flash.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart';
import 'package:pipelines_app/shell/windows/window_host.dart';
import 'package:pipelines_app/shell/windows/window_kind.dart';
import 'package:pipelines_app/shell/windows/window_manager.dart';
import 'package:pipelines_app/shell/windows/window_store.dart';
import 'package:pipelines_app/ui/input/keyboard_owner.dart';
import 'conversation/chat_thread_fixtures.dart';
const _ids = ['a', 'b', 'c', 'd'];
class _Gateway extends FakeChatGateway {
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final id in _ids)
{'id': id, 'title': 'Chat $id', 'directory': '/home/$id'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
return super.call(type, fields);
}
}
class _Store implements WindowStore {
String? value;
@override
Future<String?> read() async => value;
@override
Future<bool> write(String record) async {
value = record;
return true;
}
}
Finder _thread(String id) => find.byWidgetPredicate(
(widget) => widget is ChatThreadView && widget.sessionId == id,
skipOffstage: false,
);
Finder _input(String id) => find.descendant(
of: find.byKey(ValueKey('chat-composer-$id'), skipOffstage: false),
matching: find.byType(EditableText, skipOffstage: false),
skipOffstage: false,
);
bool _composerFocused(WidgetTester tester, String id) =>
tester.widget<EditableText>(_input(id)).focusNode.hasPrimaryFocus;
ChatWorkspaceController _workspace(WidgetTester tester) => tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace, skipOffstage: false))
.controller;
/// The chats whose focus ring is showing.
List<String> _flashing(WidgetTester tester) => [
for (final id in _ids)
if (find
.descendant(
of: find.ancestor(
of: _thread(id),
matching: find.byType(ChatPaneFocusFlash),
),
matching: find.byKey(const ValueKey('chat-pane-focus-flash')),
)
.evaluate()
.isNotEmpty)
id,
];
/// Saves a horizontal layout of [ids], left to right.
void _saved(List<String> ids) {
final layout = ChatWorkspaceController()..open(ids.first);
for (final id in ids.skip(1)) {
layout.splitActive(id, ChatSplitAxis.horizontal);
}
SharedPreferences.setMockInitialValues({
scopedServerKey(chatWorkspacePreferenceKey, 'server-a'): layout
.snapshot()!
.encode(),
});
}
/// The Chat destination with its floating windows over it, and optionally a
/// terminal that takes typing.
class _App {
final gateway = _Gateway()..history = (_) async => chatPage([]);
late final ChatRuntime runtime;
late final WindowManager manager;
late final ChatWindows windows;
final terminalFocus = FocusNode(debugLabel: 'test terminal');
final terminalTyped = <LogicalKeyboardKey>[];
Future<void> start(
WidgetTester tester, {
Size size = const Size(1800, 1000),
bool terminal = false,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
bindServerIdentity(gateway, 'server-a');
runtime = ChatRuntime(gateway: gateway, serverKey: 'server-a');
manager = WindowManager(
kinds: WindowKinds(),
store: _Store(),
server: 'server-a',
);
windows = ChatWindows(
manager: manager,
runtime: runtime,
openInChat: (_) {},
)..start();
await manager.restore();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Stack(
fit: StackFit.expand,
children: [
ChatScreen(
gateway: gateway,
persistWorkspace: true,
runtime: runtime,
windows: windows,
),
if (terminal)
Positioned(
left: 0,
top: 0,
width: 10,
height: 10,
child: TypingSurface(
child: Focus(
focusNode: terminalFocus,
onKeyEvent: (node, event) {
if (event is KeyDownEvent) {
terminalTyped.add(event.logicalKey);
}
return KeyEventResult.handled;
},
child: const SizedBox(),
),
),
),
Positioned.fill(child: WindowHost(manager: manager)),
],
),
),
),
);
await tester.pumpAndSettle();
}
Future<void> stop(WidgetTester tester) async {
await tester.pumpWidget(const SizedBox.shrink());
windows.dispose();
runtime.dispose();
manager.dispose();
terminalFocus.dispose();
gateway.close();
}
List<String> get floating => [for (final w in windows.windows) w.contentId];
}
/// Floats [session] from its pane menu.
Future<void> _float(WidgetTester tester, String session) async {
await tester.tap(
find
.descendant(
of: _thread(session),
matching: find.byTooltip('More actions'),
)
.hitTestable(),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Float (Alt+Y)').last);
await tester.pumpAndSettle();
}
/// Alt+] (or Alt+[ with [back]), leaving the focus ring mid-flash.
Future<void> _cycle(WidgetTester tester, {bool back = false}) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
final physical = back
? PhysicalKeyboardKey.bracketLeft
: PhysicalKeyboardKey.bracketRight;
final logical = back
? LogicalKeyboardKey.bracketLeft
: LogicalKeyboardKey.bracketRight;
await tester.sendKeyDownEvent(logical, physicalKey: physical);
await tester.sendKeyUpEvent(logical, physicalKey: physical);
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
for (var i = 0; i < 3; i++) {
await tester.pump();
}
}
/// Lets the flash finish.
Future<void> _settle(WidgetTester tester) async {
await tester.pump(chatPaneFlashDuration);
await tester.pumpAndSettle();
}
void main() {
testWidgets('Alt+] and Alt+[ cycle three tiled panes and a floating '
'window, wrapping, each composer focused and its ring flashing', (
tester,
) async {
_saved(['a', 'b', 'c', 'd']);
final app = _App();
await app.start(tester);
await _float(tester, 'd');
final workspace = _workspace(tester);
expect(workspace.panes.map((p) => p.sessionId), ['a', 'b', 'c']);
expect(app.floating, ['d']);
await tester.tapAt(tester.getCenter(_input('a')));
await tester.pumpAndSettle();
expect(_composerFocused(tester, 'a'), isTrue);
// Forward: the tiles left to right, then the window, then around.
for (final id in ['b', 'c', 'd', 'a']) {
await _cycle(tester);
expect(_composerFocused(tester, id), isTrue, reason: id);
expect(_flashing(tester), [id]);
if (id != 'd') expect(workspace.activePane?.sessionId, id);
await _settle(tester);
expect(_flashing(tester), isEmpty);
}
// Back: around to the window, then the tiles right to left.
for (final id in ['d', 'c', 'b', 'a']) {
await _cycle(tester, back: true);
expect(_composerFocused(tester, id), isTrue, reason: id);
expect(_flashing(tester), [id]);
await _settle(tester);
}
// Nothing opened, closed or moved.
expect(workspace.panes.map((p) => p.sessionId), ['a', 'b', 'c']);
expect(app.floating, ['d']);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('two tiled panes and a floating window cycle in the same order', (
tester,
) async {
_saved(['a', 'b', 'c']);
final app = _App();
await app.start(tester);
await _float(tester, 'c');
await tester.tapAt(tester.getCenter(_input('b')));
await tester.pumpAndSettle();
for (final id in ['c', 'a', 'b']) {
await _cycle(tester);
expect(_composerFocused(tester, id), isTrue, reason: id);
await _settle(tester);
}
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('with one pane on screen the keys do nothing', (tester) async {
_saved(['a']);
final app = _App();
await app.start(tester);
await tester.tapAt(tester.getCenter(_input('a')));
await tester.pumpAndSettle();
await _cycle(tester);
await _cycle(tester, back: true);
expect(_composerFocused(tester, 'a'), isTrue);
expect(_flashing(tester), isEmpty);
expect(_workspace(tester).paneCount, 1);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('on a phone layout the keys do nothing', (tester) async {
_saved(['a', 'b']);
final app = _App();
await app.start(tester, size: const Size(400, 800));
final workspace = _workspace(tester);
final active = workspace.activePane?.sessionId;
await _cycle(tester);
await _cycle(tester);
expect(workspace.activePane?.sessionId, active);
expect(_flashing(tester), isEmpty);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('a focused terminal keeps Alt+] and Alt+[', (tester) async {
_saved(['a', 'b']);
final app = _App();
await app.start(tester, terminal: true);
final workspace = _workspace(tester);
await tester.tapAt(tester.getCenter(_input('a')));
await tester.pumpAndSettle();
app.terminalFocus.requestFocus();
await tester.pumpAndSettle();
await _cycle(tester);
await _cycle(tester, back: true);
expect(app.terminalTyped, [
LogicalKeyboardKey.altLeft,
LogicalKeyboardKey.bracketRight,
LogicalKeyboardKey.altLeft,
LogicalKeyboardKey.bracketLeft,
]);
expect(app.terminalFocus.hasPrimaryFocus, isTrue);
expect(workspace.activePane?.sessionId, 'a');
expect(_flashing(tester), isEmpty);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
}
@@ -2,21 +2,34 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/speech/speech.dart';
import 'package:pipelines_app/features/chat/ui/speech/chat_speaking_control.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_read_aloud_button.dart';
import '../speech/fake_speech_engine.dart';
import 'chat_thread_fixtures.dart';
Widget _thread(FakeChatGateway gateway, String sessionId) => MaterialApp(
Widget _thread(
FakeChatGateway gateway,
String sessionId, {
String title = '',
bool pasteTarget = true,
}) => MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: Scaffold(
body: ChatThreadView(gateway: gateway, sessionId: sessionId, onBack: () {}),
body: ChatThreadView(
gateway: gateway,
sessionId: sessionId,
title: title,
pasteTarget: pasteTarget,
onBack: () {},
),
),
);
Future<(FakeSpeechEngine, SpeechController, FakeChatGateway)> _reading(
WidgetTester tester,
) async {
WidgetTester tester, {
String title = 'Alpha',
}) async {
tester.view.physicalSize = const Size(800, 1600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
@@ -33,42 +46,78 @@ Future<(FakeSpeechEngine, SpeechController, FakeChatGateway)> _reading(
],
),
]);
await tester.pumpWidget(_thread(gateway, 's1'));
await tester.pumpWidget(_thread(gateway, 's1', title: title));
await tester.pumpAndSettle();
await tester.tap(find.byTooltip(chatReadAloudLabel));
await tester.pump();
engine.onStart!();
await tester.pump();
expect(engine.spoken, ['Hello from the agent.']);
expect(speech.messageId, startsWith(speechScopePrefix('s1')));
expect(speech.reading.value, SpeechReading(scope: 's1', title: title));
return (engine, speech, gateway);
}
void main() {
testWidgets('switching the pane to another chat stops reading', (
testWidgets('switching the pane to another chat keeps reading', (
tester,
) async {
final (engine, speech, gateway) = await _reading(tester);
await tester.pumpWidget(_thread(gateway, 's2'));
await tester.pumpWidget(_thread(gateway, 's2', title: 'Beta'));
await tester.pumpAndSettle();
expect(speech.state, SpeechState.idle);
expect(engine.calls, contains('stop'));
expect(speech.state, SpeechState.speaking);
expect(engine.calls, isNot(contains('stop')));
expect(speechReading.value?.scope, 's1');
// Back in the chat, its reply shows the reading's Pause and Stop again.
await tester.pumpWidget(_thread(gateway, 's1', title: 'Alpha'));
await tester.pumpAndSettle();
expect(find.byTooltip(chatStopReadingLabel), findsOneWidget);
expect(find.byTooltip(chatPauseReadingLabel), findsOneWidget);
});
testWidgets('closing the chat stops reading', (tester) async {
testWidgets('leaving the conversation keeps its reply reading', (
tester,
) async {
final (engine, speech, _) = await _reading(tester);
await tester.pumpWidget(const MaterialApp(home: SizedBox()));
await tester.pumpAndSettle();
expect(speech.state, SpeechState.idle);
expect(engine.calls.last, 'stop');
});
testWidgets('closing a chat leaves another chat reading', (tester) async {
final (engine, speech, _) = await _reading(tester);
await speech.read(speechMessageId('elsewhere', 'b1'), ['Other reply']);
engine.onStart!();
await tester.pumpWidget(const MaterialApp(home: SizedBox()));
await tester.pumpAndSettle();
expect(speech.state, SpeechState.speaking);
expect(speech.messageId, speechMessageId('elsewhere', 'b1'));
expect(engine.calls, isNot(contains('stop')));
});
testWidgets('another chat names the reading and its Stop ends it', (
tester,
) async {
final (engine, speech, gateway) = await _reading(tester);
expect(find.text('Speaking · Alpha'), findsOneWidget);
await tester.pumpWidget(_thread(gateway, 's2', title: 'Beta'));
await tester.pumpAndSettle();
expect(find.text('Speaking · Alpha'), findsOneWidget);
await tester.tap(find.byTooltip(chatSpeakingStopLabel));
await tester.pumpAndSettle();
expect(speech.state, SpeechState.idle);
expect(engine.calls.last, 'stop');
expect(find.byKey(const Key('chat-speaking-control')), findsNothing);
});
testWidgets('the control follows a pause and a rename', (tester) async {
final (_, speech, gateway) = await _reading(tester);
await speech.pause();
await tester.pump();
expect(find.text('Paused · Alpha'), findsOneWidget);
await tester.pumpWidget(_thread(gateway, 's1', title: 'Renamed'));
await tester.pumpAndSettle();
expect(find.text('Paused · Renamed'), findsOneWidget);
});
testWidgets('only the active pane shows the global control', (tester) async {
final (_, _, gateway) = await _reading(tester);
await tester.pumpWidget(_thread(gateway, 's2', pasteTarget: false));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-speaking-control')), findsNothing);
});
}
@@ -1,13 +1,23 @@
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
/// Functional chat tests settle asynchronous state with reduced motion. Tests
/// covering animation explicitly opt back in and pump known frame durations.
///
/// Tests run as Android, where the Chat stack (the default) also shows on a
/// wide layout. Each test starts on Quick switch, the layout most of them
/// describe; the stack's own tests choose it.
Future<void> testExecutable(FutureOr<void> Function() testMain) async {
TestWidgetsFlutterBinding.ensureInitialized()
.platformDispatcher
.accessibilityFeaturesTestValue = const FakeAccessibilityFeatures(
disableAnimations: true,
);
setUp(
() => MobileChatNavigationController.instance.debugUse(
MobileChatNavigation.quickSwitch,
),
);
await testMain();
}
@@ -143,6 +143,29 @@ void main() {
expect(speech.state, SpeechState.idle);
});
testWidgets('reading names the conversation until the reply ends', (
tester,
) async {
reader();
await speech.read(speechMessageId('chat-1', 'm1'), ['Hi'], title: 'One');
expect(
speech.reading.value,
const SpeechReading(scope: 'chat-1', title: 'One'),
);
speech.retitle('chat-2', 'Other');
expect(speech.reading.value?.title, 'One');
speech.retitle('chat-1', 'Renamed');
expect(speech.reading.value?.title, 'Renamed');
// Another reply replaces it; finishing clears it.
await speech.read(speechMessageId('chat-2', 'm1'), ['Yo'], title: 'Two');
expect(speech.reading.value?.scope, 'chat-2');
engine.onStart!();
engine.onCompletion!();
expect(speech.reading.value, isNull);
expect(speech.state, SpeechState.idle);
});
testWidgets('voice and rate are applied and persist across a reload', (
tester,
) async {
@@ -0,0 +1,323 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/servers/server_scope.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_column.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_disc.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_drag.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_close_target.dart';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../conversation/chat_thread_fixtures.dart';
/// A chat server keeping the open-chat set, as the sync test's does.
class _Server extends FakeChatGateway {
List<String> open = ['a', 'b', 'c'];
int revision = 1;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final id in ['a', 'b', 'c', 'd'])
{'id': id, 'title': 'Chat $id', 'directory': '/w'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
if (type == 'chat_open_workspace') {
final request = fields['chat_open_workspace_request'] as Map?;
var rejected = false;
if (request != null && request['seed'] != true) {
if (request['base_revision'] != revision) {
rejected = true;
} else {
open = [
for (final e in (request['entries'] as List).cast<Map>())
'${e['session_id']}',
];
revision++;
}
}
return Future.value({
'type': 'chat_open_workspace',
'chat_open_workspace': {
'revision': revision,
'entries': [
for (final id in open) {'session_id': id},
],
if (rejected) 'rejected': true,
},
});
}
return super.call(type, fields);
}
}
Future<_Server> _pump(WidgetTester tester, {bool reduced = false}) async {
SharedPreferences.setMockInitialValues({});
unawaited(
MobileChatNavigationController.instance.setValue(
MobileChatNavigation.chatStack,
),
);
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final server = _Server()..history = (_) async => chatPage(const []);
bindServerIdentity(server, 'server-stack');
addTearDown(server.close);
await tester.pumpWidget(
MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(disableAnimations: reduced),
child: child!,
),
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) =>
ChatScreen(gateway: server, persistWorkspace: true),
},
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-stack')));
await tester.pumpAndSettle();
return server;
}
ChatWorkspaceController _workspace(WidgetTester tester) =>
tester.widget<ChatWorkspace>(find.byType(ChatWorkspace)).controller;
List<String> _order(WidgetTester tester) => [
for (final pane in _workspace(tester).panes) pane.sessionId,
];
/// Chat [id]'s avatar in the open column.
Finder _button(WidgetTester tester, String id) {
final pane = _workspace(
tester,
).panes.firstWhere((pane) => pane.sessionId == id);
return find.byKey(ValueKey('chat-stack-button-${pane.id}'));
}
final _add = find.byKey(const ValueKey('chat-stack-button-add'));
final _target = find.byType(ChatStackCloseTarget);
/// Holds [finder] until it lifts.
Future<TestGesture> _lift(WidgetTester tester, Finder finder) async {
final gesture = await tester.startGesture(tester.getCenter(finder));
await tester.pump(chatStackLiftDelay + const Duration(milliseconds: 20));
return gesture;
}
double _shown(WidgetTester tester) =>
tester.widget<ChatStackCloseTarget>(_target).armed.value;
void main() {
final navigation = MobileChatNavigationController.instance;
tearDown(() {
unawaited(navigation.setValue(MobileChatNavigation.quickSwitch));
});
test('movePane moves a pane and keeps the active one', () {
final controller = ChatWorkspaceController()..open('a');
controller
..splitActive('b', ChatSplitAxis.horizontal)
..splitActive('c', ChatSplitAxis.horizontal);
final active = controller.activePaneId;
final a = controller.panes.first.id;
controller.movePane(a, 2);
expect(controller.panes.map((p) => p.sessionId), ['b', 'c', 'a']);
expect(controller.panes.last.id, a);
expect(controller.activePaneId, active);
controller.dispose();
});
testWidgets('hold and drag reorders, and the order reaches the server', (
tester,
) async {
final server = await _pump(tester);
expect(_order(tester), ['a', 'b', 'c']);
final b = tester.getCenter(_button(tester, 'b'));
final gesture = await _lift(tester, _button(tester, 'a'));
// Lifted: the remove target comes in.
await tester.pumpAndSettle();
expect(_shown(tester), 1);
// Up past the middle of c (its middle would group): b and c slide down.
await gesture.moveBy(const Offset(0, -kChatStackPitch * 2.4));
await tester.pumpAndSettle();
expect(tester.getCenter(_button(tester, 'b')).dy, b.dy + kChatStackPitch);
await gesture.up();
await tester.pumpAndSettle();
expect(_order(tester), ['b', 'c', 'a']);
expect(server.open, ['b', 'c', 'a']);
// Everyone settles in the new slots; the column stays open.
expect(tester.getCenter(_button(tester, 'b')).dy, closeTo(b.dy + 56, .5));
expect(_shown(tester), 0);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('dropping on the × removes; Undo restores the place', (
tester,
) async {
final server = await _pump(tester);
final gesture = await _lift(tester, _button(tester, 'b'));
await tester.pumpAndSettle();
final from = tester.getCenter(_button(tester, 'b'));
await gesture.moveBy(tester.getCenter(_target) - from);
await tester.pumpAndSettle();
final drag = tester.widget<ChatStackCloseTarget>(_target).hover;
expect(drag.value, 1);
await gesture.up();
await tester.pumpAndSettle();
expect(find.text('Removed Chat b from open chats'), findsOneWidget);
expect(_order(tester), ['a', 'c']);
expect(server.open, ['a', 'c']);
await tester.tap(find.text('Undo'));
await tester.pumpAndSettle();
expect(_order(tester), ['a', 'b', 'c']);
expect(server.open, ['a', 'b', 'c']);
// The chat on screen stays on screen.
expect(_workspace(tester).activePane?.sessionId, 'a');
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Escape, or a drop away from the column, puts the chat back', (
tester,
) async {
final server = await _pump(tester);
final home = tester.getCenter(_button(tester, 'a'));
var gesture = await _lift(tester, _button(tester, 'a'));
await gesture.moveBy(const Offset(0, -kChatStackPitch * 2));
await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
await gesture.up();
await tester.pumpAndSettle();
expect(_order(tester), ['a', 'b', 'c']);
expect(tester.getCenter(_button(tester, 'a')), home);
// Escape only cancelled the drag: the column is still open.
expect(find.byType(ChatStackColumn), findsOneWidget);
gesture = await _lift(tester, _button(tester, 'a'));
await gesture.moveBy(const Offset(-200, -kChatStackPitch * 3));
await tester.pumpAndSettle();
await gesture.up();
await tester.pumpAndSettle();
expect(_order(tester), ['a', 'b', 'c']);
expect(server.open, ['a', 'b', 'c']);
expect(tester.getCenter(_button(tester, 'a')), home);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a tap still opens a chat; Add chat does not lift', (
tester,
) async {
await _pump(tester);
final add = tester.getCenter(_add);
final gesture = await _lift(tester, _add);
await tester.pumpAndSettle();
expect(_shown(tester), 0);
await gesture.moveBy(const Offset(0, kChatStackPitch * 2));
await tester.pumpAndSettle();
expect(tester.getCenter(_add), add);
await gesture.up();
await tester.pumpAndSettle();
expect(_order(tester), ['a', 'b', 'c']);
// A drag that moved off "+" is no tap: the column is still open.
expect(find.byType(ChatStackColumn), findsOneWidget);
await tester.tap(_button(tester, 'c'));
await tester.pumpAndSettle();
expect(
find
.byWidgetPredicate((w) => w is ChatThreadView && w.sessionId == 'c')
.hitTestable(),
findsOneWidget,
);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Move up, Move down and Remove are semantic actions', (
tester,
) async {
final semantics = tester.ensureSemantics();
final server = await _pump(tester);
void act(String id, String label) {
final node = tester.getSemantics(_button(tester, id));
final action = node
.getSemanticsData()
.customSemanticsActionIds!
.map(CustomSemanticsAction.getAction)
.firstWhere((action) => action!.label == label)!;
tester.binding.renderViews.first.owner!.semanticsOwner!.performAction(
node.id,
SemanticsAction.customAction,
CustomSemanticsAction.getIdentifier(action),
);
}
// The bottom chat cannot move down; the top one cannot move up.
final bottom = tester.getSemantics(_button(tester, 'a'));
expect(
bottom.getSemanticsData().customSemanticsActionIds!.map(
(id) => CustomSemanticsAction.getAction(id)!.label,
),
unorderedEquals([
ChatStackColumn.moveUpLabel,
ChatStackColumn.removeLabel,
]),
);
act('a', ChatStackColumn.moveUpLabel);
await tester.pumpAndSettle();
expect(server.open, ['b', 'a', 'c']);
act('c', ChatStackColumn.moveDownLabel);
await tester.pumpAndSettle();
expect(server.open, ['b', 'c', 'a']);
act('b', ChatStackColumn.removeLabel);
await tester.pumpAndSettle();
expect(server.open, ['c', 'a']);
expect(find.text('Removed Chat b from open chats'), findsOneWidget);
semantics.dispose();
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('reduced motion: neighbours swap at once, the × only fades', (
tester,
) async {
await _pump(tester, reduced: true);
final b = tester.getCenter(_button(tester, 'b'));
final gesture = await _lift(tester, _button(tester, 'a'));
expect(_shown(tester), 1);
await gesture.moveBy(const Offset(0, -kChatStackPitch * 1.4));
await tester.pump();
expect(tester.getCenter(_button(tester, 'b')).dy, b.dy + kChatStackPitch);
// No turn or growth: the button only fades.
expect(
find.descendant(of: _target, matching: find.byType(RotationTransition)),
findsNothing,
);
await gesture.up();
await tester.pump();
expect(_order(tester), ['b', 'a', 'c']);
expect(_shown(tester), 0);
await tester.pumpAndSettle();
await tester.pumpWidget(const SizedBox.shrink());
});
}
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_close_target.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_column.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_disc.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_entry.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_fab.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_pose.dart';
@@ -103,7 +105,8 @@ void main() {
expect(find.text('Chat 0'), findsOneWidget);
expect(find.text('Chat 4'), findsOneWidget);
expect(find.text(ChatStackColumn.addLabel), findsOneWidget);
// Item 0 sits on the stack; each further item rises one pitch.
// The stack's slot holds the close button; item 0 sits a pitch above
// it and each further item rises one more.
final first = tester.getCenter(
find.byKey(const ValueKey('chat-stack-button-pane-0')),
);
@@ -114,7 +117,11 @@ void main() {
find.byKey(const ValueKey('chat-stack-button-add')),
);
expect(first.dx, closeTo(slot.center.dx, .5));
expect(first.dy, closeTo(slot.center.dy, .5));
expect(first.dy, closeTo(slot.center.dy - kChatStackPitch, .5));
expect(
tester.getCenter(find.bySemanticsLabel(ChatStackCloseTarget.label)),
slot.center,
);
expect(second.dy, lessThan(first.dy));
expect(add.dy, lessThan(second.dy));
// Outside the column.
@@ -126,6 +133,22 @@ void main() {
expect(harness.opened, isEmpty);
});
testWidgets('the close button where the pile was folds the column', (
tester,
) async {
final harness = await _pump(tester);
final slot = tester.getRect(find.byKey(const Key('chat-stack')));
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
await tester.tapAt(slot.center);
await tester.pump();
expect(_state(tester).expanded, isFalse);
await _settle(tester);
expect(find.byType(ChatStackColumn), findsNothing);
expect(harness.opened, isEmpty);
expect(harness.added, 0);
});
testWidgets('tapping a chat opens it and folds the column', (tester) async {
final harness = await _pump(tester);
await tester.tap(find.byKey(const Key('chat-stack')));
@@ -145,17 +168,18 @@ void main() {
expect(harness.opened, ['s3']);
});
testWidgets('add opens the picker; long press removes', (tester) async {
testWidgets('add opens the picker; a hold alone removes nothing', (
tester,
) async {
final harness = await _pump(tester);
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
// A hold lifts the chat for a drag; let go in place, it settles back.
await tester.longPress(find.text('Chat 2'));
await _settle(tester);
expect(harness.removed, ['s2']);
// Removing folds the column, so a snack bar's Undo is in reach.
expect(find.byType(ChatStackColumn), findsNothing);
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
expect(harness.removed, isEmpty);
expect(harness.opened, isEmpty);
expect(find.byType(ChatStackColumn), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('chat-stack-button-add')));
await _settle(tester);
expect(harness.added, 1);
@@ -0,0 +1,371 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/servers/server_scope.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_close_target.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_column.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_disc.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_drag.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_group_dialogs.dart';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../conversation/chat_thread_fixtures.dart';
/// A chat server keeping the open-chat set with each entry's group.
class _Server extends FakeChatGateway {
List<String> open = ['a', 'b', 'c'];
Map<String, String> groups = {};
int revision = 1;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final id in ['a', 'b', 'c', 'd'])
{'id': id, 'title': 'Chat $id', 'directory': '/w'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
if (type == 'chat_open_workspace') {
final request = fields['chat_open_workspace_request'] as Map?;
var rejected = false;
if (request != null && request['seed'] != true) {
if (request['base_revision'] != revision) {
rejected = true;
} else {
final entries = (request['entries'] as List).cast<Map>();
open = [for (final e in entries) '${e['session_id']}'];
groups = {
for (final e in entries)
if (e['group'] != null) '${e['session_id']}': '${e['group']}',
};
revision++;
}
}
return Future.value({
'type': 'chat_open_workspace',
'chat_open_workspace': _body(rejected),
});
}
return super.call(type, fields);
}
JsonMap _body([bool rejected = false]) => {
'revision': revision,
'entries': [
for (final id in open)
{'session_id': id, if (groups[id] != null) 'group': groups[id]},
],
if (rejected) 'rejected': true,
};
/// Another device changed the set.
void change(List<String> ids, Map<String, String> byGroup) {
open = ids;
groups = byGroup;
revision++;
emitRaw({
'type': 'chat_open_workspace_changed',
'chat_open_workspace': _body(),
});
}
}
Future<_Server> _pump(WidgetTester tester) async {
SharedPreferences.setMockInitialValues({});
MobileChatNavigationController.instance.debugUse(
MobileChatNavigation.chatStack,
);
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final server = _Server()..history = (_) async => chatPage(const []);
bindServerIdentity(server, 'server-groups');
addTearDown(server.close);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) =>
ChatScreen(gateway: server, persistWorkspace: true),
},
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
await _expand(tester);
return server;
}
Future<void> _expand(WidgetTester tester) async {
await tester.tap(find.byKey(const Key('chat-stack')));
await tester.pumpAndSettle();
}
ChatWorkspaceController _workspace(WidgetTester tester) =>
tester.widget<ChatWorkspace>(find.byType(ChatWorkspace)).controller;
Finder _chat(WidgetTester tester, String id) {
final pane = _workspace(
tester,
).panes.firstWhere((pane) => pane.sessionId == id);
return find.byKey(ValueKey('chat-stack-button-${pane.id}'));
}
Finder _group(String name) =>
find.byKey(ValueKey('chat-stack-button-group-$name'));
final _header = find.byKey(const ValueKey('chat-stack-button-header'));
/// Holds [item] until it lifts, moves it by [by], lets go.
Future<void> _drag(WidgetTester tester, Finder item, Offset by) async {
final gesture = await tester.startGesture(tester.getCenter(item));
await tester.pump(chatStackLiftDelay + const Duration(milliseconds: 20));
await gesture.moveBy(by);
await tester.pumpAndSettle();
await gesture.up();
await tester.pumpAndSettle();
}
const _up = Offset(0, -kChatStackPitch);
/// Makes group "Work" of b and a (a dropped onto b), naming it.
Future<void> _makeWork(WidgetTester tester) async {
await _drag(tester, _chat(tester, 'a'), _up);
expect(find.text('Name the group'), findsOneWidget);
await tester.enterText(
find.byKey(const Key('chat-stack-group-name')),
'Work',
);
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
}
void _act(WidgetTester tester, Finder target, String label) {
final node = tester.getSemantics(target);
final action = node
.getSemanticsData()
.customSemanticsActionIds!
.map(CustomSemanticsAction.getAction)
.firstWhere((action) => action!.label == label)!;
tester.binding.renderViews.first.owner!.semanticsOwner!.performAction(
node.id,
SemanticsAction.customAction,
CustomSemanticsAction.getIdentifier(action),
);
}
void main() {
tearDown(
() => MobileChatNavigationController.instance.debugUse(
MobileChatNavigation.quickSwitch,
),
);
testWidgets('a chat dropped onto a chat makes a named group that syncs', (
tester,
) async {
final server = await _pump(tester);
// Mid-drag over b's middle: b grows (the drop target).
final gesture = await tester.startGesture(
tester.getCenter(_chat(tester, 'a')),
);
await tester.pump(chatStackLiftDelay + const Duration(milliseconds: 20));
final b = tester.getSize(_chat(tester, 'b'));
await gesture.moveBy(_up);
await tester.pumpAndSettle();
expect(
tester.getRect(_chat(tester, 'b')).width,
closeTo(b.width * chatStackOntoScale, .5),
);
// The dragged chat shrinks onto it, so the target's ring shows around.
expect(
tester.getRect(_chat(tester, 'a')).width,
closeTo(b.width * chatStackLiftScale * chatStackOverRemoveScale, .5),
);
await gesture.up();
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('chat-stack-group-name')),
'Work',
);
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
expect(server.open, ['b', 'a', 'c']);
expect(server.groups, {'b': 'Work', 'a': 'Work'});
expect(_group('Work'), findsOneWidget);
expect(find.text('Work'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a group opens in place; header, Back and outside return', (
tester,
) async {
await _pump(tester);
await _makeWork(tester);
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
expect(_chat(tester, 'a').hitTestable(), findsOneWidget);
expect(_chat(tester, 'b').hitTestable(), findsOneWidget);
expect(_header.hitTestable(), findsOneWidget);
// The top level's chat c is behind: no input.
expect(_chat(tester, 'c').hitTestable(), findsNothing);
await tester.tap(_header);
await tester.pumpAndSettle();
expect(_group('Work').hitTestable(), findsOneWidget);
// Outside: out of the group first, then folded.
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
await tester.tapAt(const Offset(40, 120));
await tester.pumpAndSettle();
expect(_group('Work').hitTestable(), findsOneWidget);
await tester.tapAt(const Offset(40, 120));
await tester.pumpAndSettle();
expect(find.byType(ChatStackColumn), findsNothing);
// Back leaves the group, then folds.
await _expand(tester);
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(_group('Work').hitTestable(), findsOneWidget);
// A chat in a group opens as any other.
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
await tester.tap(_chat(tester, 'b'));
await tester.pumpAndSettle();
expect(_workspace(tester).activePane?.sessionId, 'b');
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a chat joins a group; a group takes a chat in', (tester) async {
final server = await _pump(tester);
await _makeWork(tester);
// Top level: Work (b, a) at the bottom, c above it. c down onto it.
await _drag(tester, _chat(tester, 'c'), -_up);
expect(server.groups, {'b': 'Work', 'a': 'Work', 'c': 'Work'});
expect(server.open, ['b', 'a', 'c']);
// Leaving from inside the group: drop on its header.
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
await _drag(tester, _chat(tester, 'c'), _up);
expect(server.groups, {'b': 'Work', 'a': 'Work'});
expect(server.open, ['b', 'a', 'c']);
// Back on the top level: drag the group onto c.
await tester.tap(_header);
await tester.pumpAndSettle();
await _drag(tester, _group('Work'), _up);
expect(server.groups, {'b': 'Work', 'a': 'Work', 'c': 'Work'});
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('the last chat left alone dissolves the group', (tester) async {
final server = await _pump(tester);
await _makeWork(tester);
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
// a is second in the group: one slot up is the header.
await _drag(tester, _chat(tester, 'a'), _up);
expect(server.groups, isEmpty);
// The group is gone: back on the top level.
expect(_header, findsNothing);
expect(_chat(tester, 'a').hitTestable(), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Rename, Ungroup and Close all; each syncs, Undo restores', (
tester,
) async {
final semantics = tester.ensureSemantics();
final server = await _pump(tester);
await _makeWork(tester);
_act(tester, _group('Work'), ChatStackGroupAction.rename.label);
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('chat-stack-group-name')),
'Personal',
);
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
expect(server.groups, {'b': 'Personal', 'a': 'Personal'});
_act(tester, _group('Personal'), ChatStackGroupAction.ungroup.label);
await tester.pumpAndSettle();
expect(server.groups, isEmpty);
expect(find.text('Ungrouped Personal'), findsOneWidget);
await tester.tap(find.text('Undo'));
await tester.pumpAndSettle();
expect(server.groups, {'b': 'Personal', 'a': 'Personal'});
await _expand(tester);
_act(tester, _group('Personal'), ChatStackGroupAction.closeAll.label);
await tester.pumpAndSettle();
expect(server.open, ['c']);
await tester.tap(find.text('Undo'));
await tester.pumpAndSettle();
expect(server.open, ['b', 'a', 'c']);
expect(server.groups, {'b': 'Personal', 'a': 'Personal'});
semantics.dispose();
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Move to group and Remove from group as semantic actions', (
tester,
) async {
final semantics = tester.ensureSemantics();
final server = await _pump(tester);
await _makeWork(tester);
_act(tester, _chat(tester, 'c'), ChatStackColumn.moveToGroupLabel);
await tester.pumpAndSettle();
await tester.tap(find.text('Work').last);
await tester.pumpAndSettle();
expect(server.groups['c'], 'Work');
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
_act(tester, _chat(tester, 'b'), ChatStackColumn.leaveGroupLabel);
await tester.pumpAndSettle();
expect(server.groups, {'a': 'Work', 'c': 'Work'});
expect(server.open, ['a', 'c', 'b']);
semantics.dispose();
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a group dropped on the close button is ungrouped', (
tester,
) async {
final server = await _pump(tester);
await _makeWork(tester);
final group = tester.getCenter(_group('Work'));
final close = tester.getCenter(
find.bySemanticsLabel(ChatStackCloseTarget.label),
);
await _drag(tester, _group('Work'), close - group);
expect(server.groups, isEmpty);
expect(server.open, ['b', 'a', 'c']);
expect(find.text('Ungrouped Work'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('groups from another device appear', (tester) async {
final server = await _pump(tester);
server.change(['a', 'b', 'c'], {'a': 'Home', 'c': 'Home'});
await tester.pumpAndSettle();
expect(_group('Home'), findsOneWidget);
expect(find.text('Home'), findsOneWidget);
// The group's pill counts its chats.
expect(find.text('2'), findsWidgets);
await tester.pumpWidget(const SizedBox.shrink());
});
}
@@ -0,0 +1,168 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_drop_target.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_entry.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_group_ops.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_groups.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_node.dart';
import 'package:pipelines_app/features/chat/workspace/chat_open_workspace_gateway.dart';
ChatStackEntry _entry(String id, [String? group]) =>
ChatStackEntry(paneId: 'p$id', session: {'id': id}, group: group);
void main() {
group('ChatStackGroups', () {
test('assigns, merges on rename, dissolves a group of one', () {
final groups = ChatStackGroups();
var changes = 0;
groups.addListener(() => changes++);
// One chat is no group.
groups.assign(['a'], 'Work');
expect(groups.assignments, isEmpty);
expect(changes, 0);
groups.assign(['a', 'b'], 'Work');
groups.assign(['c', 'd'], 'Home');
expect(groups.membersOf('Work'), ['a', 'b']);
expect(groups.nextName(), 'Group 1');
groups.rename('Home', 'Work');
expect(groups.membersOf('Work'), ['a', 'b', 'c', 'd']);
groups.unassign(['a', 'b', 'c']);
expect(groups.assignments, isEmpty);
groups.assign(['a', 'b', 'c'], 'Group 1');
expect(groups.nextName(), 'Group 2');
groups.retain({'a', 'x'});
expect(groups.assignments, isEmpty);
expect(changes, greaterThan(0));
groups.dispose();
});
test('names are trimmed, bounded and never empty', () {
expect(chatStackGroupName(' Work \n'), 'Work');
expect(chatStackGroupName(' '), isNull);
expect(chatStackGroupName('a\tb'), 'a b');
expect(chatStackGroupName('x' * 100)!.length, chatStackGroupNameLimit);
});
});
group('nodes and drops', () {
final entries = [
_entry('a'),
_entry('b', 'Work'),
_entry('c'),
_entry('d', 'Work'),
];
final nodes = chatStackNodes(entries);
test('a group stands where its first chat is', () {
expect(nodes.map((node) => node.key), [
'chat:pa',
'group:Work',
'chat:pc',
]);
expect(chatStackOrder(nodes), ['a', 'b', 'd', 'c']);
// A lone member shows as a chat.
expect(
chatStackNodes([_entry('x', 'Solo')]).single,
isA<ChatStackChatNode>(),
);
});
test('dropping onto a chat or a group joins as expected', () {
final made = chatStackJoined(nodes, 2, 0, () => 'Group 1');
expect(made.created, isTrue);
expect(made.join, ['a', 'c']);
expect(made.order, ['a', 'c', 'b', 'd']);
final joined = chatStackJoined(nodes, 0, 1, () => 'unused');
expect((joined.group, joined.created), ('Work', false));
expect(joined.join, ['a']);
expect(joined.order, ['b', 'd', 'a', 'c']);
final took = chatStackJoined(nodes, 1, 2, () => 'unused');
expect(took.join, ['c']);
expect(took.order, ['a', 'b', 'd', 'c']);
expect(chatStackLeft(nodes, 'Work', 'b'), ['a', 'd', 'b', 'c']);
expect(chatStackRegrouped(nodes, 'Work', ['d', 'b']), [
'a',
'd',
'b',
'c',
]);
expect(chatStackMoved(nodes, 0, 2), ['b', 'd', 'c', 'a']);
});
test('the middle of an item groups, its edges reorder, stably', () {
bool all(int _) => true;
// From slot 0, one slot up: the middle of item 1.
expect(
chatStackDropTarget(
position: 1,
from: 0,
count: 3,
slot: 0,
canDropOnto: all,
),
(slot: 0, onto: 1),
);
// Past its middle: the gap moves above it...
expect(
chatStackDropTarget(
position: 1.4,
from: 0,
count: 3,
slot: 0,
canDropOnto: all,
),
(slot: 1, onto: null),
);
// ...and holds there while item 1 slides below it.
expect(
chatStackDropTarget(
position: 1.3,
from: 0,
count: 3,
slot: 1,
canDropOnto: all,
),
(slot: 1, onto: null),
);
// Below its middle the gap stays below it.
expect(
chatStackDropTarget(
position: .7,
from: 0,
count: 3,
slot: 0,
canDropOnto: all,
),
(slot: 0, onto: null),
);
// Without grouping the middle reorders too; the gap never passes
// lastSlot.
expect(
chatStackDropTarget(
position: 2.3,
from: 0,
count: 3,
slot: 1,
lastSlot: 1,
),
(slot: 1, onto: null),
);
});
});
test('an entry carries its group over the wire', () {
final entry = ChatOpenWorkspaceEntry.fromJson({
'session_id': 'a',
'group': ' Work ',
})!;
expect(entry.group, 'Work');
expect(entry.toJson(), {'session_id': 'a', 'group': 'Work'});
expect(ChatOpenWorkspaceEntry.fromJson({'session_id': 'b'})!.group, isNull);
const snapshot = ChatOpenWorkspaceSnapshot(1, [
ChatOpenWorkspaceEntry('a'),
]);
expect(
snapshot.sameEntries([const ChatOpenWorkspaceEntry('a', group: 'W')]),
isFalse,
);
});
}
@@ -34,6 +34,15 @@ class _Gateway extends FakeChatGateway {
}
}
class _Store implements MobileChatNavigationStore {
_Store(this.value);
final String? value;
@override
Future<String?> load() async => value;
@override
Future<bool> save(String value) async => true;
}
Future<void> _pump(WidgetTester tester, Size size) async {
SharedPreferences.setMockInitialValues({});
unawaited(
@@ -114,39 +123,53 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('long press removes a chat, Undo restores it', (tester) async {
await _pump(tester, const Size(390, 844));
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
await tester.tap(_stack);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('chat-stack-button-add')));
await tester.pumpAndSettle();
await tester.tap(find.text('Gamma').last);
await tester.pumpAndSettle();
expect(find.bySemanticsLabel(chatStackLabel(2)), findsOneWidget);
await tester.tap(_stack);
await tester.pumpAndSettle();
await tester.longPress(find.text('Alpha').last);
await tester.pumpAndSettle();
expect(find.text('Removed Alpha from open chats'), findsOneWidget);
expect(find.bySemanticsLabel(chatStackLabel(1)), findsOneWidget);
await tester.tap(find.text('Undo'));
await tester.pumpAndSettle();
// Gamma stays on screen; Alpha is back in the stack.
expect(_thread('c').hitTestable(), findsOneWidget);
expect(find.bySemanticsLabel(chatStackLabel(2)), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets(
'a wide desktop window keeps its panes and shows no stack',
variant: TargetPlatformVariant.desktop(),
(tester) async {
await _pump(tester, const Size(1280, 800));
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
expect(_thread('a'), findsOneWidget);
expect(_stack, findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
},
);
testWidgets('a wide window keeps its panes and shows no stack', (
tester,
) async {
await _pump(tester, const Size(1280, 800));
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
expect(_thread('a'), findsOneWidget);
expect(_stack, findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
testWidgets(
'a wide phone or tablet layout (an unfolded foldable) keeps the stack',
variant: TargetPlatformVariant({
TargetPlatform.android,
TargetPlatform.iOS,
}),
(tester) async {
await _pump(tester, const Size(1280, 800));
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
expect(_thread('a'), findsOneWidget);
// The list stays beside the chat, the stack floats over the pane.
expect(find.byKey(const Key('chat-row-b')), findsOneWidget);
expect(_stack.hitTestable(), findsOneWidget);
await tester.tap(_stack);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('chat-stack-button-add')));
await tester.pumpAndSettle();
await tester.tap(find.text('Beta').last);
await tester.pumpAndSettle();
expect(find.bySemanticsLabel(chatStackLabel(2)), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
},
);
test('Chat stack is the default without a stored choice', () async {
final controller = MobileChatNavigationController(store: _Store(null));
expect(controller.value, MobileChatNavigation.chatStack);
await controller.restore();
expect(controller.value, MobileChatNavigation.chatStack);
final chosen = MobileChatNavigationController(store: _Store('quickSwitch'));
await chosen.restore();
expect(chosen.value, MobileChatNavigation.quickSwitch);
controller.dispose();
chosen.dispose();
});
}
@@ -0,0 +1,78 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/data/chat_repository.dart';
import 'package:pipelines_app/features/chat/speech/speech.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_controller.dart';
import '../../speech/fake_speech_engine.dart';
import 'chat_test_harness.dart';
import 'fake_chat_gateway.dart';
JsonMap _row(String id, {bool closed = false}) => {
'id': id,
'title': id,
'directory': '/w',
if (closed) 'closed_at': '2026-12-03T10:00:00Z',
};
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late FakeChatGateway gateway;
late ChatSessionsController controller;
late SpeechController speech;
setUp(() async {
speech = installFakeSpeech(FakeSpeechEngine());
gateway = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [_row('s1'), _row('s2')],
}
..actionHandler = (_, _) async => const {};
controller = ChatSessionsController(
ChatRepository(gateway),
localStore: MemoryChatSessionLocalStore(),
);
addTearDown(controller.dispose);
await controller.refresh();
await speech.read(speechMessageId('s1', 'r1'), ['Hello.']);
expect(speech.state, SpeechState.speaking);
});
test('closing the reading chat stops it', () async {
await controller.close('s1');
await pumpEventQueue();
expect(speech.state, SpeechState.idle);
});
test('closing another chat keeps reading', () async {
await controller.close('s2');
await pumpEventQueue();
expect(speech.state, SpeechState.speaking);
});
test('a chat closed on another device stops it on the next read', () async {
gateway.sessionsReply = {
'chat_sessions': [_row('s1', closed: true), _row('s2')],
};
await controller.refresh();
await pumpEventQueue();
expect(speech.state, SpeechState.idle);
});
test('a deleted chat stops it; a failed read does not', () async {
gateway.sessionsHandler = () async => throw StateError('offline');
await controller.refresh();
await pumpEventQueue();
expect(speech.state, SpeechState.speaking);
gateway
..sessionsHandler = null
..sessionsReply = {
'chat_sessions': [_row('s2')],
};
await controller.refresh();
await pumpEventQueue();
expect(speech.state, SpeechState.idle);
});
}
@@ -0,0 +1,104 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/speech/speech.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_awaiting.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_compact_avatar.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
import '../../speech/fake_speech_engine.dart';
const _speaking = Key('chat-row-speaking');
Widget _avatars({bool reduceMotion = false}) => MaterialApp(
home: MediaQuery(
data: MediaQueryData(disableAnimations: reduceMotion),
child: const Scaffold(
body: Column(
children: [
ChatSessionAvatar(
key: Key('one'),
session: {'id': 's1', 'title': 'One'},
running: true,
awaitingOperator: 2,
),
ChatSessionAvatar(
key: Key('two'),
session: {'id': 's2', 'title': 'Two'},
),
ChatCompactAvatar(
key: Key('two-compact'),
sessionId: 's2',
title: 'Two',
color: Colors.blue,
active: false,
visible: false,
running: false,
backgroundTasks: 0,
unread: false,
),
],
),
),
),
);
Finder _badgeOf(String avatar) => find.descendant(
of: find.byKey(Key(avatar)),
matching: find.byKey(_speaking),
);
Future<void> _read(WidgetTester tester, SpeechController speech, String chat) =>
tester.runAsync(() => speech.read(speechMessageId(chat, 'r1'), ['Hi.']));
void main() {
testWidgets('the reading chat wears the speaking badge, and it moves', (
tester,
) async {
final speech = installFakeSpeech(FakeSpeechEngine());
await tester.pumpWidget(_avatars());
expect(find.byKey(_speaking), findsNothing);
await _read(tester, speech, 's1');
await tester.pump();
expect(_badgeOf('one'), findsOneWidget);
expect(_badgeOf('two'), findsNothing);
expect(_badgeOf('two-compact'), findsNothing);
// Speaking outranks the operator wait and the running spinner.
expect(find.byKey(const Key('chat-row-working')), findsNothing);
expect(find.byType(ChatAwaitingBadge), findsNothing);
await _read(tester, speech, 's2');
await tester.pump();
expect(_badgeOf('one'), findsNothing);
expect(_badgeOf('two'), findsOneWidget);
expect(_badgeOf('two-compact'), findsOneWidget);
expect(find.byKey(const Key('chat-speaking-wave')), findsNWidgets(2));
await tester.runAsync(speech.stop);
await tester.pump();
expect(find.byKey(_speaking), findsNothing);
});
testWidgets('a Settings voice sample marks no chat', (tester) async {
final speech = installFakeSpeech(FakeSpeechEngine());
await tester.pumpWidget(_avatars());
await tester.runAsync(speech.sample);
await tester.pump();
expect(speech.state, SpeechState.speaking);
expect(find.byKey(_speaking), findsNothing);
});
testWidgets('reduced motion shows a still speaker', (tester) async {
final speech = installFakeSpeech(FakeSpeechEngine());
await tester.pumpWidget(_avatars(reduceMotion: true));
// The first chat's spinner gives way to the speaking badge.
await _read(tester, speech, 's1');
await tester.pump();
expect(_badgeOf('one'), findsOneWidget);
expect(find.byKey(const Key('chat-speaking-still')), findsOneWidget);
expect(find.byKey(const Key('chat-speaking-wave')), findsNothing);
// Nothing ticks: settling finishes with the badge still shown.
await tester.pumpAndSettle();
expect(_badgeOf('one'), findsOneWidget);
});
}
@@ -0,0 +1,122 @@
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/workspace/chat_pane_cycle.dart';
KeyEvent _down(
PhysicalKeyboardKey physical,
LogicalKeyboardKey logical, {
String? character,
}) => KeyDownEvent(
physicalKey: physical,
logicalKey: logical,
character: character,
timeStamp: Duration.zero,
);
final _right = _down(
PhysicalKeyboardKey.bracketRight,
LogicalKeyboardKey.bracketRight,
);
final _left = _down(
PhysicalKeyboardKey.bracketLeft,
LogicalKeyboardKey.bracketLeft,
);
int? _step(
KeyEvent event,
Set<LogicalKeyboardKey> held, [
TargetPlatform platform = TargetPlatform.linux,
]) => chatPaneCycleShortcut(event, _FakeKeyboard(held), platform: platform);
void main() {
test('Alt+] goes forward and Alt+[ back on every platform', () {
for (final platform in TargetPlatform.values) {
expect(_step(_right, {LogicalKeyboardKey.altLeft}, platform), 1);
expect(_step(_left, {LogicalKeyboardKey.altLeft}, platform), -1);
}
});
test('Option+] types a quote on a Mac: it matches by key position', () {
final quote = _down(
PhysicalKeyboardKey.bracketRight,
const LogicalKeyboardKey(0x2018),
character: '‘',
);
expect(_step(quote, {LogicalKeyboardKey.altLeft}, TargetPlatform.macOS), 1);
});
test('Cmd+] and Cmd+[ only on Apple platforms', () {
expect(
_step(_right, {LogicalKeyboardKey.metaLeft}, TargetPlatform.macOS),
1,
);
expect(_step(_left, {LogicalKeyboardKey.metaLeft}, TargetPlatform.iOS), -1);
expect(_step(_right, {LogicalKeyboardKey.metaLeft}), isNull);
expect(
_step(_right, {LogicalKeyboardKey.metaLeft}, TargetPlatform.windows),
isNull,
);
});
test('plain brackets type; Shift, Ctrl, AltGr and key-up do not match', () {
expect(_step(_right, {}), isNull);
for (final extra in [
LogicalKeyboardKey.shiftLeft,
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.metaLeft,
LogicalKeyboardKey.altGraph,
]) {
expect(
_step(_right, {LogicalKeyboardKey.altLeft, extra}),
isNull,
reason: '$extra',
);
}
expect(
_step(
const KeyUpEvent(
physicalKey: PhysicalKeyboardKey.bracketRight,
logicalKey: LogicalKeyboardKey.bracketRight,
timeStamp: Duration.zero,
),
{LogicalKeyboardKey.altLeft},
),
isNull,
);
// A key typing "[" elsewhere on the keyboard is not the chord.
expect(
_step(_down(PhysicalKeyboardKey.digit8, LogicalKeyboardKey.bracketLeft), {
LogicalKeyboardKey.altLeft,
}),
isNull,
);
});
test('labels name the chords this platform answers', () {
expect(chatPaneCycleShortcutLabel(TargetPlatform.linux), 'Alt+], Alt+[');
expect(chatPaneCycleShortcutLabel(TargetPlatform.windows), 'Alt+], Alt+[');
expect(
chatPaneCycleShortcutLabel(TargetPlatform.macOS),
'Option+], Option+[, Cmd+], Cmd+[',
);
});
test('targets wrap both ways; one entry or none has no target', () {
const order = ['a', 'b', 'c'];
expect(chatPaneCycleTarget(order, 0, 1), 'b');
expect(chatPaneCycleTarget(order, 2, 1), 'a');
expect(chatPaneCycleTarget(order, 0, -1), 'c');
expect(chatPaneCycleTarget(order, 1, -1), 'a');
expect(chatPaneCycleTarget(order, -1, 1), 'a');
expect(chatPaneCycleTarget(order, -1, -1), 'c');
expect(chatPaneCycleTarget(['a'], 0, 1), isNull);
expect(chatPaneCycleTarget(<String>[], -1, 1), isNull);
});
}
class _FakeKeyboard extends HardwareKeyboard {
_FakeKeyboard(this.pressed);
final Set<LogicalKeyboardKey> pressed;
@override
bool isLogicalKeyPressed(LogicalKeyboardKey key) => pressed.contains(key);
}
@@ -0,0 +1,84 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/graph/domain/stage_run_facts.dart';
import 'package:pipelines_app/features/graph/domain/stage_summary.dart';
void main() {
test('a model stage with no tools block runs the default tools', () {
final summary = stageSummaryFor({
'stages': [
{'key': 'a', 'prompt': 'Do it', 'edges': {}},
],
}, 'a')!;
expect(summary.kind, StageKind.model);
expect(summary.tools, defaultStageTools);
expect(summary.toolsDefault, isTrue);
expect(summary.prompt, 'Do it');
});
test('a delivery check reads as the delivery gate with its commands', () {
final summary = stageSummaryFor({
'stages': [
{
'key': 'land',
'type': 'check',
'configs': {'delivery': 'true', 'command_timeout': '10m'},
'blocks': {'commands': 'make test\n\nmake lint'},
'edges': {'pass': '#success'},
},
],
}, 'land')!;
expect(summary.typeLabel, 'Delivery gate');
expect(summary.commands, ['make test', 'make lint']);
expect(summary.tools, isEmpty);
expect(summary.prompt, isNull);
expect(summary.meta, ['10m timeout']);
expect(summary.routes.single, (outcome: 'pass', target: 'Success'));
});
test('an undeclared stage has no summary; a terminal lists routes in', () {
final graph = {
'stages': [
{
'key': 'a',
'edges': {'success': '#success'},
},
],
};
expect(stageSummaryFor(graph, 'missing'), isNull);
final end = stageSummaryFor(graph, '#success')!;
expect(end.kind, StageKind.terminal);
expect(end.routes.single, (outcome: 'success', target: 'a'));
});
test('short model names drop the vendor and date', () {
expect(
shortModelName('anthropic/claude-opus-4-1-20250805'),
'claude-opus-4-1',
);
expect(shortModelName('gpt-5'), 'gpt-5');
});
test('an unvisited stage has no run facts', () {
final facts = stageRunFacts({'steps': []}, 'a');
expect(facts.visits, 0);
expect(facts.status, isNull);
});
test('a failure reason is read only from a failed latest visit', () {
final facts = stageRunFacts({
'steps': [
{'sequence': 1, 'stage': 'a', 'status': 'failed', 'diagnostic': 'boom'},
{
'sequence': 2,
'stage': 'a',
'status': 'completed',
'diagnostic': 'old',
},
],
}, 'a');
expect(facts.visits, 2);
expect(facts.status, 'completed');
expect(facts.failure, isNull);
});
}
@@ -96,8 +96,13 @@ void main() {
// A tap in the larger canvas follows the same transform and updates the
// presentation's own selection.
// The tap opens the stage's popover; its "Open definition" reports it.
await tester.tap(_inExpanded(_node('plan')));
await tester.pump();
expect(picked, isEmpty);
expect(find.byKey(const Key('graph-stage-popover')), findsOneWidget);
await tester.tap(find.byKey(const Key('stage-popover-open-definition')));
await tester.pump();
expect(picked, ['plan']);
expect(
tester.widget<GraphStageNode>(_inExpanded(_node('plan'))).selected,
@@ -98,6 +98,14 @@ Future<void> _tapNode(WidgetTester tester, String key) async {
await tester.pump();
}
/// Taps a node, then its popover's "Open definition", which reports the key.
Future<void> _openDefinition(WidgetTester tester, String key) async {
await _tapNode(tester, key);
expect(find.byKey(const Key('graph-stage-popover')), findsOneWidget);
await tester.tap(find.byKey(const Key('stage-popover-open-definition')));
await tester.pump();
}
void _expectNoOverlaps(WidgetTester tester) {
final rects = <Rect>[
for (final element in find.byType(GraphStageNode).evaluate())
@@ -148,11 +156,10 @@ void main() {
expect(tester.widget<GraphStageNode>(_node('build')).selected, isTrue);
expect(tester.widget<GraphStageNode>(_node('plan')).selected, isFalse);
await tester.tap(_node('plan'));
await tester.pump();
await _openDefinition(tester, 'plan');
expect(picked, ['plan']);
await _tapNode(tester, '#success');
await _openDefinition(tester, '#success');
expect(picked, ['plan', '#success']);
});
@@ -189,7 +196,10 @@ void main() {
);
await tester.tapAt(build.center);
await tester.pump();
expect(picked, ['build']);
expect(
tester.widget<Text>(find.byKey(const Key('stage-popover-title'))).data,
'build',
);
});
testWidgets('nodes use measured native sizes and never overlap', (
@@ -0,0 +1,369 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/graph/widgets/definition_graph_view.dart';
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart';
import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart';
import 'package:pipelines_app/features/graph/widgets/stage_popover_position.dart';
/// One stage of every type, with the fields the popover shows.
JsonMap _graph() => <String, dynamic>{
'stages': <dynamic>[
<String, dynamic>{
'key': 'implement',
'type': 'model',
'prompt': 'Implement the feature.\n\nKeep the change small.',
'configs': <String, dynamic>{
'harness': 'claude',
'model': 'anthropic/claude-sonnet-4-5-20250929',
'reasoning_effort': 'high',
'timeout': '30m',
'retries': '2',
'budget_usd': '5',
},
'blocks': <String, dynamic>{
'tools': 'read\nglob\nedit\nshell\nmcp:pipelines',
'permissions': '{"edit": ["app/**"], "shell": ["flutter test"]}',
},
'limits': <String, dynamic>{
'max_visits': 3,
'on': ['fail'],
'on_exhausted': 'decide',
},
'edges': <String, dynamic>{'success': 'verify', 'error': '#failure'},
},
<String, dynamic>{
'key': 'verify',
'type': 'check',
'blocks': <String, dynamic>{'commands': 'flutter analyze\nflutter test'},
'edges': <String, dynamic>{
'pass': 'triage',
'fail': 'implement',
'error': '#failure',
},
},
<String, dynamic>{
'key': 'triage',
'type': 'findings',
'configs': <String, dynamic>{'severity': 'critical', 'origin': 'any'},
'edges': <String, dynamic>{'open': 'approve', 'clear': '#success'},
},
<String, dynamic>{
'key': 'approve',
'type': 'human',
'prompt': 'Check the screenshots before landing.',
'edges': <String, dynamic>{'accept': '#success', 'reject': 'implement'},
},
],
};
JsonMap _run() => <String, dynamic>{
'id': 7,
'pipeline_id': 3,
'name': 'feature',
'version': 4,
'steps': <dynamic>[
<String, dynamic>{
'sequence': 1,
'stage': 'implement',
'status': 'completed',
'outcome': 'success',
'target': 'verify',
'started_at': '2026-10-21T10:00:00Z',
'finished_at': '2026-10-21T10:01:00Z',
},
<String, dynamic>{
'sequence': 2,
'stage': 'verify',
'status': 'failed',
'outcome': 'fail',
'target': 'implement',
'diagnostic': 'flutter test: 2 failures',
},
<String, dynamic>{
'sequence': 3,
'stage': 'implement',
'status': 'completed',
'outcome': 'success',
'target': 'verify',
'started_at': '2026-10-21T10:02:00Z',
'finished_at': '2026-10-21T10:04:05Z',
'output': '# Fixed the two failing tests\nmore detail',
'verdict': <String, dynamic>{'option': 'success', 'reason': 'All green'},
},
],
'current_stage': '',
'executing': false,
};
Widget _host(Widget child, {Size size = const Size(1000, 760)}) => MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: SizedBox(width: size.width, height: size.height, child: child),
),
),
);
Future<void> _settle(WidgetTester tester) async {
await tester.pump();
await tester.pump();
await tester.pump();
}
Finder _node(String key) => find.byWidgetPredicate(
(widget) => widget is GraphStageNode && widget.node.key == key,
);
final Finder _popover = find.byKey(const Key('graph-stage-popover'));
String _title(WidgetTester tester) =>
tester.widget<Text>(find.byKey(const Key('stage-popover-title'))).data!;
Future<void> _view(
WidgetTester tester, {
ValueChanged<String>? onSelected,
Size size = const Size(1000, 760),
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
_host(
DefinitionGraphView(graph: _graph(), onSelected: onSelected ?? (_) {}),
size: size,
),
);
await _settle(tester);
}
void main() {
testWidgets('a model stage shows its type, configs, tools and prompt', (
tester,
) async {
await _view(tester);
expect(_popover, findsNothing);
await tester.tap(_node('implement'));
await tester.pump();
expect(_popover, findsOneWidget);
expect(_title(tester), 'implement');
expect(find.text('Model'), findsOneWidget);
for (final chip in [
'claude',
'claude-sonnet-4-5',
'high effort',
'30m timeout',
'2 retries',
r'$5 budget',
'mcp:pipelines',
'max 3 visits',
'on fail',
'when exhausted: decide',
]) {
expect(find.text(chip), findsOneWidget, reason: chip);
}
for (final route in ['success to verify', 'error to Failure']) {
expect(find.bySemanticsLabel(route), findsOneWidget, reason: route);
}
expect(find.textContaining('Implement the feature.'), findsOneWidget);
// The permission allow-lists stay behind a collapsed line.
expect(
find.byKey(const Key('stage-popover-permission-lines')),
findsNothing,
);
await tester.tap(find.byKey(const Key('stage-popover-permissions')));
await tester.pump();
expect(
tester
.widget<Text>(find.byKey(const Key('stage-popover-permission-lines')))
.data,
'edit: app/**\nshell: flutter test',
);
// The node is the open selection while its popover shows.
expect(tester.widget<GraphStageNode>(_node('implement')).selected, isTrue);
});
testWidgets('a check stage lists its commands instead of a prompt', (
tester,
) async {
await _view(tester);
await tester.tap(_node('verify'));
await tester.pump();
expect(find.text('Check'), findsWidgets);
expect(find.byKey(const Key('stage-popover-commands')), findsOneWidget);
expect(find.byKey(const Key('stage-popover-prompt')), findsNothing);
final commands = tester.widget<SelectableText>(
find.byKey(const Key('stage-popover-commands')),
);
expect(commands.textSpan!.toPlainText(), contains('flutter analyze'));
expect(find.bySemanticsLabel('fail to implement'), findsOneWidget);
});
testWidgets('a findings gate shows severity and origin', (tester) async {
await _view(tester);
await tester.tap(_node('triage'));
await tester.pump();
expect(find.text('Findings gate'), findsOneWidget);
expect(find.text('min severity critical'), findsOneWidget);
expect(find.text('origin any'), findsOneWidget);
});
testWidgets('a human stage shows the operator instructions', (tester) async {
await _view(tester);
await tester.tap(_node('approve'));
await tester.pump();
expect(find.text('Human'), findsOneWidget);
expect(find.text('Operator instructions'), findsOneWidget);
expect(
find.textContaining('Check the screenshots before landing.'),
findsOneWidget,
);
});
testWidgets('the card sits inside the viewport with its nub on the node', (
tester,
) async {
await _view(tester);
await tester.tap(_node('verify'));
await tester.pump();
final card = tester.getRect(find.byKey(const Key('stage-popover-body')));
final viewport = tester.getRect(find.byType(InteractiveViewer));
expect(viewport.inflate(1).contains(card.topLeft), isTrue);
expect(viewport.inflate(1).contains(card.bottomRight), isTrue);
final position = tester.renderObject<RenderStagePopoverPosition>(_popover);
expect(position.side, isNot(StagePopoverSide.over));
});
testWidgets('an outside tap, Escape and the same node close it', (
tester,
) async {
await _view(tester);
await tester.tap(_node('implement'));
await tester.pump();
expect(_popover, findsOneWidget);
// Tapping inside the card keeps it open.
await tester.tap(find.byKey(const Key('stage-popover-title')));
await tester.pump();
expect(_popover, findsOneWidget);
// An outside tap on the empty canvas closes it.
final viewport = tester.getRect(find.byType(InteractiveViewer));
await tester.tapAt(viewport.bottomRight - const Offset(10, 10));
await tester.pump();
expect(_popover, findsNothing);
// A drag pans the graph but keeps the card on its node.
await tester.tap(_node('implement'));
await tester.pump();
await tester.dragFrom(
viewport.bottomRight - const Offset(40, 40),
const Offset(-60, -20),
);
await tester.pump();
expect(_popover, findsOneWidget);
// Escape closes it.
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pump();
expect(_popover, findsNothing);
// Tapping the same node again toggles it shut.
await tester.tap(_node('implement'));
await tester.pump();
expect(_popover, findsOneWidget);
await tester.tap(_node('implement'));
await tester.pump();
expect(_popover, findsNothing);
// Another node replaces it.
await tester.tap(_node('triage'));
await tester.pump();
expect(_title(tester), 'triage');
await tester.tap(_node('implement'));
await tester.pump();
expect(_title(tester), 'implement');
});
testWidgets('Open definition reports the stage and closes the card', (
tester,
) async {
final opened = <String>[];
await _view(tester, onSelected: opened.add);
await tester.tap(_node('approve'));
await tester.pump();
await tester.tap(find.byKey(const Key('stage-popover-open-definition')));
await tester.pump();
expect(opened, ['approve']);
expect(_popover, findsNothing);
});
testWidgets('a focused node opens with Enter', (tester) async {
await _view(tester);
// The node's own focus: the nearest focus above its label.
final label = find
.descendant(of: _node('triage'), matching: find.byType(Text))
.first;
Focus.of(tester.element(label)).requestFocus();
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
expect(_popover, findsOneWidget);
expect(_title(tester), 'triage');
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pump();
expect(_popover, findsNothing);
});
testWidgets('a phone-width graph opens the stage in a bottom sheet', (
tester,
) async {
await _view(tester, size: const Size(390, 760));
await tester.tap(_node('implement'));
await tester.pumpAndSettle();
expect(_popover, findsNothing);
expect(find.byKey(const Key('graph-stage-sheet')), findsOneWidget);
expect(_title(tester), 'implement');
expect(find.text('claude-sonnet-4-5'), findsOneWidget);
});
testWidgets('the run variant shows status, visits, verdict and failure', (
tester,
) async {
tester.view.physicalSize = const Size(1000, 760);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final visits = <String>[];
await tester.pumpWidget(
_host(
RunGraphView(graph: _graph(), run: _run(), onStageSelected: visits.add),
),
);
await _settle(tester);
await tester.tap(_node('implement'));
await tester.pump();
expect(find.text('completed'), findsWidgets);
expect(find.text('×2'), findsOneWidget);
expect(find.text('2m 5s'), findsOneWidget);
expect(find.text('success: All green'), findsOneWidget);
expect(find.text('Fixed the two failing tests'), findsOneWidget);
await tester.tap(find.byKey(const Key('stage-popover-open-visit')));
await tester.pump();
expect(visits, ['implement']);
await tester.tap(_node('verify'));
await tester.pump();
expect(find.text('×1'), findsOneWidget);
expect(find.text('flutter test: 2 failures'), findsOneWidget);
// Open definition pushes the pinned stage definition page.
await tester.tap(find.byKey(const Key('stage-popover-open-definition')));
await tester.pumpAndSettle();
expect(find.text('verify definition'), findsOneWidget);
});
}
@@ -260,7 +260,7 @@ void main() {
});
testWidgets(
'a visited stage reports its key and an unvisited node does not',
'a visited stage opens its visit from the popover; an unvisited one has none',
(tester) async {
final picked = <String>[];
await tester.pumpWidget(
@@ -278,28 +278,26 @@ void main() {
final visited = tester.getSemantics(_node('plan')).getSemanticsData();
expect(visited.flagsCollection.isButton, isTrue);
expect(visited.hasAction(SemanticsAction.tap), isTrue);
// An unvisited stage still opens its declaration, with no status.
final unvisited = tester.getSemantics(_node('build')).getSemanticsData();
expect(unvisited.flagsCollection.isButton, isFalse);
expect(unvisited.hasAction(SemanticsAction.tap), isFalse);
expect(unvisited.flagsCollection.isButton, isTrue);
expect(unvisited.label, 'build');
await tester.tap(_node('plan'));
await tester.pump();
expect(picked, isEmpty);
await tester.tap(find.byKey(const Key('stage-popover-open-visit')));
await tester.pump();
expect(picked, ['plan']);
// `build` was never recorded in this run: it is a plain label, not a
// button, and tapping it reports nothing (never a fabricated visit).
await tester.tap(_node('build'), warnIfMissed: false);
// `build` was never recorded in this run: its popover offers no visit,
// so nothing is ever fabricated.
await tester.tap(_node('build'));
await tester.pump();
expect(find.byKey(const Key('graph-stage-popover')), findsOneWidget);
expect(find.byKey(const Key('stage-popover-open-visit')), findsNothing);
expect(find.byKey(const Key('stage-popover-status')), findsNothing);
expect(picked, ['plan']);
expect(
find.ancestor(
of: _node('build'),
matching: find.byWidgetPredicate(
(widget) => widget is IgnorePointer && widget.ignoring,
),
),
findsOneWidget,
);
handle.dispose();
},
);
@@ -30,6 +30,10 @@ Future<void> _tapNode(WidgetTester tester, Finder node) async {
await tester.pumpAndSettle();
}
await tester.tap(node);
await tester.pump(); // A tap opens the stage's popover (or sheet); "Open definition" opens the
// pinned definition page, as a tap did before the popover.
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('stage-popover-open-definition')));
await tester.pump();
}
@@ -25,6 +25,10 @@ Future<void> _tapNode(WidgetTester tester, String key) async {
await tester.pumpAndSettle();
}
await tester.tap(_node(key));
await tester.pump(); // A tap opens the stage's popover (or sheet); "Open definition" opens the
// pinned definition page, as a tap did before the popover.
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('stage-popover-open-definition')));
await tester.pump();
}
@@ -182,7 +182,7 @@ void main() {
) async {
await pumpDeepLink(tester, RunDetailTestPlatform.material);
await openRunDetailTab(tester, RunDetailTab.graph);
await tapGraphNode(tester, 'plan');
await openGraphVisit(tester, 'plan');
await tester.pumpAndSettle();
// The web client's graph click takes the last visit in sequence order, not
@@ -156,3 +156,11 @@ Future<void> tapGraphNode(WidgetTester tester, String key) async {
await tester.pump();
await tester.pump();
}
/// Opens [key]'s stage popover (or sheet), then its "Open visit".
Future<void> openGraphVisit(WidgetTester tester, String key) async {
await tapGraphNode(tester, key);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('stage-popover-open-visit')));
await tester.pump();
}
@@ -46,7 +46,7 @@ void main() {
) async {
await pumpRunDetail(tester, platform);
await openRunDetailTab(tester, RunDetailTab.graph);
await tapGraphNode(tester, 'plan');
await openGraphVisit(tester, 'plan');
await tester.pumpAndSettle();
// The Graph reports the stage; the exact recorded visit opens as its
@@ -76,9 +76,11 @@ void main() {
) async {
await pumpRunDetail(tester, platform);
await openRunDetailTab(tester, RunDetailTab.graph);
// `audit` was never recorded: its node is not a control and a click must
// leave the detail on the Graph tab.
// `audit` was never recorded: its popover shows the declaration but
// offers no visit, and the detail stays on the Graph tab.
await tapGraphNode(tester, 'audit');
await tester.pumpAndSettle();
expect(find.byKey(const Key('stage-popover-open-visit')), findsNothing);
expect(find.byType(RunGraphView), findsOneWidget);
expect(
find.byKey(const Key('run-detail-tab-body-timeline')),
@@ -96,7 +98,7 @@ void main() {
scale: 2,
);
await openRunDetailTab(tester, RunDetailTab.graph);
await tapGraphNode(tester, 'plan');
await openGraphVisit(tester, 'plan');
await tester.pumpAndSettle();
// Leaving the visit page lands on Timeline. At 320/2x the strip
@@ -24,8 +24,13 @@ void main() {
});
test('scattered letters in a long note do not match', () {
// `float` occurs only as scattered letters in other entries' notes.
expect(actions('float'), everyElement(contains('floating')));
// `float` occurs as scattered letters in many entries' notes; only the
// entries that say "floating" match.
final found = [
for (final match in filterShortcuts(registry.entries, 'float'))
'${match.entry.action} ${match.entry.caveat ?? ''}',
];
expect(found, everyElement(contains('floating')));
});
test('keys are searchable with or without the plus', () {
@@ -32,19 +32,20 @@ void main() {
),
);
expect(find.text(SettingsChatNavigationSection.title), findsOneWidget);
expect(controller.value, MobileChatNavigation.quickSwitch);
// Without a stored choice: the Chat stack.
expect(controller.value, MobileChatNavigation.chatStack);
expect(
find.text(MobileChatNavigation.quickSwitch.description),
find.text(MobileChatNavigation.chatStack.description),
findsOneWidget,
);
await tester.tap(
find.byKey(const ValueKey('settings-chat-navigation-chatStack')),
find.byKey(const ValueKey('settings-chat-navigation-quickSwitch')),
);
await tester.pumpAndSettle();
expect(controller.value, MobileChatNavigation.chatStack);
expect(store.saved, 'chatStack');
expect(controller.value, MobileChatNavigation.quickSwitch);
expect(store.saved, 'quickSwitch');
expect(
find.text(MobileChatNavigation.chatStack.description),
find.text(MobileChatNavigation.quickSwitch.description),
findsOneWidget,
);
@@ -52,11 +53,11 @@ void main() {
final next = MobileChatNavigationController(store: store);
addTearDown(next.dispose);
await next.restore();
expect(next.value, MobileChatNavigation.chatStack);
expect(next.value, MobileChatNavigation.quickSwitch);
store.success = false;
await tester.tap(
find.byKey(const ValueKey('settings-chat-navigation-quickSwitch')),
find.byKey(const ValueKey('settings-chat-navigation-chatStack')),
);
await tester.pumpAndSettle();
expect(find.text('Could not save; applies until reload.'), findsOneWidget);
@@ -117,4 +117,40 @@ void main() {
await next.restore();
expect(next.design, AppDesign.paper);
});
testWidgets('choosing Compact stores it, densifies the page live, draws '
'a denser swatch and is restored on the next launch', (tester) async {
final store = MemoryAppDesignStore();
final designs = AppDesignController(store: store);
await _pump(tester, designs);
final swatch = tester.widget<DesignSwatchPreview>(
find.descendant(
of: find.byKey(settingsDesignKey(AppDesign.compact)),
matching: find.byType(DesignSwatchPreview),
),
);
expect(swatch.lines, greaterThan(2));
expect(find.text(AppDesign.compact.description), findsOneWidget);
final before = tester.getSize(
find.byKey(settingsDesignKey(AppDesign.paper)),
);
await tester.tap(find.text(AppDesign.compact.label));
await tester.pumpAndSettle();
expect(store.id, 'compact');
expect(designs.design, AppDesign.compact);
final tokens = _tokens(tester);
expect(tokens.density.dense, isTrue);
expect(tokens.transcript, TranscriptStyle.bubbles);
// The rows themselves tighten at once.
final after = tester.getSize(
find.byKey(settingsDesignKey(AppDesign.paper)),
);
expect(after.height, lessThan(before.height));
final next = AppDesignController(store: MemoryAppDesignStore(store.id));
await next.restore();
expect(next.design, AppDesign.compact);
});
}
@@ -27,7 +27,7 @@ bool _switchValue(WidgetTester tester) {
}
void main() {
testWidgets('shows the switch, status and ntfy note', (tester) async {
testWidgets('shows the switch, status and delivery note', (tester) async {
final service = FakeNotificationService();
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
@@ -4,7 +4,7 @@ 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_ntfy_section.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 {
@@ -32,24 +32,31 @@ JsonMap _reply(bool run, bool needs, bool reply) => {
},
};
Widget _host(ApiGateway gateway) {
Widget _host(ApiGateway gateway, {bool connected = true}) {
final body = SingleChildScrollView(
child: SettingsNtfySection(gateway: gateway, connected: true),
child: SettingsNotificationSettingsSection(
gateway: gateway,
connected: connected,
),
);
return MaterialApp(home: Scaffold(body: body));
}
bool _checked(WidgetTester tester, String key) {
final tile = find.byKey(ntfySettingKey(key));
return tester.widget<CheckboxListTile>(tile).value!;
}
Finder _tile(String key) => find.byKey(notificationSettingKey(key));
bool _checked(WidgetTester tester, String key) =>
tester.widget<CheckboxListTile>(_tile(key)).value!;
void main() {
testWidgets('loads the stored values', (tester) async {
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'),
@@ -57,14 +64,13 @@ void main() {
);
expect(find.text('Chat needs your answer or approval'), findsOneWidget);
expect(find.text('Chat reply finished'), findsOneWidget);
expect(find.text(ntfySectionSubtitle), 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 {
// The server's defaults: run ends notify only for "Notify me" runs.
final gateway = _Gateway((_, _) => _reply(false, true, false));
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
@@ -73,24 +79,53 @@ void main() {
expect(_checked(tester, 'chat_reply_finished'), isFalse);
});
testWidgets('toggling writes only that setting', (tester) async {
final gateway = _Gateway((type, fields) {
if (type == 'set_notification_settings') {
return _reply(true, true, true);
}
return _reply(true, true, false);
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();
await tester.tap(find.byKey(ntfySettingKey('chat_reply_finished')));
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, hasLength(2));
expect(gateway.calls.last.$1, 'set_notification_settings');
expect(gateway.calls.last.$2, {
'notification_settings': {'chat_reply_finished': true},
});
expect(_checked(tester, 'chat_reply_finished'), isTrue);
expect(find.byKey(ntfyErrorKey), findsNothing);
expect(find.byType(CheckboxListTile), findsNWidgets(3));
});
testWidgets('failure reverts and shows the refusal', (tester) async {
@@ -101,53 +136,50 @@ void main() {
});
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
await tester.tap(find.byKey(ntfySettingKey('run_finished')));
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(find.byKey(ntfySettingKey('chat_needs_you')));
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,
);
expect(find.text('Could not save: settings are read-only'), findsOneWidget);
});
testWidgets('disabled while loading and offline', (tester) async {
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(find.byKey(ntfySettingKey('run_finished')));
await tester.tap(_tile('run_finished'));
await tester.pump();
expect(gateway.calls, hasLength(1));
expect(
tester
.widget<CheckboxListTile>(find.byKey(ntfySettingKey('run_finished')))
.onChanged,
tester.widget<CheckboxListTile>(_tile('run_finished')).onChanged,
isNull,
);
pending.complete(_reply(true, true, false));
await tester.pumpAndSettle();
expect(find.text('Loading…'), findsNothing);
});
final offline = _Gateway((_, _) => _reply(true, true, false));
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SettingsNtfySection(gateway: offline, connected: false),
),
),
);
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(offline.calls, isEmpty);
expect(find.text(ntfyOfflineText), findsOneWidget);
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 {
@@ -165,47 +197,7 @@ void main() {
fail = false;
await tester.tap(find.text('Retry'));
await tester.pumpAndSettle();
expect(find.byKey(ntfyErrorKey), findsNothing);
expect(
tester
.widget<CheckboxListTile>(find.byKey(ntfySettingKey('run_finished')))
.value,
isFalse,
);
});
group('ntfy_enabled', () {
JsonMap withNtfy(bool ntfy) => {
'type': 'notification_settings',
'notification_settings': {
...(_reply(true, true, false)['notification_settings'] as Map),
'ntfy_enabled': ntfy,
},
};
testWidgets('hidden when the server does not send it', (tester) async {
final gateway = _Gateway((_, _) => _reply(true, true, false));
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(find.byKey(ntfySettingKey('ntfy_enabled')), findsNothing);
expect(find.text(ntfySectionSubtitle), findsOneWidget);
});
testWidgets('shows and writes it', (tester) async {
final gateway = _Gateway(
(type, _) => withNtfy(type == 'set_notification_settings'),
);
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(find.text('Also send to ntfy'), findsOneWidget);
expect(find.text(ntfySectionAppSubtitle), findsOneWidget);
expect(_checked(tester, 'ntfy_enabled'), isFalse);
await tester.tap(find.byKey(ntfySettingKey('ntfy_enabled')));
await tester.pumpAndSettle();
expect(gateway.calls.last.$2, {
'notification_settings': {'ntfy_enabled': true},
});
expect(_checked(tester, 'ntfy_enabled'), isTrue);
});
expect(find.byKey(notificationSettingsErrorKey), findsNothing);
expect(_checked(tester, 'run_finished'), isFalse);
});
}
@@ -164,8 +164,8 @@ void main() {
'ping',
'notification_settings',
]);
await openSettingsSection(tester, 'Phone notifications');
_answerNtfySettings(factory.last);
await openSettingsSection(tester, 'Notification events');
_answerNotificationSettings(factory.last);
await tester.pump();
await tester.pump();
expect(factory.last.decodedOutgoing, hasLength(2));
@@ -203,8 +203,8 @@ void main() {
expect(find.text(serverDetailsPending), findsNothing);
expect(find.text('Server build unavailable'), findsOneWidget);
expect(find.text('Server time unavailable'), findsOneWidget);
await openSettingsSection(tester, 'Phone notifications');
_answerNtfySettings(factory.last);
await openSettingsSection(tester, 'Notification events');
_answerNotificationSettings(factory.last);
await tester.pump();
});
@@ -521,8 +521,8 @@ Future<void> _pump(
await openSettingsSection(tester, 'Connection');
}
/// Answers the Settings screen's queued ntfy-settings load on [channel].
void _answerNtfySettings(FakeChannel channel) {
/// Answers the Settings screen's queued notification-settings load on [channel].
void _answerNotificationSettings(FakeChannel channel) {
final request = channel.decodedOutgoing.last;
expect(request['type'], 'notification_settings');
channel.reply(<String, dynamic>{
@@ -48,7 +48,7 @@ void main() {
..._filler(6),
SettingsSection(
id: 'server',
title: 'Phone notifications',
title: 'Notification events',
lazy: true,
builder: (_) => ServerSettingsView<int>(
load: load,
@@ -60,11 +60,11 @@ void main() {
// The local sections are built and the server section is only a skeleton:
// no request runs until the list reaches it.
expect(find.text('filler body'), findsWidgets);
expect(find.text('Phone notifications'), findsOneWidget);
expect(find.text('Notification events'), findsOneWidget);
expect(fetches, 0);
expect(tester.takeException(), isNull);
await tester.ensureVisible(find.text('Phone notifications'));
await tester.ensureVisible(find.text('Notification events'));
await tester.pump();
await tester.pump();
expect(fetches, 1);
@@ -131,8 +131,8 @@ void main() {
..._filler(6),
SettingsSection(
id: 'server',
title: 'Phone notifications',
keywords: 'ntfy push',
title: 'Notification events',
keywords: 'push devices',
lazy: true,
builder: (_) => ServerSettingsView<int>(
load: load,
@@ -144,7 +144,7 @@ void main() {
await tester.enterText(
find.byKey(const ValueKey('settings.search')),
'ntfy',
'devices',
);
await tester.pump();
await tester.pump();