Highlight the active chat in session lists

This commit is contained in:
2026-10-25 17:17:43 +00:00
parent 7fe106b426
commit a58d820d43
8 changed files with 268 additions and 35 deletions
@@ -51,6 +51,10 @@ void main() {
'at $size', (tester) async {
await _pumpShell(tester, size);
expect(find.text('Select a chat to open it here.'), findsOneWidget);
expect(
tester.widget<ListTile>(find.byKey(const Key('chat-row-a'))).selected,
isFalse,
);
await tester.tap(find.text('First chat'));
await tester.pumpAndSettle();
@@ -59,6 +63,14 @@ void main() {
expect(find.byType(NavigationRail), findsOneWidget);
expect(find.byKey(const ValueKey('chat-thread-a')), findsOneWidget);
expect(find.text('Second chat'), findsOneWidget);
expect(
tester.widget<ListTile>(find.byKey(const Key('chat-row-a'))).selected,
isTrue,
);
expect(
tester.widget<ListTile>(find.byKey(const Key('chat-row-b'))).selected,
isFalse,
);
// The shell bar keeps the list's controls; the pane bar has the chat's
// title and no Back.
expect(find.byKey(const Key('chat-new-chat')), findsOneWidget);
@@ -76,6 +88,14 @@ void main() {
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('chat-thread-a')), findsNothing);
expect(find.byKey(const ValueKey('chat-thread-b')), findsOneWidget);
expect(
tester.widget<ListTile>(find.byKey(const Key('chat-row-a'))).selected,
isFalse,
);
expect(
tester.widget<ListTile>(find.byKey(const Key('chat-row-b'))).selected,
isTrue,
);
expect(navigator.canPop(), isFalse);
// The rail still switches destinations with a chat open.
@@ -98,6 +118,13 @@ void main() {
expect(findNativeBack(), findsOneWidget);
expect(find.byType(NavigationBar), findsNothing);
await tester.pageBack();
await tester.pumpAndSettle();
expect(
tester.widget<ListTile>(find.byKey(const Key('chat-row-a'))).selected,
isFalse,
);
await tester.pumpWidget(const SizedBox.shrink());
});
}
@@ -0,0 +1,113 @@
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/features/chat/ui/sessions/chat_sessions_screen.dart';
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']),
);
},
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
home: screen,
)
: 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,
);
if (cupertino) {
final tile = tester.widget<CupertinoListTile>(row);
expect(
tile.backgroundColor,
active
? CupertinoColors.tertiarySystemFill.resolveFrom(
tester.element(row),
)
: isNull,
);
} else {
final tile = tester.widget<ListTile>(row);
expect(tile.selected, active);
expect(
tile.selectedTileColor,
Theme.of(tester.element(row)).colorScheme.secondaryContainer,
);
}
}
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);
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();
}
},
);
}
}
}