Merge branch 'main' into worktree-agent-a1b6c249e2bec6658
# Conflicts: # app/lib/ui/theme/app_design_controller.dart
This commit is contained in:
@@ -103,7 +103,11 @@ void main() {
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
final send = find.byKey(const Key('chat-composer-primary'));
|
||||
expect(tester.widget<IconButton>(send).style, isNull);
|
||||
// Only the fixed size is set: no colours, so the host's filled colours
|
||||
// apply.
|
||||
final style = tester.widget<IconButton>(send).style!;
|
||||
expect(style.backgroundColor, isNull);
|
||||
expect(style.foregroundColor, isNull);
|
||||
expect(chatSchemeOf(tester.element(send), null), isNull);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user