Merge branch 'main' into worktree-agent-a349550966b0e2bad
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);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/shell/shell_design_shortcut.dart';
|
||||
|
||||
KeyDownEvent _down(PhysicalKeyboardKey physical, LogicalKeyboardKey logical) =>
|
||||
KeyDownEvent(
|
||||
physicalKey: physical,
|
||||
logicalKey: logical,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
|
||||
void main() {
|
||||
test('Alt+L alone is the design switcher, Option+L by position', () {
|
||||
bool chord(Set<LogicalKeyboardKey> held, KeyEvent event) =>
|
||||
shellDesignShortcut(event, _FakeKeyboard(held));
|
||||
final l = _down(PhysicalKeyboardKey.keyL, LogicalKeyboardKey.keyL);
|
||||
const alt = LogicalKeyboardKey.altLeft;
|
||||
expect(chord({alt}, l), isTrue);
|
||||
expect(chord({}, l), isFalse);
|
||||
expect(chord({alt, LogicalKeyboardKey.shiftLeft}, l), isFalse);
|
||||
expect(chord({alt, LogicalKeyboardKey.controlLeft}, l), isFalse);
|
||||
expect(chord({alt, LogicalKeyboardKey.metaLeft}, l), isFalse);
|
||||
expect(chord({LogicalKeyboardKey.controlLeft}, l), isFalse);
|
||||
expect(chord({LogicalKeyboardKey.metaLeft}, l), isFalse);
|
||||
// Option+L types ¬ on a Mac.
|
||||
final symbol = _down(
|
||||
PhysicalKeyboardKey.keyL,
|
||||
const LogicalKeyboardKey(0x00ac),
|
||||
);
|
||||
expect(chord({alt}, symbol), isTrue);
|
||||
final k = _down(PhysicalKeyboardKey.keyK, LogicalKeyboardKey.keyK);
|
||||
expect(chord({alt}, k), isFalse);
|
||||
final up = KeyUpEvent(
|
||||
physicalKey: PhysicalKeyboardKey.keyL,
|
||||
logicalKey: LogicalKeyboardKey.keyL,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
expect(chord({alt}, up), isFalse);
|
||||
expect(shellDesignShortcutLabel(TargetPlatform.macOS), 'Option+L');
|
||||
expect(shellDesignShortcutLabel(TargetPlatform.linux), 'Alt+L');
|
||||
});
|
||||
}
|
||||
|
||||
class _FakeKeyboard extends HardwareKeyboard {
|
||||
_FakeKeyboard(this.pressed);
|
||||
final Set<LogicalKeyboardKey> pressed;
|
||||
@override
|
||||
bool isLogicalKeyPressed(LogicalKeyboardKey key) => pressed.contains(key);
|
||||
}
|
||||
@@ -66,6 +66,33 @@ void main() {
|
||||
expect(designs.design, AppDesign.standard);
|
||||
});
|
||||
|
||||
test('a preview shows a design without storing it; select ends it', () async {
|
||||
final store = MemoryAppDesignStore('default');
|
||||
final designs = AppDesignController(store: store);
|
||||
await designs.restore();
|
||||
var notified = 0;
|
||||
designs.addListener(() => notified++);
|
||||
designs.preview(AppDesign.paper);
|
||||
expect(designs.design, AppDesign.paper);
|
||||
expect(designs.chosen, AppDesign.standard);
|
||||
expect(notified, 1);
|
||||
designs.preview(AppDesign.paper);
|
||||
expect(notified, 1);
|
||||
designs.preview(null);
|
||||
expect(designs.design, AppDesign.standard);
|
||||
expect(notified, 2);
|
||||
expect(store.id, 'default');
|
||||
|
||||
designs.preview(AppDesign.terminal);
|
||||
await designs.select(AppDesign.terminal);
|
||||
expect(notified, 3);
|
||||
expect(designs.design, AppDesign.terminal);
|
||||
expect(store.id, 'terminal');
|
||||
designs.preview(null);
|
||||
expect(designs.design, AppDesign.terminal);
|
||||
expect(notified, 3);
|
||||
});
|
||||
|
||||
test('shared preferences keep the choice per device', () async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
const store = SharedPreferencesAppDesignStore();
|
||||
|
||||
Reference in New Issue
Block a user