Merge main
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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,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);
|
||||
}
|
||||
@@ -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', () {
|
||||
|
||||
Reference in New Issue
Block a user