4268ce20eb
The chat switcher's popup and keys over the AppDesign registry: filter, Ctrl+N/P and arrows preview the selected design app-wide without storing it (AppDesignController.preview), Enter keeps it, Esc or Alt+L again returns to the design it opened with. The current design is checked. Listed in Settings -> Keyboard shortcuts and the cheatsheet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
220 lines
7.2 KiB
Dart
220 lines
7.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/settings/design_quick_switch.dart';
|
|
import 'package:pipelines_app/features/settings/design_quick_switch_match.dart';
|
|
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
|
import 'package:pipelines_app/shell/destination.dart';
|
|
import 'package:pipelines_app/ui/input/keyboard_owner.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_design_tokens.dart';
|
|
|
|
final _field = find.byKey(const Key('design-quick-switch-field'));
|
|
Finder _row(AppDesign design) =>
|
|
find.byKey(Key('design-quick-switch-row-${design.id}'));
|
|
bool _selected(WidgetTester tester, AppDesign design) =>
|
|
tester.widget<ListTile>(_row(design)).selected;
|
|
|
|
class _App {
|
|
_App(this.store) : designs = AppDesignController(store: store);
|
|
final MemoryAppDesignStore store;
|
|
final AppDesignController designs;
|
|
final terminal = FocusNode();
|
|
|
|
/// The design the app's theme is drawn in, read from the shell's context.
|
|
AppDesign shown(WidgetTester tester) =>
|
|
AppDesignTokens.of(tester.element(find.byKey(const Key('body')))).design;
|
|
}
|
|
|
|
Future<_App> _pump(WidgetTester tester, {String? stored}) async {
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
final app = _App(MemoryAppDesignStore(stored));
|
|
addTearDown(app.terminal.dispose);
|
|
await app.designs.restore();
|
|
final toggle = DesignQuickSwitchToggle(designs: app.designs);
|
|
await tester.pumpWidget(
|
|
ListenableBuilder(
|
|
listenable: app.designs,
|
|
builder: (context, _) => MaterialApp(
|
|
theme: app.designs.design.light(),
|
|
themeAnimationDuration: Duration.zero,
|
|
home: AdaptiveShell(
|
|
onDesignSwitch: toggle.toggle,
|
|
destinationBodies: {
|
|
AppDestination.pipelines: (_) => TypingSurface(
|
|
child: Focus(
|
|
focusNode: app.terminal,
|
|
child: const Text('body', key: Key('body')),
|
|
),
|
|
),
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
return app;
|
|
}
|
|
|
|
Future<void> _chord(
|
|
WidgetTester tester,
|
|
LogicalKeyboardKey modifier,
|
|
LogicalKeyboardKey key,
|
|
) async {
|
|
await tester.sendKeyDownEvent(modifier);
|
|
await tester.sendKeyEvent(key);
|
|
await tester.sendKeyUpEvent(modifier);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
Future<void> _altL(WidgetTester tester) =>
|
|
_chord(tester, LogicalKeyboardKey.altLeft, LogicalKeyboardKey.keyL);
|
|
|
|
void main() {
|
|
test('a query narrows the designs by name, then summary', () {
|
|
expect(designQuickSwitchMatches(AppDesign.values, ''), AppDesign.values);
|
|
expect(designQuickSwitchMatches(AppDesign.values, 'PAP'), [
|
|
AppDesign.paper,
|
|
]);
|
|
expect(designQuickSwitchMatches(AppDesign.values, 'mono'), [
|
|
AppDesign.terminal,
|
|
]);
|
|
expect(designQuickSwitchMatches(AppDesign.values, 'paper serif'), [
|
|
AppDesign.paper,
|
|
]);
|
|
expect(designQuickSwitchMatches(AppDesign.values, 'zzz'), isEmpty);
|
|
});
|
|
|
|
testWidgets('Alt+L lists every design with its swatch, the current one '
|
|
'marked and selected; Alt+L again closes it', (tester) async {
|
|
final app = await _pump(tester);
|
|
await _altL(tester);
|
|
expect(_field, findsOneWidget);
|
|
for (final design in AppDesign.values) {
|
|
expect(_row(design), findsOneWidget);
|
|
expect(
|
|
find.descendant(of: _row(design), matching: find.text(design.label)),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
find.descendant(
|
|
of: _row(design),
|
|
matching: find.text(design.description),
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
}
|
|
expect(find.byType(ListTile), findsNWidgets(AppDesign.values.length));
|
|
expect(
|
|
find.descendant(
|
|
of: _row(AppDesign.terminal),
|
|
matching: find.byKey(const Key('design-quick-switch-current')),
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.byKey(const Key('design-quick-switch-current')), findsOne);
|
|
expect(_selected(tester, AppDesign.terminal), isTrue);
|
|
|
|
await _altL(tester);
|
|
expect(_field, findsNothing);
|
|
expect(app.shown(tester), AppDesign.terminal);
|
|
});
|
|
|
|
testWidgets('Ctrl+N and Ctrl+P preview live without storing; Esc goes back '
|
|
'to the design it opened with', (tester) async {
|
|
final app = await _pump(tester);
|
|
await _altL(tester);
|
|
final order = AppDesign.values;
|
|
final start = order.indexOf(AppDesign.terminal);
|
|
final next = order[(start + 1) % order.length];
|
|
final previous = order[(start - 1) % order.length];
|
|
|
|
await _chord(
|
|
tester,
|
|
LogicalKeyboardKey.controlLeft,
|
|
LogicalKeyboardKey.keyN,
|
|
);
|
|
expect(_selected(tester, next), isTrue);
|
|
expect(app.shown(tester), next);
|
|
expect(app.designs.chosen, AppDesign.terminal);
|
|
expect(app.store.id, isNull);
|
|
|
|
await _chord(
|
|
tester,
|
|
LogicalKeyboardKey.controlLeft,
|
|
LogicalKeyboardKey.keyP,
|
|
);
|
|
await _chord(
|
|
tester,
|
|
LogicalKeyboardKey.controlLeft,
|
|
LogicalKeyboardKey.keyP,
|
|
);
|
|
expect(_selected(tester, previous), isTrue);
|
|
expect(app.shown(tester), previous);
|
|
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
|
await tester.pumpAndSettle();
|
|
expect(_field, findsNothing);
|
|
expect(app.shown(tester), AppDesign.terminal);
|
|
expect(app.designs.design, AppDesign.terminal);
|
|
expect(app.store.id, isNull);
|
|
});
|
|
|
|
testWidgets('a filter selects the best match and Enter keeps it', (
|
|
tester,
|
|
) async {
|
|
final app = await _pump(tester, stored: AppDesign.standard.id);
|
|
await _altL(tester);
|
|
expect(_selected(tester, AppDesign.standard), isTrue);
|
|
|
|
await tester.enterText(_field, 'pap');
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(ListTile), findsOneWidget);
|
|
expect(_selected(tester, AppDesign.paper), isTrue);
|
|
expect(app.shown(tester), AppDesign.paper);
|
|
expect(app.store.id, AppDesign.standard.id);
|
|
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pumpAndSettle();
|
|
expect(_field, findsNothing);
|
|
expect(app.shown(tester), AppDesign.paper);
|
|
expect(app.designs.chosen, AppDesign.paper);
|
|
expect(app.store.id, AppDesign.paper.id);
|
|
|
|
// Reopened, Paper is now the marked one.
|
|
await _altL(tester);
|
|
expect(
|
|
find.descendant(
|
|
of: _row(AppDesign.paper),
|
|
matching: find.byKey(const Key('design-quick-switch-current')),
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
});
|
|
|
|
testWidgets('a filter matching nothing shows the design it opened with', (
|
|
tester,
|
|
) async {
|
|
final app = await _pump(tester);
|
|
await _altL(tester);
|
|
await tester.enterText(_field, 'pap');
|
|
await tester.pumpAndSettle();
|
|
expect(app.shown(tester), AppDesign.paper);
|
|
await tester.enterText(_field, 'zzz');
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('design-quick-switch-empty')), findsOne);
|
|
expect(app.shown(tester), AppDesign.terminal);
|
|
});
|
|
|
|
testWidgets('the terminal keeps Alt+L', (tester) async {
|
|
final app = await _pump(tester);
|
|
app.terminal.requestFocus();
|
|
await tester.pump();
|
|
await _altL(tester);
|
|
expect(_field, findsNothing);
|
|
});
|
|
}
|