Merge branch 'worktree-agent-acbb1fb1d035904b7'
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_app.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_chat.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_route.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_window_body.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_bar_tint.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_header.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import '../chat_registration_test.dart' show webServer;
|
||||
import 'detached_fixtures.dart';
|
||||
|
||||
Future<void> _run(WidgetTester tester, ChatServer server, Duration d) async {
|
||||
for (var t = 0; t < d.inMilliseconds; t += 16) {
|
||||
server.answer();
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
}
|
||||
server.answer();
|
||||
}
|
||||
|
||||
ChatThreadHeader _header(WidgetTester tester) => tester
|
||||
.widget<ChatThreadHeader>(find.byKey(const Key('chat-thread-header')));
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
});
|
||||
|
||||
void sized(WidgetTester tester) {
|
||||
tester.view.physicalSize = const Size(1200, 860);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
addTearDown(() => TerminalLayout.instance.persist = true);
|
||||
}
|
||||
|
||||
testWidgets('a chat opened before its machine connects is read again on '
|
||||
'connect: the header names it and wears its colour', (tester) async {
|
||||
sized(tester);
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final server = ChatServer(channel)
|
||||
..listsChats = false
|
||||
..colors['a'] = 'teal';
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
await client.connect(Uri.parse('ws://fixture/connect'));
|
||||
final ready = ValueNotifier(true);
|
||||
final sync = ValueNotifier(0);
|
||||
final titles = <String>[];
|
||||
addTearDown(ready.dispose);
|
||||
addTearDown(sync.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: DetachedChat(
|
||||
sessionId: 'a',
|
||||
gateway: client,
|
||||
window: DetachedWindowControls(
|
||||
ready: ready,
|
||||
sync: sync,
|
||||
setTitle: titles.add,
|
||||
close: () {},
|
||||
bringBackItem: (_, _, _, _) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await _run(tester, server, const Duration(milliseconds: 600));
|
||||
// The first list found no machine: no row, so no name and no colour.
|
||||
expect(_header(tester).title, isEmpty);
|
||||
expect(_header(tester).chatColor, isNull);
|
||||
expect(titles.last, 'a');
|
||||
|
||||
// The machine connects: the pool's revision (the window's sync) moves.
|
||||
server.listsChats = true;
|
||||
sync.value = 1;
|
||||
await _run(tester, server, const Duration(milliseconds: 600));
|
||||
expect(_header(tester).title, 'Chat a');
|
||||
expect(_header(tester).folder, 'demo');
|
||||
expect(_header(tester).chatColor, 'teal');
|
||||
expect(find.byKey(const Key('chat-bar-tint')), findsOneWidget);
|
||||
expect(titles.last, 'Chat a');
|
||||
|
||||
// A rename and a new colour from the main window (or another device)
|
||||
// arrive live.
|
||||
channel.incoming.add(
|
||||
jsonEncode({
|
||||
'type': 'chat_session_changed',
|
||||
'chat_session': {'id': 'a', 'title': 'Renamed', 'color': 'blue'},
|
||||
}),
|
||||
);
|
||||
await _run(tester, server, const Duration(milliseconds: 300));
|
||||
expect(_header(tester).chatColor, 'blue');
|
||||
expect(_header(tester).title, 'Renamed');
|
||||
expect(titles.last, 'Renamed');
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
client.dispose();
|
||||
});
|
||||
|
||||
testWidgets('the detached window uses the main window\'s design and the '
|
||||
'chat\'s colour', (tester) async {
|
||||
sized(tester);
|
||||
final designs = AppDesignController.instance;
|
||||
final before = designs.design;
|
||||
await designs.select(AppDesign.terminal);
|
||||
addTearDown(() => designs.select(before));
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final server = ChatServer(channel)..colors['a'] = 'amber';
|
||||
await tester.pumpWidget(
|
||||
DetachedWindowApp(
|
||||
route: DetachedRoute.chat('a')!,
|
||||
server: webServer(),
|
||||
client: PipelinesClient(channelFactory: (_) => channel),
|
||||
platform: FakeDetachedPlatform(),
|
||||
),
|
||||
);
|
||||
await _run(tester, server, const Duration(milliseconds: 900));
|
||||
final app = tester.widget<MaterialApp>(find.byType(MaterialApp));
|
||||
final terminal = AppDesign.terminal.light();
|
||||
expect(app.theme!.colorScheme, terminal.colorScheme);
|
||||
expect(
|
||||
app.theme!.textTheme.bodyMedium?.fontFamily,
|
||||
terminal.textTheme.bodyMedium?.fontFamily,
|
||||
);
|
||||
expect(app.title, 'Chat a · Pipelines');
|
||||
final header = _header(tester);
|
||||
expect(header.title, 'Chat a');
|
||||
expect(header.chatColor, 'amber');
|
||||
final context = tester.element(find.byKey(const Key('chat-thread-header')));
|
||||
final tint = tester
|
||||
.widget<ChatBarTintScope>(find.byKey(const Key('chat-bar-tint')))
|
||||
.tint;
|
||||
expect(tint, chatBarTintOf(context, 'amber'));
|
||||
});
|
||||
}
|
||||
@@ -107,6 +107,13 @@ class ChatServer {
|
||||
final FakeChannel channel;
|
||||
final _answered = <Object?>{};
|
||||
final requests = <Map<String, dynamic>>[];
|
||||
|
||||
/// False answers the chat list with no rows, as a pool whose machines
|
||||
/// have not connected yet does.
|
||||
bool listsChats = true;
|
||||
|
||||
/// Each chat's shared colour, by id.
|
||||
final colors = <String, String>{};
|
||||
List<Object?> _entries;
|
||||
int _revision = 1;
|
||||
|
||||
@@ -135,13 +142,15 @@ class ChatServer {
|
||||
'id': id,
|
||||
'type': type,
|
||||
'chat_sessions': [
|
||||
for (final s in const ['a', 'b', 'c'])
|
||||
{
|
||||
'id': s,
|
||||
'title': 'Chat $s',
|
||||
'directory': '/workspace/demo',
|
||||
'updated_at': '2026-11-12T10:00:00Z',
|
||||
},
|
||||
if (listsChats)
|
||||
for (final s in const ['a', 'b', 'c'])
|
||||
{
|
||||
'id': s,
|
||||
'title': 'Chat $s',
|
||||
'directory': '/workspace/demo',
|
||||
'updated_at': '2026-11-12T10:00:00Z',
|
||||
'color': ?colors[s],
|
||||
},
|
||||
],
|
||||
};
|
||||
case 'chat_messages':
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_preferences.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font_controller.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font_store.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('the design and font chosen in the main window follow into a '
|
||||
'detached window, on a storage event and on coming to the front', (
|
||||
tester,
|
||||
) async {
|
||||
final designStore = MemoryAppDesignStore();
|
||||
final fontStore = MemoryAppFontStore();
|
||||
final designs = AppDesignController(store: designStore);
|
||||
final fonts = AppFontController(store: fontStore, loader: (_, _) async {});
|
||||
final changes = StreamController<void>.broadcast();
|
||||
var reloads = 0;
|
||||
final follower = DetachedPreferencesFollower(
|
||||
changes: changes.stream,
|
||||
designs: designs,
|
||||
fonts: fonts,
|
||||
reload: () async => reloads++,
|
||||
)..start();
|
||||
addTearDown(() {
|
||||
follower.dispose();
|
||||
unawaited(changes.close());
|
||||
});
|
||||
|
||||
// Another window stores the Terminal design and a font.
|
||||
designStore.id = AppDesign.terminal.id;
|
||||
fontStore.id = AppFont.inter.id;
|
||||
changes.add(null);
|
||||
await tester.pumpAndSettle();
|
||||
expect(reloads, 1);
|
||||
expect(designs.design, AppDesign.terminal);
|
||||
expect(fonts.selected, AppFont.inter);
|
||||
expect(fonts.family, AppFont.inter.family);
|
||||
|
||||
// Back to the defaults, seen when this window comes to the front.
|
||||
designStore.id = AppDesign.standard.id;
|
||||
fontStore.id = AppFont.system.id;
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
await tester.pumpAndSettle();
|
||||
expect(reloads, 2);
|
||||
expect(designs.design, AppDesign.standard);
|
||||
expect(fonts.selected, AppFont.system);
|
||||
expect(fonts.family, isNull);
|
||||
// Following never writes the choice back.
|
||||
expect(designStore.id, AppDesign.standard.id);
|
||||
});
|
||||
|
||||
test('a font id this device cannot resolve keeps the current font', () async {
|
||||
final store = MemoryAppFontStore(AppFont.inter.id);
|
||||
final fonts = AppFontController(store: store, loader: (_, _) async {});
|
||||
await fonts.restore();
|
||||
expect(fonts.selected, AppFont.inter);
|
||||
store.id = 'custom-unknown';
|
||||
await fonts.restore();
|
||||
expect(fonts.selected, AppFont.inter);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user