Merge branch 'worktree-agent-a027d4a4581416c93'
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app_session.dart';
|
||||
@@ -29,6 +30,12 @@ Widget host(AppSession session, {String? initialSessionId}) => MaterialApp(
|
||||
);
|
||||
|
||||
void main() {
|
||||
// These describe the Quick switch layout (the peek of the next chat).
|
||||
setUp(
|
||||
() => MobileChatNavigationController.instance.debugUse(
|
||||
MobileChatNavigation.quickSwitch,
|
||||
),
|
||||
);
|
||||
testWidgets('nothing is requested before the shared socket is ready', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -296,6 +297,12 @@ Future<void> replyChatHistory(
|
||||
}
|
||||
|
||||
void main() {
|
||||
// These describe the Quick switch layout (the peek of the next chat).
|
||||
setUp(
|
||||
() => MobileChatNavigationController.instance.debugUse(
|
||||
MobileChatNavigation.quickSwitch,
|
||||
),
|
||||
);
|
||||
testWidgets(
|
||||
'a wide /chat/s1 deep link shows that thread beside the list and route Back returns to /chat',
|
||||
(tester) async {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user