App: chat colours, Ctrl+1-9 opens the Nth list item, starred chats alphabetical
A chat's colour is picked from its row menu (Colour...), a long-press or the chat information sheet. The list shows it as a leading bar, a faint row tint and a coloured avatar; the open chat shows a faint wash under its top bar. Shades are Cupertino's dynamic system colours and Material swatches tuned per brightness. Changes from other devices apply live. Ctrl+1...Ctrl+9 open the Nth item of the open tab's list (chats, runs, pipelines) in on-screen order, also while typing. Starred chats are sorted by name, case-insensitively, as one alphabetical group.
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
import 'package:flutter/material.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/features/chat/screen.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';
|
||||
|
||||
/// Recency order puts the plain chat first; the starred ones lead the list
|
||||
/// alphabetically all the same.
|
||||
class _Gateway extends FakeChatGateway {
|
||||
final rows = <JsonMap>[
|
||||
{'id': 'r', 'title': 'Recent', 'directory': '/w'},
|
||||
{'id': 'z', 'title': 'Zed', 'directory': '/w', 'starred': true},
|
||||
{
|
||||
'id': 'a',
|
||||
'title': 'apple',
|
||||
'directory': '/w',
|
||||
'starred': true,
|
||||
'color': 'green',
|
||||
},
|
||||
];
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type == 'chat_sessions') {
|
||||
return Future.value({
|
||||
'chat_sessions': [
|
||||
for (final row in rows) {...row},
|
||||
],
|
||||
});
|
||||
}
|
||||
if (type == 'chat_color') {
|
||||
final query = fields['chat_query'] as JsonMap;
|
||||
final row = rows.firstWhere((r) => r['id'] == query['session_id']);
|
||||
row['color'] = query['color'];
|
||||
calls.add((type: type, fields: fields));
|
||||
return Future.value({'chat_session': row});
|
||||
}
|
||||
if (type == 'chat_shells') return Future.value({'chat_shells': []});
|
||||
return super.call(type, fields);
|
||||
}
|
||||
}
|
||||
|
||||
Future<_Gateway> _pumpShell(
|
||||
WidgetTester tester,
|
||||
Size size, {
|
||||
TargetPlatform platform = TargetPlatform.android,
|
||||
Brightness brightness = Brightness.light,
|
||||
}) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = _Gateway()..history = (_) async => chatPage(const []);
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(platform: platform, brightness: brightness),
|
||||
home: AdaptiveShell(
|
||||
cupertino: platform == TargetPlatform.iOS,
|
||||
destination: AppDestination.chat,
|
||||
destinationBodies: {
|
||||
AppDestination.chat: (_) => ChatScreen(gateway: gateway),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return gateway;
|
||||
}
|
||||
|
||||
Future<void> _ctrl(WidgetTester tester, LogicalKeyboardKey digit) async {
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(digit);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Finder _thread(String id) => find.byKey(ValueKey('chat-thread-$id'));
|
||||
|
||||
void main() {
|
||||
testWidgets('starred chats lead the list alphabetically', (tester) async {
|
||||
await _pumpShell(tester, const Size(1280, 800));
|
||||
final apple = tester.getTopLeft(find.byKey(const Key('chat-row-a'))).dy;
|
||||
final zed = tester.getTopLeft(find.byKey(const Key('chat-row-z'))).dy;
|
||||
final recent = tester.getTopLeft(find.byKey(const Key('chat-row-r'))).dy;
|
||||
expect(apple, lessThan(zed));
|
||||
expect(zed, lessThan(recent));
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('Ctrl+N opens the Nth chat shown, also from the composer', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpShell(tester, const Size(1280, 800));
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit1);
|
||||
expect(_thread('a'), findsOneWidget, reason: 'Starred apple is first');
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit3);
|
||||
expect(_thread('r'), findsOneWidget);
|
||||
|
||||
// Typing in the composer: the chord still switches chats and types
|
||||
// nothing.
|
||||
final field = find.descendant(
|
||||
of: find.byKey(const ValueKey('chat-composer-r')),
|
||||
matching: find.byType(EditableText),
|
||||
);
|
||||
await tester.tap(field);
|
||||
await tester.enterText(field, 'draft');
|
||||
await tester.pump();
|
||||
expect(tester.widget<EditableText>(field).focusNode.hasFocus, isTrue);
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit2);
|
||||
expect(_thread('z'), findsOneWidget);
|
||||
expect(_thread('r'), findsNothing);
|
||||
|
||||
// Past the end nothing changes.
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit9);
|
||||
expect(_thread('z'), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('Ctrl+N opens the chat as its own page on a phone', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpShell(tester, const Size(390, 844));
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit2);
|
||||
expect(_thread('z'), findsOneWidget);
|
||||
final navigator = tester.state<NavigatorState>(
|
||||
find.byType(Navigator).first,
|
||||
);
|
||||
expect(navigator.canPop(), isTrue);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
for (final platform in [TargetPlatform.android, TargetPlatform.iOS]) {
|
||||
for (final brightness in Brightness.values) {
|
||||
final host =
|
||||
'${platform == TargetPlatform.iOS ? 'Cupertino' : 'Material'} '
|
||||
'${brightness.name}';
|
||||
testWidgets('$host: a coloured chat washes its top; the info sheet '
|
||||
'changes the colour', (tester) async {
|
||||
final gateway = await _pumpShell(
|
||||
tester,
|
||||
const Size(1280, 800),
|
||||
platform: platform,
|
||||
brightness: brightness,
|
||||
);
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit1);
|
||||
expect(_thread('a'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-color-wash')), findsOneWidget);
|
||||
final washRect = tester.getRect(
|
||||
find.byKey(const Key('chat-color-wash')),
|
||||
);
|
||||
final pane = tester.getRect(
|
||||
find.byKey(const ValueKey('chat-detail-pane')),
|
||||
);
|
||||
expect(washRect.top, pane.top);
|
||||
expect(washRect.height, lessThan(pane.height / 4));
|
||||
final box = tester.widget<DecoratedBox>(
|
||||
find.byKey(const Key('chat-color-wash')),
|
||||
);
|
||||
final gradient =
|
||||
(box.decoration as BoxDecoration).gradient! as LinearGradient;
|
||||
expect(gradient.colors.first.a, lessThanOrEqualTo(0.2));
|
||||
expect(gradient.colors.last.a, 0);
|
||||
|
||||
// A plain chat has none.
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit3);
|
||||
expect(find.byKey(const Key('chat-color-wash')), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-info')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-color-section')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-color-blue')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.calls.last.fields, {
|
||||
'chat_query': {'session_id': 'r', 'color': 'blue'},
|
||||
});
|
||||
await tester.tap(find.byKey(const Key('chat-info-close')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-color-wash')), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_colors.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_sessions.dart';
|
||||
|
||||
List<String> _ids(Iterable<JsonMap> rows) => [
|
||||
for (final row in rows) '${row['id']}',
|
||||
];
|
||||
|
||||
void main() {
|
||||
// Server recency order: the newest first.
|
||||
final rows = <JsonMap>[
|
||||
{'id': 'c1', 'title': 'zeta', 'directory': '/b', 'starred': true},
|
||||
{'id': 'c2', 'title': 'Recent', 'directory': '/a'},
|
||||
{'id': 'c3', 'title': 'Alpha', 'directory': '/b', 'starred': true},
|
||||
{'id': 'c4', 'title': 'Older', 'directory': '/b'},
|
||||
{'id': 'c6', 'title': 'beta', 'directory': '/a', 'starred': true},
|
||||
{'id': 'c5', 'title': 'Beta', 'directory': '/c', 'starred': true},
|
||||
{'id': 'c7', 'title': 'Oldest', 'directory': '/a'},
|
||||
{'id': 'c8', 'title': 'Done', 'closed_at': 1, 'starred': true},
|
||||
];
|
||||
|
||||
test('starred chats are alphabetical, ignoring case, ties by id', () {
|
||||
final sections = chatSessionSections(rows);
|
||||
expect(sections.map((s) => s.title), ['Starred', 'Chats', 'Closed']);
|
||||
expect(_ids(sections[0].sessions), ['c3', 'c5', 'c6', 'c1']);
|
||||
// The other sections keep the server's recency order.
|
||||
expect(_ids(sections[1].sessions), ['c2', 'c4', 'c7']);
|
||||
expect(_ids(sections[2].sessions), ['c8']);
|
||||
});
|
||||
|
||||
test('a starred chat keeps its place when another is used', () {
|
||||
final used = [rows[2], ...rows.where((r) => r['id'] != 'c3')];
|
||||
expect(
|
||||
_ids(chatSessionSections(used).first.sessions),
|
||||
_ids(chatSessionSections(rows).first.sessions),
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'list order: starred whole, then chats by directory, folded skipped',
|
||||
() {
|
||||
final sections = chatSessionSections(rows);
|
||||
expect(
|
||||
_ids(chatSessionsInListOrder(sections, isOpen: (t) => t != 'Closed')),
|
||||
['c3', 'c5', 'c6', 'c1', 'c2', 'c7', 'c4'],
|
||||
);
|
||||
expect(_ids(chatSessionsInListOrder(sections, isOpen: (_) => true)), [
|
||||
'c3',
|
||||
'c5',
|
||||
'c6',
|
||||
'c1',
|
||||
'c2',
|
||||
'c7',
|
||||
'c4',
|
||||
'c8',
|
||||
]);
|
||||
expect(
|
||||
_ids(chatSessionsInListOrder(sections, isOpen: (t) => t == 'Chats')),
|
||||
['c2', 'c7', 'c4'],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('only palette names are colours', () {
|
||||
expect(chatSessionColor({'color': 'teal'}), 'teal');
|
||||
expect(chatSessionColor({'color': '#ff0000'}), isNull);
|
||||
expect(chatSessionColor({}), isNull);
|
||||
expect(chatSessionColor(null), isNull);
|
||||
expect(chatColorNames, hasLength(8));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
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';
|
||||
import 'package:pipelines_app/features/chat/data/chat_repository.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_controller.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
|
||||
import 'package:pipelines_app/ui/layout/app_list_avatar.dart';
|
||||
import 'package:pipelines_app/ui/layout/app_list_row.dart';
|
||||
|
||||
import 'chat_test_harness.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
|
||||
/// A server whose list keeps each accepted colour, as the registry does.
|
||||
FakeChatGateway _gateway() {
|
||||
final rows = <JsonMap>[
|
||||
{'id': 's1', 'title': 'Teal chat', 'directory': '/w', 'color': 'teal'},
|
||||
{'id': 's2', 'title': 'Plain chat', 'directory': '/w'},
|
||||
];
|
||||
final gateway = FakeChatGateway();
|
||||
gateway.sessionsHandler = () async => {
|
||||
'chat_sessions': [
|
||||
for (final row in rows) {...row},
|
||||
],
|
||||
};
|
||||
gateway.actionHandler = (type, fields) async {
|
||||
if (type != 'chat_color') return const {};
|
||||
final query = fields['chat_query'] as JsonMap;
|
||||
final row = rows.firstWhere((r) => r['id'] == query['session_id']);
|
||||
final color = query['color'];
|
||||
color == null ? row.remove('color') : row['color'] = color;
|
||||
return {'chat_session': row};
|
||||
};
|
||||
return gateway;
|
||||
}
|
||||
|
||||
Future<void> _pump(
|
||||
WidgetTester tester,
|
||||
FakeChatGateway gateway, {
|
||||
required bool cupertino,
|
||||
required Brightness brightness,
|
||||
}) async {
|
||||
final screen = ChatSessionsScreen(
|
||||
gateway: gateway,
|
||||
onOpen: (_) {},
|
||||
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,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Finder _accent(String id) => find.descendant(
|
||||
of: find.byKey(Key('chat-row-$id')),
|
||||
matching: find.byKey(appListRowAccentKey),
|
||||
);
|
||||
|
||||
Color _accentColor(WidgetTester tester, String id) {
|
||||
final box = tester.widget<DecoratedBox>(_accent(id));
|
||||
final border = (box.decoration as BoxDecoration).border as BorderDirectional;
|
||||
return border.start.color;
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final brightness in Brightness.values) {
|
||||
final host = '${cupertino ? 'Cupertino' : '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: 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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 tester.longPress(find.text('Plain chat'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-color-sheet')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-color-red')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.lastFields('chat_color'), {
|
||||
'chat_query': {'session_id': 's2', 'color': 'red'},
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('the selected coloured row keeps its colour and selection', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(
|
||||
body: ChatSessionRow(
|
||||
session: const {'id': 's1', 'title': 'T', 'color': 'amber'},
|
||||
selected: true,
|
||||
onOpen: (_) {},
|
||||
onAction: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final surface = tester.widget<Material>(find.byKey(appListRowSurfaceKey));
|
||||
final context = tester.element(find.byType(ChatSessionRow));
|
||||
expect(
|
||||
surface.color,
|
||||
AppListRow.selectedColor(context, cupertino: false),
|
||||
reason: 'The selected fill, not the tint, marks the open row',
|
||||
);
|
||||
expect(find.byKey(appListRowAccentKey), findsOneWidget);
|
||||
});
|
||||
|
||||
group('controller', () {
|
||||
late FakeChatGateway gateway;
|
||||
late ChatSessionsController controller;
|
||||
|
||||
setUp(() async {
|
||||
gateway = _gateway();
|
||||
controller = ChatSessionsController(
|
||||
ChatRepository(gateway),
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
);
|
||||
await controller.refresh();
|
||||
});
|
||||
tearDown(() => controller.dispose());
|
||||
|
||||
JsonMap row(String id) =>
|
||||
controller.sessions.firstWhere((s) => s['id'] == id);
|
||||
|
||||
test('another device\'s change arrives live without a re-list', () async {
|
||||
final lists = gateway.count('chat_sessions');
|
||||
gateway.pushed.add({
|
||||
'type': 'chat_session_changed',
|
||||
'chat_session': {
|
||||
'id': 's2',
|
||||
'title': 'Plain chat',
|
||||
'color': 'pink',
|
||||
'starred': true,
|
||||
'starred_at': 5,
|
||||
},
|
||||
});
|
||||
await pumpEventQueue();
|
||||
expect(row('s2')['color'], 'pink');
|
||||
expect(row('s2')['starred'], isTrue);
|
||||
// An omitted colour is a cleared one.
|
||||
gateway.pushed.add({
|
||||
'type': 'chat_session_changed',
|
||||
'chat_session': {'id': 's1', 'title': 'Teal chat'},
|
||||
});
|
||||
await pumpEventQueue();
|
||||
expect(row('s1').containsKey('color'), isFalse);
|
||||
expect(gateway.count('chat_sessions'), lists);
|
||||
});
|
||||
|
||||
test('a refused colour is undone and the reason shown', () async {
|
||||
gateway.failures['chat_color'] = 'unknown chat colour';
|
||||
await controller.setColor('s2', 'blue');
|
||||
expect(row('s2')['color'], isNull);
|
||||
expect(controller.errorFor('s2'), contains('unknown chat colour'));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/shell/shell_list_shortcuts.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Ctrl+1…9 reach only the open tab\'s list; other chords pass', (
|
||||
tester,
|
||||
) async {
|
||||
final opened = <(AppDestination, int)>[];
|
||||
final field = FocusNode();
|
||||
addTearDown(field.dispose);
|
||||
Widget list(AppDestination destination) => ShellListShortcut(
|
||||
onOpenIndex: (index) {
|
||||
if (index > 4) return false;
|
||||
opened.add((destination, index));
|
||||
return true;
|
||||
},
|
||||
child: TextField(focusNode: field),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destination: AppDestination.runs,
|
||||
destinationBodies: {
|
||||
AppDestination.runs: (_) => list(AppDestination.runs),
|
||||
AppDestination.pipelines: (_) => list(AppDestination.pipelines),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
field.requestFocus();
|
||||
await tester.pump();
|
||||
|
||||
Future<void> press(
|
||||
LogicalKeyboardKey key, {
|
||||
List<LogicalKeyboardKey> held = const [LogicalKeyboardKey.controlLeft],
|
||||
}) async {
|
||||
for (final modifier in held) {
|
||||
await tester.sendKeyDownEvent(modifier);
|
||||
}
|
||||
await tester.sendKeyEvent(key);
|
||||
for (final modifier in held.reversed) {
|
||||
await tester.sendKeyUpEvent(modifier);
|
||||
}
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
await press(LogicalKeyboardKey.digit1);
|
||||
await press(LogicalKeyboardKey.digit5);
|
||||
expect(opened, [(AppDestination.runs, 0), (AppDestination.runs, 4)]);
|
||||
|
||||
opened.clear();
|
||||
await press(
|
||||
LogicalKeyboardKey.digit2,
|
||||
held: [LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft],
|
||||
);
|
||||
await press(
|
||||
LogicalKeyboardKey.digit2,
|
||||
held: [LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.metaLeft],
|
||||
);
|
||||
await press(LogicalKeyboardKey.digit2, held: const []);
|
||||
await press(LogicalKeyboardKey.digit0);
|
||||
expect(opened, isEmpty);
|
||||
expect(field.hasFocus, isTrue);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user