Remove Cupertino chat session branches

Keep the Material-only session UI and narrow its tests to the supported host. Preserve public Cupertino parameters for callers while removing unreachable Cupertino widgets and variants.
This commit is contained in:
2026-11-11 14:18:04 +00:00
parent 96de9f5bea
commit ae208699d8
37 changed files with 566 additions and 2121 deletions
@@ -1,6 +1,5 @@
import 'dart:ui' show Tristate;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/layout/app_list_row.dart';
@@ -10,104 +9,94 @@ import 'chat_test_harness.dart';
import 'fake_chat_gateway.dart';
void main() {
for (final cupertino in [false, true]) {
for (final brightness in Brightness.values) {
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} $brightness: active row '
'follows selection, survives refresh and clears with the route',
(tester) async {
final semantics = tester.ensureSemantics();
try {
final gateway = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [
{'id': 'a', 'title': 'Same title'},
{'id': 'b', 'title': 'Same title'},
],
};
addTearDown(gateway.pushed.close);
final store = MemoryChatSessionLocalStore();
String? selected = 'a'; // A routed chat need not have been tapped.
late StateSetter rebuild;
final screen = StatefulBuilder(
builder: (context, setState) {
rebuild = setState;
return ChatSessionsScreen(
gateway: gateway,
localStore: store,
activeSessionId: selected,
onOpen: (session) => setState(() => selected = session['id']),
);
},
for (final brightness in Brightness.values) {
testWidgets('Material $brightness: active row '
'follows selection, survives refresh and clears with the route', (
tester,
) async {
final semantics = tester.ensureSemantics();
try {
final gateway = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [
{'id': 'a', 'title': 'Same title'},
{'id': 'b', 'title': 'Same title'},
],
};
addTearDown(gateway.pushed.close);
final store = MemoryChatSessionLocalStore();
String? selected = 'a'; // A routed chat need not have been tapped.
late StateSetter rebuild;
final screen = StatefulBuilder(
builder: (context, setState) {
rebuild = setState;
return ChatSessionsScreen(
gateway: gateway,
localStore: store,
activeSessionId: selected,
onOpen: (session) => setState(() => selected = session['id']),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
home: screen,
)
: MaterialApp(
theme: ThemeData(brightness: brightness),
home: screen,
),
);
await tester.pumpAndSettle();
},
);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(brightness: brightness),
home: screen,
),
);
await tester.pumpAndSettle();
void expectRow(String id, bool active) {
final row = find.byKey(Key('chat-row-$id'));
expect(
tester.getSemantics(row).flagsCollection.isSelected ==
Tristate.isTrue,
active,
);
expect(tester.widget<AppListRow>(row).selected, active);
final surface = find.descendant(
of: row,
matching: find.byKey(appListRowSurfaceKey),
);
final color = cupertino
? tester.widget<ColoredBox>(surface).color
: tester.widget<Material>(surface).color;
expect(color, const Color(0x00000000));
final highlight = tester.widget<AnimatedContainer>(
find.byKey(ValueKey('chat-visibility-$id')),
);
final gradient =
(highlight.decoration as BoxDecoration).gradient!
as LinearGradient;
expect(gradient.colors.first.a > 0, active);
expect(gradient.colors.last.a > 0, active);
}
void expectRow(String id, bool active) {
final row = find.byKey(Key('chat-row-$id'));
expect(
tester.getSemantics(row).flagsCollection.isSelected ==
Tristate.isTrue,
active,
);
expect(tester.widget<AppListRow>(row).selected, active);
final surface = find.descendant(
of: row,
matching: find.byKey(appListRowSurfaceKey),
);
final color = tester.widget<Material>(surface).color;
expect(color, const Color(0x00000000));
final highlight = tester.widget<AnimatedContainer>(
find.byKey(ValueKey('chat-visibility-$id')),
);
final gradient =
(highlight.decoration as BoxDecoration).gradient!
as LinearGradient;
expect(gradient.colors.first.a > 0, active);
expect(gradient.colors.last.a > 0, active);
}
expectRow('a', true);
expectRow('b', false);
await tester.tap(find.byKey(const Key('chat-row-b')));
await tester.pumpAndSettle();
expectRow('a', false);
expectRow('b', true);
expectRow('a', true);
expectRow('b', false);
await tester.tap(find.byKey(const Key('chat-row-b')));
await tester.pumpAndSettle();
expectRow('a', false);
expectRow('b', true);
gateway.sessionsReply = {
'chat_sessions': [
{'id': 'b', 'title': 'Renamed active chat'},
{'id': 'a', 'title': 'Same title'},
],
};
await tester.tap(find.byKey(const Key('chat-refresh')));
await tester.pumpAndSettle();
expectRow('b', true);
expectRow('a', false);
gateway.sessionsReply = {
'chat_sessions': [
{'id': 'b', 'title': 'Renamed active chat'},
{'id': 'a', 'title': 'Same title'},
],
};
await tester.tap(find.byKey(const Key('chat-refresh')));
await tester.pumpAndSettle();
expectRow('b', true);
expectRow('a', false);
rebuild(() => selected = null);
await tester.pumpAndSettle();
expectRow('a', false);
expectRow('b', false);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
} finally {
semantics.dispose();
}
},
);
}
rebuild(() => selected = null);
await tester.pumpAndSettle();
expectRow('a', false);
expectRow('b', false);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
} finally {
semantics.dispose();
}
});
}
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -39,7 +38,6 @@ FakeChatGateway _gateway() {
Future<void> _pump(
WidgetTester tester,
FakeChatGateway gateway, {
required bool cupertino,
required Brightness brightness,
}) async {
final screen = ChatSessionsScreen(
@@ -48,21 +46,13 @@ Future<void> _pump(
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
home: MediaQuery(
data: MediaQueryData(platformBrightness: brightness),
child: screen,
),
)
: MaterialApp(
theme: ThemeData(
platform: TargetPlatform.android,
brightness: brightness,
),
home: screen,
),
MaterialApp(
theme: ThemeData(
platform: TargetPlatform.android,
brightness: brightness,
),
home: screen,
),
);
await tester.pumpAndSettle();
}
@@ -78,110 +68,83 @@ Color _accentColor(WidgetTester tester, String id) =>
tester.widget<AppListRow>(_accent(id)).accent!;
void main() {
// The row menu is Material only.
for (final cupertino in [false]) {
for (final brightness in Brightness.values) {
final host = '${cupertino ? 'Cupertino' : 'Material'} ${brightness.name}';
for (final brightness in Brightness.values) {
final host = 'Material ${brightness.name}';
testWidgets('$host: a coloured chat wears its colour, a plain one none', (
tester,
) async {
await _pump(
tester,
_gateway(),
cupertino: cupertino,
brightness: brightness,
);
expect(_accent('s1'), findsOneWidget);
expect(_accent('s2'), findsNothing);
final accent = _accentColor(tester, 's1');
// The avatar takes the same colour as the bar.
final avatar = tester.widget<AppListAvatar>(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byType(AppListAvatar),
),
);
expect(avatar.foreground, accent);
// A teal shade, not the host's accent or a grey.
expect(accent.g, greaterThan(accent.r));
expect(accent.b, greaterThan(accent.r));
// The row tint is faint: the selected fill stays the stronger mark.
final tint = cupertino
? tester
.widget<ColoredBox>(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byKey(appListRowSurfaceKey),
),
)
.color
: tester
.widget<Material>(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byKey(appListRowSurfaceKey),
),
)
.color!;
expect(tint.a, inInclusiveRange(0.05, 0.13));
// Shades are tuned per brightness.
final shade = accent.computeLuminance();
if (brightness == Brightness.dark) {
expect(shade, greaterThan(0.2));
} else {
expect(shade, lessThan(0.55));
}
testWidgets('$host: a coloured chat wears its colour, a plain one none', (
tester,
) async {
await _pump(tester, _gateway(), brightness: brightness);
expect(_accent('s1'), findsOneWidget);
expect(_accent('s2'), findsNothing);
final accent = _accentColor(tester, 's1');
// The avatar takes the same colour as the bar.
final avatar = tester.widget<AppListAvatar>(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byType(AppListAvatar),
),
);
expect(avatar.foreground, accent);
// A teal shade, not the host's accent or a grey.
expect(accent.g, greaterThan(accent.r));
expect(accent.b, greaterThan(accent.r));
// The row tint is faint: the selected fill stays the stronger mark.
final tint = tester
.widget<Material>(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byKey(appListRowSurfaceKey),
),
)
.color!;
expect(tint.a, inInclusiveRange(0.05, 0.13));
// Shades are tuned per brightness.
final shade = accent.computeLuminance();
if (brightness == Brightness.dark) {
expect(shade, greaterThan(0.2));
} else {
expect(shade, lessThan(0.55));
}
});
testWidgets('$host: the row menu sets and clears the colour', (
tester,
) async {
final gateway = _gateway();
await _pump(tester, gateway, brightness: brightness);
await tester.tap(
find.descendant(
of: find.byKey(const Key('chat-actions-s2')),
matching: find.byType(IconButton),
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Colour…'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-color-sheet')), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-color-purple')));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_color'), {
'chat_query': {'session_id': 's2', 'color': 'purple'},
});
// The row shows it at once, before the list re-reads.
expect(_accent('s2'), findsOneWidget);
testWidgets('$host: the row menu sets and clears the colour', (
tester,
) async {
final gateway = _gateway();
await _pump(
tester,
gateway,
cupertino: cupertino,
brightness: brightness,
);
await tester.tap(
find.descendant(
of: find.byKey(const Key('chat-actions-s2')),
matching: find.byType(cupertino ? CupertinoButton : IconButton),
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Colour…'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-color-sheet')), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-color-purple')));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_color'), {
'chat_query': {'session_id': 's2', 'color': 'purple'},
});
// The row shows it at once, before the list re-reads.
expect(_accent('s2'), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-color-none')));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_color'), {
'chat_query': {'session_id': 's2', 'color': null},
});
await tester.tap(find.byKey(const Key('chat-color-done')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-color-sheet')), findsNothing);
await tester.tap(find.byKey(const Key('chat-color-none')));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_color'), {
'chat_query': {'session_id': 's2', 'color': null},
});
}
await tester.tap(find.byKey(const Key('chat-color-done')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-color-sheet')), findsNothing);
});
}
testWidgets('a long-press on a row opens the colour choice', (tester) async {
final gateway = _gateway();
await _pump(
tester,
gateway,
cupertino: false,
brightness: Brightness.light,
);
await _pump(tester, gateway, brightness: Brightness.light);
await tester.longPress(find.text('Plain chat'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-color-sheet')), findsOneWidget);
@@ -1,6 +1,6 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -76,13 +76,13 @@ void main() {
},
);
testWidgets('Cupertino create dialog keeps the draft when catalogs fail', (
testWidgets('create dialog keeps the draft when catalogs fail', (
tester,
) async {
final gateway = FakeChatGateway();
gateway.directoriesHandler = () =>
Future.error(StateError('Server did not return chat directories.'));
await pumpCupertinoChat(tester, gateway);
await pumpMaterialChat(tester, gateway);
await tester.tap(find.byKey(const Key('chat-new-chat')));
await tester.pumpAndSettle();
@@ -124,77 +124,6 @@ void main() {
expect(fields.containsKey('instructions'), isFalse);
});
testWidgets('Cupertino create dialog uses native selectors and fields', (
tester,
) async {
final gateway = FakeChatGateway();
JsonMap? opened;
await pumpCupertinoChat(
tester,
gateway,
onOpen: (session) => opened = session,
);
await tester.tap(find.byKey(const Key('chat-new-chat')));
await tester.pumpAndSettle();
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
expect(find.text('Start a chat'), findsOneWidget);
expect(find.byKey(const Key('chat-create-instructions')), findsNothing);
await tester.tap(find.byKey(const Key('chat-create-send-prompt')));
await tester.pumpAndSettle();
expect(
find.text('Where should this chat live?: Home (~) — /work'),
findsOneWidget,
);
expect(find.text('Chat harness: OpenCode'), findsOneWidget);
await tester.ensureVisible(
find.byKey(const Key('chat-create-prompt-choice')),
);
await tester.tap(find.byKey(const Key('chat-create-prompt-choice')));
await tester.pumpAndSettle();
await tester.tap(find.text('Careful coding'));
await tester.pumpAndSettle();
expect(
find.textContaining('Act as a careful coding agent.'),
findsOneWidget,
);
await tester.ensureVisible(find.byKey(const Key('chat-create-backend')));
await tester.tap(find.byKey(const Key('chat-create-backend')));
await tester.pumpAndSettle();
await tester.tap(find.text('Codex'));
await tester.pumpAndSettle();
expect(find.text('Chat harness: Codex'), findsOneWidget);
await tester.ensureVisible(
find.byKey(const Key('chat-create-server-directory')),
);
await tester.tap(find.byKey(const Key('chat-create-server-directory')));
await tester.pumpAndSettle();
expect(find.text('/archive'), findsOneWidget);
await tester.tap(find.text('/archive'));
await tester.pumpAndSettle();
expect(find.text('Where should this chat live?: /archive'), findsOneWidget);
expect(find.text('Start in /archive'), findsOneWidget);
await tester.enterText(
find.byKey(const Key('chat-create-instructions')),
'Be careful',
);
await tester.ensureVisible(find.byKey(const Key('chat-create-confirm')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-create-confirm')));
await tester.pumpAndSettle();
final fields =
gateway.lastFields('chat_create')!['chat_create']! as JsonMap;
expect(fields['title'], 'Archive Codex');
expect(fields['directory'], '/archive');
expect(fields['backend'], 'codex');
expect(fields['instructions'], 'Be careful');
expect(opened?['id'], 'created');
});
testWidgets('a created chat opens before the list refresh completes', (
tester,
) async {
@@ -1,7 +1,6 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/data/chat_create_prompt_store.dart';
import 'package:pipelines_app/features/chat/data/chat_repository.dart';
@@ -243,36 +242,6 @@ void main() {
'Saved preset',
);
});
testWidgets('Cupertino prompt chooser has native preset and custom choices', (
tester,
) async {
final prompts = _MemoryPrompts();
await tester.pumpWidget(
CupertinoApp(
home: CupertinoPageScaffold(
child: CreateChatDialog(
repository: ChatRepository(FakeChatGateway()),
operationId: 'op',
prompts: prompts,
onSubmit: (_, _) async => {'id': 'new'},
),
),
),
);
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-create-send-prompt')), findsOneWidget);
expect(find.byKey(const Key('chat-create-instructions')), findsNothing);
await tester.tap(find.byKey(const Key('chat-create-send-prompt')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-create-prompt-choice')));
await tester.pumpAndSettle();
expect(find.byType(CupertinoActionSheet), findsOneWidget);
expect(find.text('Careful coding'), findsOneWidget);
await tester.tap(find.text('Cancel').last);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
});
}
Future<void> _pickPrompt(WidgetTester tester, String label) async {
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -69,30 +68,6 @@ void main() {
});
});
testWidgets('Cupertino close confirmation uses the action sheet flow', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
await pumpCupertinoChat(tester, gateway);
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Close chat…'));
await tester.pumpAndSettle();
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
expect(
find.textContaining('marks it closed on every device'),
findsOneWidget,
);
await tester.tap(find.text('Close chat'));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_close'), {
'chat_query': {'session_id': 's2'},
});
});
testWidgets('material rename disables Save while the name is blank', (
tester,
) async {
@@ -114,27 +89,6 @@ void main() {
expect(gateway.count('chat_rename'), 0);
});
testWidgets('Cupertino rename disables Save while the name is blank', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
await pumpCupertinoChat(tester, gateway);
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Rename…'));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('chat-rename-field')), ' ');
await tester.pump();
final save = tester.widget<CupertinoDialogAction>(
find.widgetWithText(CupertinoDialogAction, 'Save'),
);
expect(save.onPressed, isNull);
expect(gateway.count('chat_rename'), 0);
});
testWidgets('material rename helper wraps instead of truncating at 2x', (
tester,
) async {
@@ -29,29 +29,6 @@ void main() {
expect(tester.takeException(), isNull);
});
testWidgets('Cupertino rename refusal fits 320px at 2x', (tester) async {
useSmallTextSurface(tester);
final gateway = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [
{'id': 's2', 'title': 'Open chat', 'directory': '/work'},
],
}
..failures['chat_rename'] = 'a title with usable text is required';
await pumpCupertinoChat(tester, gateway);
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Rename…'));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('chat-rename-field')), ' x ');
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
expect(find.text('a title with usable text is required'), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('Material create catalog fits real paths at 320px and 2x', (
tester,
) async {
@@ -88,21 +65,4 @@ void main() {
expect(tester.takeException(), isNull);
expect(find.byKey(const Key('chat-create-instructions')), findsOneWidget);
});
testWidgets('Cupertino create catalog fits real paths at 320px and 2x', (
tester,
) async {
useSmallTextSurface(tester);
final gateway = FakeChatGateway();
await pumpCupertinoChat(tester, gateway);
await tester.tap(find.byKey(const Key('chat-new-chat')));
await tester.pumpAndSettle();
expect(
find.textContaining('Where should this chat live?:'),
findsOneWidget,
);
expect(tester.takeException(), isNull);
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -158,57 +157,4 @@ void main() {
);
expect(tester.takeException(), isNull);
});
testWidgets('Cupertino row refusal is readable at 320px 2x dark', (
tester,
) async {
useSmallTextSurface(tester);
final gateway = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [
{
'id': 's4',
'title': 'Closed chat',
'directory': '/work',
'closed_at': '2026-01-01',
},
],
}
..failures['chat_reopen'] = _refusal;
await tester.pumpWidget(
CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
localStore: MemoryChatSessionLocalStore(),
),
),
);
await tester.pumpAndSettle();
await expandClosedChats(tester);
await tester.ensureVisible(find.byKey(const Key('chat-actions-s4')));
await tester.tap(find.byKey(const Key('chat-actions-s4')));
await tester.pumpAndSettle();
await tester.tap(find.text('Reopen'));
await tester.pumpAndSettle();
// Regression: `CupertinoListTile.subtitle` is wrapped by the SDK in
// `DefaultTextStyle(maxLines: 1, overflow: ellipsis)`. The full sentence
// must be readable, so it cannot live inside that tile.
final paragraph = tester.renderObject<RenderParagraph>(
find.byKey(const Key('chat-row-error-s4')),
);
expect(paragraph.didExceedMaxLines, isFalse);
expect(find.text(_refusal), findsOneWidget);
expect(
find.ancestor(
of: find.byKey(const Key('chat-row-error-s4')),
matching: find.byType(CupertinoListTile),
),
findsNothing,
);
expect(tester.takeException(), isNull);
});
}
@@ -1,281 +0,0 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/layout/app_list_row.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_list_cupertino.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_row_style.dart';
/// The Cupertino list, the host the web client runs on macOS/iOS.
Future<void> _pumpRows(
WidgetTester tester,
List<JsonMap> sessions, {
bool Function(JsonMap)? isUnseen,
}) async {
await tester.pumpWidget(
CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoPageScaffold(
child: CupertinoSessionList(
sections: [(title: 'Chats', sessions: sessions)],
emptyMessage: null,
duplicateTitles: const {},
onOpen: (_) {},
onRename: (_) {},
onClose: (_) {},
onReopen: (_) {},
onStar: (_) {},
onHide: (_) {},
onClearSearch: null,
isUnseen: isUnseen ?? (_) => false,
errorFor: (_) => null,
),
),
),
);
// A running row's activity badge animates for as long as it runs.
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
}
void _useNarrowText(WidgetTester tester) {
tester.view.physicalSize = const Size(320, 640);
tester.view.devicePixelRatio = 1;
tester.platformDispatcher.textScaleFactorTestValue = 2;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
}
/// The resolved style a text is painted with, after merging with the host's
/// own `DefaultTextStyle`.
TextStyle _styleOf(WidgetTester tester, String text) =>
tester.renderObject<RenderParagraph>(find.textContaining(text)).text.style!;
void main() {
test(
'relative recency uses shared compact wording and never invents a time',
() {
final now = DateTime(2026, 10, 22, 12);
final from = now.subtract;
expect(relativeChatSessionTime(null, now: now), '');
expect(relativeChatSessionTime(0, now: now), '');
expect(
relativeChatSessionTime(now.millisecondsSinceEpoch, now: now),
'just now',
);
expect(
relativeChatSessionTime(
from(const Duration(minutes: 5)).millisecondsSinceEpoch,
now: now,
),
'5m',
);
expect(
relativeChatSessionTime(
from(const Duration(hours: 3)).millisecondsSinceEpoch,
now: now,
),
'3h',
);
expect(
relativeChatSessionTime(
from(const Duration(hours: 25)).millisecondsSinceEpoch,
now: now,
),
'1d',
);
expect(
relativeChatSessionTime(
from(const Duration(days: 3)).millisecondsSinceEpoch,
now: now,
),
'3d',
);
expect(
relativeChatSessionTime(
DateTime(2026, 10, 1, 9).millisecondsSinceEpoch,
now: now,
),
'1 Oct',
);
// The web formats with `Intl.DateTimeFormat('en-GB', …)`, whose short
// September is `Sept`; its own test asserts `12 Sept`.
expect(
relativeChatSessionTime(
DateTime(2026, 9, 12, 9).millisecondsSinceEpoch,
now: now,
),
'12 Sep',
);
},
);
test('the subtitle and status come only from the row', () {
expect(
chatSessionSubtitle({'directory': '/work', 'model': 'model-a'}),
'model-a · /work',
);
expect(chatSessionSubtitle({'directory': '/work'}), '/work');
expect(chatSessionSubtitle({}), '');
// The harness is the avatar, not a word; the home folder reads as ~.
expect(
chatSessionSubtitle({
'backend': 'claude',
'model': 'opus',
'directory': '/Users/alan/repos/pipelines',
}),
'opus · ~/repos/pipelines',
);
expect(homeRelativePath('/home/dev/x'), '~/x');
expect(homeRelativePath('/Users/alan'), '~');
expect(homeRelativePath('/srv/work'), '/srv/work');
expect(chatSessionRowStatus({}, unseen: false), isNull);
expect(chatSessionRowStatus({}, unseen: true), 'New');
expect(chatSessionRowStatus({'running': true}, unseen: true), 'New');
expect(chatSessionRowStatus({'running': true}, unseen: false), isNull);
expect(
chatSessionRowStatus({'closed_at': '2026-01-01'}, unseen: true),
'Closed',
);
});
testWidgets('a row reads avatar, title with time, one muted line and menu', (
tester,
) async {
final now = DateTime.now();
final sessions = <JsonMap>[
{
'id': 's1',
'title': 'Unread chat',
'backend': 'claude',
'directory': '/work',
'model': 'model-a',
'starred': true,
'updated_at': now
.subtract(const Duration(minutes: 5))
.millisecondsSinceEpoch,
},
{
'id': 's2',
'title': 'Read chat',
'directory': '/work',
'running': true,
'updated_at': now
.subtract(const Duration(hours: 2, minutes: 30))
.millisecondsSinceEpoch,
},
];
await _pumpRows(
tester,
sessions,
isUnseen: (session) => session['id'] == 's1',
);
final title = tester.getRect(find.textContaining('Unread chat'));
final time = tester.getRect(find.text('5m'));
final subtitle = tester.getRect(find.text('model-a · /work'));
final avatar = tester.getRect(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byType(ChatSessionAvatar),
),
);
// Avatar leads, the time trails the title on its line, the muted line
// sits beneath, and the menu trails the whole row.
expect(avatar.right, lessThanOrEqualTo(title.left));
expect(time.left, greaterThan(title.right));
expect(time.center.dy, closeTo(title.center.dy, 2));
expect(subtitle.top, greaterThanOrEqualTo(title.bottom - 1));
expect(
tester.getRect(find.byKey(const Key('chat-actions-s1'))).left,
greaterThanOrEqualTo(time.right),
);
// Unread is bold with an accent time and dot; read rows are not.
expect(_styleOf(tester, 'Unread chat').fontWeight, FontWeight.w700);
expect(_styleOf(tester, 'Read chat').fontWeight, FontWeight.w600);
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
final accent = CupertinoTheme.of(
tester.element(find.text('5m')),
).primaryColor;
expect(_styleOf(tester, '5m').color, accent);
expect(_styleOf(tester, '2h').color, isNot(accent));
// Starred shows a small star by the title; running a badge on the avatar.
expect(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byKey(const Key('chat-row-starred')),
),
findsOneWidget,
);
expect(
find.descendant(
of: find.byKey(const Key('chat-row-s2')),
matching: find.byKey(const Key('chat-row-working')),
),
findsOneWidget,
);
expect(find.byType(AppListRow), findsNWidgets(2));
expect(
tester.getTopLeft(find.byKey(const Key('chat-row-s2'))).dy,
greaterThanOrEqualTo(
tester.getBottomLeft(find.byKey(const Key('chat-row-s1'))).dy,
),
);
});
testWidgets('at 320px 2x the long title and subtitle ellipsise', (
tester,
) async {
_useNarrowText(tester);
final now = DateTime.now();
await _pumpRows(tester, [
{
'id': 's1',
'title': 'A conversation title long enough to need an ellipsis',
'directory': '/a/very/long/directory/that/must/ellipsise',
'model': 'provider/an-extremely-long-recorded-model-id',
'updated_at': now
.subtract(const Duration(days: 3))
.millisecondsSinceEpoch,
},
{
'id': 'c1',
'title': 'A closed conversation',
'directory': '/work',
'closed_at': '2026-01-01',
},
], isUnseen: (session) => session['id'] == 's1');
expect(tester.takeException(), isNull);
final title = tester.renderObject<RenderParagraph>(
find.text('A conversation title long enough to need an ellipsis'),
);
expect(title.maxLines, 1);
expect(title.didExceedMaxLines, isTrue);
final subtitle = tester.renderObject<RenderParagraph>(
find.text(
'provider/an-extremely-long-recorded-model-id · '
'/a/very/long/directory/that/must/ellipsise',
),
);
expect(subtitle.maxLines, 1);
expect(subtitle.didExceedMaxLines, isTrue);
// The time and the Closed word stay inside their row.
for (final (row, word) in [('s1', '3d'), ('c1', 'Closed')]) {
expect(
tester.getRect(find.textContaining(word)).right,
lessThanOrEqualTo(
tester.getRect(find.byKey(Key('chat-row-$row'))).right,
),
);
}
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -56,23 +55,17 @@ Finder _spinner(String id) => find.descendant(
matching: find.byKey(const Key('chat-row-working')),
);
Future<void> _pump(
WidgetTester tester,
FakeChatGateway fake, {
bool cupertino = false,
}) async {
Future<void> _pump(WidgetTester tester, FakeChatGateway fake) async {
final screen = ChatSessionsScreen(
gateway: fake,
onOpen: (_) {},
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: screen)
: MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: screen,
),
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: screen,
),
);
// A spinner never settles, so pump a few frames instead.
for (var i = 0; i < 5; i++) {
@@ -177,21 +170,6 @@ void main() {
expect(_badge('s1'), findsNothing);
});
testWidgets('the Cupertino host shows the background task count', (
tester,
) async {
final fake = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [_row('bg', activity: _activity(tasks: 1))],
};
await _pump(tester, fake, cupertino: true);
expect(
find.descendant(of: _badge('bg'), matching: find.text('1')),
findsOneWidget,
);
expect(_label(1), findsOneWidget);
});
group('controller', () {
late FakeChatGateway fake;
late ChatSessionsController controller;
@@ -16,35 +16,27 @@ List<JsonMap> _many() => [
];
void main() {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('Material list scrolls behind the bar and starts below it', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': _many()};
await pumpMaterialChat(tester, gateway);
testWidgets('$host list scrolls behind the bar and starts below it', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': _many()};
if (cupertino) {
await pumpCupertinoChat(tester, gateway);
} else {
await pumpMaterialChat(tester, gateway);
}
final bar = tester.getRect(find.byType(SegmentedBar));
final list = tester.getRect(find.byType(CustomScrollView).first);
// The list reaches under the bar ...
expect(list.top, lessThan(bar.bottom));
// ... yet at rest its first row is clear of it.
final first = tester.getRect(
find.descendant(
of: find.byKey(const ValueKey('chat-section-Chats')),
matching: find.byType(SectionHeading),
),
);
expect(first.top, greaterThanOrEqualTo(bar.bottom));
expect(tester.takeException(), isNull);
});
}
final bar = tester.getRect(find.byType(SegmentedBar));
final list = tester.getRect(find.byType(CustomScrollView).first);
// The list reaches under the bar ...
expect(list.top, lessThan(bar.bottom));
// ... yet at rest its first row is clear of it.
final first = tester.getRect(
find.descendant(
of: find.byKey(const ValueKey('chat-section-Chats')),
matching: find.byType(SectionHeading),
),
);
expect(first.top, greaterThanOrEqualTo(bar.bottom));
expect(tester.takeException(), isNull);
});
testWidgets('the standalone Material list has one New chat, in the bar', (
tester,
@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -29,22 +28,6 @@ Future<void> _pump(
await tester.pumpAndSettle();
}
Future<void> _pumpCupertino(
WidgetTester tester,
FakeChatGateway gateway,
) async {
await tester.pumpWidget(
CupertinoApp(
home: ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
localStore: _store,
),
),
);
await tester.pumpAndSettle();
}
late MemoryChatSessionLocalStore _store;
class _DeferredStore implements ChatSessionLocalStore {
@@ -339,31 +322,4 @@ void main() {
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
expect(delayed.saved?.isUnseen('s1'), isFalse);
});
testWidgets('Cupertino rows load, mark a real answer New, then read it', (
tester,
) async {
final fake = gateway();
await _pumpCupertino(tester, fake);
fake.pushed.add({
'type': 'chat_event',
'chat_event': {
'session_id': 's1',
'kind': 'step',
'step': {'status': 'started'},
},
});
await tester.pump();
await tester.pump();
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
fake.pushed.add(_event('s1'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-row-s1')));
await tester.pump();
await tester.pump();
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
});
}
@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -96,87 +95,31 @@ void main() {
expect(find.textContaining('No chats match'), findsNothing);
});
testWidgets(
'Cupertino app renders standard controls, groups and renames without Material',
(tester) async {
_inventoryViewport(tester);
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
await pumpCupertinoChat(tester, gateway);
expect(find.byType(CupertinoPageScaffold), findsOneWidget);
// The list has no search field; New chat and Refresh are the actions.
expect(find.byType(CupertinoSearchTextField), findsNothing);
expect(find.byType(Scaffold), findsNothing);
// Directory groups sit under their section's heading.
expect(find.byKey(const ValueKey('chat-section-Chats')), findsOneWidget);
expect(find.text('/work'), findsWidgets);
expect(find.text('/else'), findsWidgets);
// Starring lives in the row's actions menu.
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Star'));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_star'), {
'chat_query': {'session_id': 's2', 'starred': true},
});
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
expect(find.text('Rename…'), findsOneWidget);
await tester.tap(find.text('Rename…'));
await tester.pumpAndSettle();
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
await tester.enterText(
find.byKey(const Key('chat-rename-field')),
'Renamed on Cupertino',
testWidgets('load failure wraps the reason and hides the empty message', (
tester,
) async {
usePhoneSurface(tester);
final gateway = FakeChatGateway()
..sessionsHandler = () => Future.error(
StateError(
'server unavailable while listing chat sessions for this operator',
),
);
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_rename'), {
'chat_rename': {'session_id': 's2', 'title': 'Renamed on Cupertino'},
});
await pumpMaterialChat(tester, gateway);
await expandClosedChats(tester);
await tester.ensureVisible(find.byKey(const Key('chat-actions-s4')));
await tester.tap(find.byKey(const Key('chat-actions-s4')));
await tester.pumpAndSettle();
await tester.tap(find.text('Reopen'));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_reopen'), {
'chat_query': {'session_id': 's4'},
});
},
);
testWidgets(
'Cupertino load failure wraps the reason and hides the empty message',
(tester) async {
usePhoneSurface(tester);
final gateway = FakeChatGateway()
..sessionsHandler = () => Future.error(
StateError(
'server unavailable while listing chat sessions for this operator',
),
);
await pumpCupertinoChat(tester, gateway);
const message =
'Bad state: server unavailable while listing chat sessions '
'for this operator';
expect(find.text(message), findsOneWidget);
expect(find.text('No chat sessions on this server yet.'), findsNothing);
final messageBox = tester.renderObject<RenderBox>(find.text(message));
expect(
messageBox.size.height,
greaterThan(30),
reason: 'the server reason must wrap instead of being cut to one line',
);
expect(find.widgetWithText(CupertinoButton, 'Retry'), findsOneWidget);
},
);
const message =
'Bad state: server unavailable while listing chat sessions '
'for this operator';
expect(find.text(message), findsOneWidget);
expect(find.text('No chat sessions on this server yet.'), findsNothing);
final messageBox = tester.renderObject<RenderBox>(find.text(message));
expect(
messageBox.size.height,
greaterThan(30),
reason: 'the server reason must wrap instead of being cut to one line',
);
expect(find.widgetWithText(TextButton, 'Retry'), findsOneWidget);
});
testWidgets('closed chats start folded away behind their heading', (
tester,
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -9,126 +8,105 @@ import 'fake_chat_gateway.dart';
void main() {
// The row menu is Material only.
for (final cupertino in [false]) {
for (final beside in [false, true]) {
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} split menu passes selected chat ${beside ? 'beside' : 'below'}',
(tester) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close);
final opened = <JsonMap>[];
final right = <JsonMap>[];
final below = <JsonMap>[];
final screen = ChatSessionsScreen(
gateway: gateway,
onOpen: opened.add,
onOpenBeside: right.add,
onOpenBelow: below.add,
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
expect(find.text('Open to the right'), findsOneWidget);
expect(find.text('Open below'), findsOneWidget);
if (cupertino) {
expect(find.byType(CupertinoActionSheet), findsOneWidget);
}
await tester.tap(
find.text(beside ? 'Open to the right' : 'Open below'),
);
await tester.pumpAndSettle();
expect(opened, isEmpty);
expect(beside ? right : below, hasLength(1));
expect((beside ? right : below).single['id'], 's2');
expect((beside ? right : below).single['title'], 'Open chat');
expect(beside ? below : right, isEmpty);
expect(
gateway.calls.where((call) => call.type != 'chat_sessions'),
isEmpty,
);
expect(find.text('Open to the right'), findsNothing);
},
);
}
for (final beside in [false, true]) {
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} updates available directions on mounted rows',
(tester) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close);
final right = <JsonMap>[];
final below = <JsonMap>[];
Future<void> show({required bool horizontal}) async {
final screen = ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
onOpenBeside: horizontal ? right.add : null,
onOpenBelow: horizontal ? null : below.add,
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
}
await show(horizontal: true);
expect(find.text('Open to the right'), findsOneWidget);
expect(find.text('Open below'), findsNothing);
if (cupertino) {
await tester.tap(find.text('Cancel'));
} else {
await tester.tapAt(const Offset(5, 5));
}
await tester.pumpAndSettle();
await show(horizontal: false);
expect(find.text('Open to the right'), findsNothing);
expect(find.text('Open below'), findsOneWidget);
await tester.tap(find.text('Open below'));
await tester.pumpAndSettle();
expect(right, isEmpty);
expect(below.single['id'], 's2');
},
);
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} hides unavailable split choices and keeps row open',
'Material split menu passes selected chat ${beside ? 'beside' : 'below'}',
(tester) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close);
final opened = <JsonMap>[];
final right = <JsonMap>[];
final below = <JsonMap>[];
final screen = ChatSessionsScreen(
gateway: gateway,
onOpen: opened.add,
onOpenBeside: right.add,
onOpenBelow: below.add,
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen),
);
await tester.pumpWidget(MaterialApp(home: screen));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
expect(find.text('Open to the right'), findsOneWidget);
expect(find.text('Open below'), findsOneWidget);
await tester.tap(
find.text(beside ? 'Open to the right' : 'Open below'),
);
await tester.pumpAndSettle();
expect(opened, isEmpty);
expect(beside ? right : below, hasLength(1));
expect((beside ? right : below).single['id'], 's2');
expect((beside ? right : below).single['title'], 'Open chat');
expect(beside ? below : right, isEmpty);
expect(
gateway.calls.where((call) => call.type != 'chat_sessions'),
isEmpty,
);
expect(find.text('Open to the right'), findsNothing);
expect(find.text('Open below'), findsNothing);
if (cupertino) {
await tester.tap(find.text('Cancel'));
} else {
await tester.tapAt(const Offset(5, 5));
}
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-row-s2')));
await tester.pumpAndSettle();
expect(opened.single['id'], 's2');
},
);
}
testWidgets('Material updates available directions on mounted rows', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close);
final right = <JsonMap>[];
final below = <JsonMap>[];
Future<void> show({required bool horizontal}) async {
final screen = ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
onOpenBeside: horizontal ? right.add : null,
onOpenBelow: horizontal ? null : below.add,
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(MaterialApp(home: screen));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
}
await show(horizontal: true);
expect(find.text('Open to the right'), findsOneWidget);
expect(find.text('Open below'), findsNothing);
await tester.tapAt(const Offset(5, 5));
await tester.pumpAndSettle();
await show(horizontal: false);
expect(find.text('Open to the right'), findsNothing);
expect(find.text('Open below'), findsOneWidget);
await tester.tap(find.text('Open below'));
await tester.pumpAndSettle();
expect(right, isEmpty);
expect(below.single['id'], 's2');
});
testWidgets('Material hides unavailable split choices and keeps row open', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close);
final opened = <JsonMap>[];
final screen = ChatSessionsScreen(
gateway: gateway,
onOpen: opened.add,
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(MaterialApp(home: screen));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
expect(find.text('Open to the right'), findsNothing);
expect(find.text('Open below'), findsNothing);
await tester.tapAt(const Offset(5, 5));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-row-s2')));
await tester.pumpAndSettle();
expect(opened.single['id'], 's2');
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_session_state.dart';
@@ -161,69 +160,53 @@ void main() {
semantics.dispose();
});
for (final cupertino in [false, true]) {
for (final brightness in Brightness.values) {
testWidgets(
'native metadata and state contrast on tinted rows $cupertino $brightness',
(tester) async {
late BuildContext context;
final theme = ThemeData(brightness: brightness);
final body = Builder(
builder: (value) {
context = value;
return const SizedBox();
},
for (final brightness in Brightness.values) {
testWidgets(
'native metadata and state contrast on tinted rows $brightness',
(tester) async {
late BuildContext context;
final theme = ThemeData(brightness: brightness);
final body = Builder(
builder: (value) {
context = value;
return const SizedBox();
},
);
await tester.pumpWidget(MaterialApp(theme: theme, home: body));
final surface = theme.colorScheme.surface;
for (final name in [
'red',
'orange',
'amber',
'green',
'teal',
'blue',
'purple',
'pink',
]) {
final color = chatColorShade(context, name)!;
final background = Color.alphaBlend(
color.withValues(alpha: brightness == Brightness.dark ? .30 : .22),
surface,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
home: body,
)
: MaterialApp(theme: theme, home: body),
);
final surface = cupertino
? CupertinoDynamicColor.resolve(
CupertinoTheme.of(context).scaffoldBackgroundColor,
context,
)
: theme.colorScheme.surface;
for (final name in [
'red',
'orange',
'amber',
'green',
'teal',
'blue',
'purple',
'pink',
for (final foreground in [
chatStateForeground(context),
chatMetadataForeground(context),
]) {
final color = chatColorShade(context, name)!;
final background = Color.alphaBlend(
color.withValues(
alpha: brightness == Brightness.dark ? .30 : .22,
),
surface,
final rendered = Color.alphaBlend(foreground, background);
final a = rendered.computeLuminance(),
b = background.computeLuminance();
final ratio = (a > b
? (a + .05) / (b + .05)
: (b + .05) / (a + .05));
expect(
ratio,
greaterThanOrEqualTo(4.5),
reason: '$name metadata contrast',
);
for (final foreground in [
chatStateForeground(context),
chatMetadataForeground(context),
]) {
final rendered = Color.alphaBlend(foreground, background);
final a = rendered.computeLuminance(),
b = background.computeLuminance();
final ratio = (a > b
? (a + .05) / (b + .05)
: (b + .05) / (a + .05));
expect(
ratio,
greaterThanOrEqualTo(4.5),
reason: '$name metadata contrast',
);
}
}
},
);
}
}
},
);
}
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -57,23 +56,6 @@ Future<void> pumpMaterialChat(
await tester.pumpAndSettle();
}
Future<void> pumpCupertinoChat(
WidgetTester tester,
FakeChatGateway gateway, {
ValueChanged<JsonMap>? onOpen,
}) async {
await tester.pumpWidget(
CupertinoApp(
home: ChatSessionsScreen(
gateway: gateway,
onOpen: onOpen ?? (_) {},
localStore: MemoryChatSessionLocalStore(),
),
),
);
await tester.pumpAndSettle();
}
/// The screen's iOS/macOS path: Cupertino controls under the app's ordinary
/// `MaterialApp` root, with no Material or CupertinoTheme ancestor.
Future<void> pumpIosMaterialChat(
@@ -35,29 +35,4 @@ void main() {
expect(find.text('Open chat'), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('Cupertino Undo bar fits 320px at 2x', (tester) async {
useSmallTextSurface(tester);
final gateway = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [
{'id': 's2', 'title': 'Open chat', 'directory': '/work'},
],
};
await pumpCupertinoChat(tester, gateway);
await tester.ensureVisible(find.byKey(const Key('chat-actions-s2')));
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Hide on this device'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-undo-hide')), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.tap(find.text('Undo'));
await tester.pumpAndSettle();
expect(find.text('Open chat'), findsOneWidget);
expect(tester.takeException(), isNull);
});
}
@@ -1,104 +1,80 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_harness_icon.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_list_cupertino.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_list_material.dart';
void main() {
for (final cupertino in [false, true]) {
for (final backend in ['opencode', 'claude']) {
testWidgets(
'$backend avatar beside title; the menu stars and unstars ($cupertino)',
(tester) async {
var starred = true;
final body = StatefulBuilder(
builder: (context, setState) {
final sections = [
(
title: 'Chats',
sessions: [
<String, dynamic>{
'id': 's',
'title': 'Harness chat',
'backend': backend,
'starred': starred,
},
],
),
];
void star(Map<String, dynamic> _) =>
setState(() => starred = !starred);
return cupertino
? CupertinoSessionList(
sections: sections,
emptyMessage: null,
duplicateTitles: const {},
onOpen: (_) {},
onRename: (_) {},
onClose: (_) {},
onReopen: (_) {},
onStar: star,
onHide: (_) {},
onClearSearch: null,
isUnseen: (_) => false,
errorFor: (_) => null,
)
: MaterialSessionList(
sections: sections,
emptyMessage: null,
duplicateTitles: const {},
onOpen: (_) {},
onRename: (_) {},
onClose: (_) {},
onReopen: (_) {},
onStar: star,
onHide: (_) {},
onClearSearch: null,
isUnseen: (_) => false,
errorFor: (_) => null,
);
},
for (final backend in ['opencode', 'claude']) {
testWidgets('$backend avatar beside title; the menu stars and unstars', (
tester,
) async {
var starred = true;
final body = StatefulBuilder(
builder: (context, setState) {
final sections = [
(
title: 'Chats',
sessions: [
<String, dynamic>{
'id': 's',
'title': 'Harness chat',
'backend': backend,
'starred': starred,
},
],
),
];
void star(Map<String, dynamic> _) =>
setState(() => starred = !starred);
return MaterialSessionList(
sections: sections,
emptyMessage: null,
duplicateTitles: const {},
onOpen: (_) {},
onRename: (_) {},
onClose: (_) {},
onReopen: (_) {},
onStar: star,
onHide: (_) {},
onClearSearch: null,
isUnseen: (_) => false,
errorFor: (_) => null,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body)),
);
await tester.pumpAndSettle();
final mark = find.byType(SessionHarnessIcon);
expect(mark, findsOneWidget);
expect(
tester.widget<ImageIcon>(find.byType(ImageIcon)).image,
AssetImage('assets/harnesses/$backend.png'),
);
final title = tester.getRect(find.textContaining('Harness chat'));
final icon = tester.getRect(mark);
expect(icon.right, lessThanOrEqualTo(title.left));
expect(icon.top, lessThan(title.bottom));
expect(icon.bottom, greaterThan(title.top));
expect(find.byKey(const Key('chat-row-starred')), findsOneWidget);
// Star and unstar live in the row's menu, not a separate button.
await tester.tap(find.byKey(const Key('chat-actions-s')));
await tester.pumpAndSettle();
await tester.tap(find.text('Unstar'));
await tester.pumpAndSettle();
expect(starred, isFalse);
expect(find.byKey(const Key('chat-row-starred')), findsNothing);
await tester.tap(find.byKey(const Key('chat-actions-s')));
await tester.pumpAndSettle();
await tester.tap(find.text('Star'));
await tester.pumpAndSettle();
expect(starred, isTrue);
expect(
find.byType(SessionHarnessIcon),
findsOneWidget,
reason: 'Changing favorite must not change harness identity',
);
expect(tester.takeException(), isNull);
},
);
}
await tester.pumpWidget(MaterialApp(home: Scaffold(body: body)));
await tester.pumpAndSettle();
final mark = find.byType(SessionHarnessIcon);
expect(mark, findsOneWidget);
expect(
tester.widget<ImageIcon>(find.byType(ImageIcon)).image,
AssetImage('assets/harnesses/$backend.png'),
);
final title = tester.getRect(find.textContaining('Harness chat'));
final icon = tester.getRect(mark);
expect(icon.right, lessThanOrEqualTo(title.left));
expect(icon.top, lessThan(title.bottom));
expect(icon.bottom, greaterThan(title.top));
expect(find.byKey(const Key('chat-row-starred')), findsOneWidget);
// Star and unstar live in the row's menu, not a separate button.
await tester.tap(find.byKey(const Key('chat-actions-s')));
await tester.pumpAndSettle();
await tester.tap(find.text('Unstar'));
await tester.pumpAndSettle();
expect(starred, isFalse);
expect(find.byKey(const Key('chat-row-starred')), findsNothing);
await tester.tap(find.byKey(const Key('chat-actions-s')));
await tester.pumpAndSettle();
await tester.tap(find.text('Star'));
await tester.pumpAndSettle();
expect(starred, isTrue);
expect(
find.byType(SessionHarnessIcon),
findsOneWidget,
reason: 'Changing favorite must not change harness identity',
);
expect(tester.takeException(), isNull);
});
}
}