b59ab5fad7
- Colours: terminal background is the theme's lowest surface; the 16 ANSI colours come from a chosen palette (Theme colours, Classic, Calm, Vivid; Settings > Terminal > Colours, saved as `palette`) adjusted in lightness to the background: colours 4.5:1, bright ones lighter than normal, white light and black dark in both themes so white-on-red/blue/magenta and black-on-green/yellow/cyan (ls setuid, setgid, sticky) keep 3:1. Selection, find matches and the current match keep text at 4.5:1. - Bottom panel opens at 40% of the window, at least 16 rows, until dragged; the dragged height is remembered (old saved 300 px default reads as never resized). - Navigation rail scrolls its tabs (and below 240 px Settings too), so items never overlap under a tall panel. - Chat command cards: Expand / Collapse grows a live terminal to 60% of the window (finished output only to its rows); collapsed stays 12 rows. - Terminal tabs: ellipsised titles (220 px) with the whole title in the tooltip, selected tab filled, outlined and bold, close buttons are IconButtons (48 px touch, 40 px desktop). - Capture fixture: ?terminalColors=1 and ?terminalPalette=. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
352 lines
12 KiB
Dart
352 lines
12 KiB
Dart
import 'dart:ui' show Tristate;
|
|
|
|
import 'package:flutter/material.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/list_detail.dart';
|
|
import 'package:pipelines_app/shell/navigation_rail.dart';
|
|
import 'package:pipelines_app/shell/shell_bar.dart';
|
|
import 'package:pipelines_app/shell/windows/window_host.dart';
|
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
|
|
|
import 'windows/window_test_harness.dart';
|
|
|
|
/// On a wide window the destinations sit in a Material navigation rail at the
|
|
/// left edge (Settings pinned to its foot); narrower windows keep the floating
|
|
/// bar. The rail keeps the badges and the keys of the bar it replaces.
|
|
void main() {
|
|
Future<void> pumpShell(
|
|
WidgetTester tester, {
|
|
required double width,
|
|
double height = 800,
|
|
int runningRunCount = 0,
|
|
bool withPanes = false,
|
|
}) async {
|
|
tester.view.physicalSize = Size(width, height);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
final shell = AdaptiveShell(
|
|
destination: withPanes ? AppDestination.runs : AppDestination.pipelines,
|
|
runningRunCount: runningRunCount,
|
|
destinationBodies: {
|
|
AppDestination.pipelines: (_) => const Text('pipelines body'),
|
|
AppDestination.runs: (_) => withPanes
|
|
? ListDetailPanes(
|
|
list: const ShellBar(child: Text('runs list')),
|
|
detail: const Center(child: Text('runs detail')),
|
|
)
|
|
: const Text('runs body'),
|
|
AppDestination.chat: (_) => const Text('chat body'),
|
|
AppDestination.search: (_) => const Text('search body'),
|
|
AppDestination.settings: (_) => const Text('settings body'),
|
|
},
|
|
);
|
|
await tester.pumpWidget(MaterialApp(home: shell));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
Finder rail() => find.byType(NavigationRail);
|
|
|
|
Finder inRail(Finder finder) => find.descendant(of: rail(), matching: finder);
|
|
|
|
testWidgets('a wide window shows a labelled rail at the left edge, full '
|
|
'height, with Settings pinned to its foot', (tester) async {
|
|
await pumpShell(tester, width: 1000);
|
|
|
|
expect(rail(), findsOneWidget);
|
|
expect(find.byType(FloatingDestinationBar), findsNothing);
|
|
for (final label in ['Pipelines', 'Runs', 'Chat', 'Search', 'Settings']) {
|
|
expect(inRail(find.text(label)), findsOneWidget, reason: label);
|
|
}
|
|
final railRect = tester.getRect(rail());
|
|
expect(railRect.left, 0);
|
|
expect(railRect.top, 0);
|
|
expect(railRect.height, 800);
|
|
expect(railRect.width, kNavigationRailWidth);
|
|
|
|
// Settings sits below every tab, at the bottom of the rail.
|
|
final settings = tester.getRect(
|
|
find.byKey(const ValueKey('shell.destination.settings')),
|
|
);
|
|
final runs = tester.getRect(
|
|
find.byKey(const ValueKey('shell.destination.runs')),
|
|
);
|
|
expect(settings.top, greaterThan(runs.bottom));
|
|
expect(settings.bottom, closeTo(railRect.bottom, 1));
|
|
});
|
|
|
|
testWidgets('the rail marks the selected tab and one tap selects another', (
|
|
tester,
|
|
) async {
|
|
await pumpShell(tester, width: 1000);
|
|
expect(tester.widget<NavigationRail>(rail()).selectedIndex, 0);
|
|
expect(find.text('pipelines body'), findsOneWidget);
|
|
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.widget<NavigationRail>(rail()).selectedIndex, 1);
|
|
expect(find.text('runs body'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('Settings opens from the rail foot as a destination with no '
|
|
'Back and no tab is selected meanwhile', (tester) async {
|
|
final semantics = tester.ensureSemantics();
|
|
await pumpShell(tester, width: 1000);
|
|
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('settings body'), findsOneWidget);
|
|
expect(tester.widget<NavigationRail>(rail()).selectedIndex, isNull);
|
|
expect(
|
|
tester
|
|
.getSemantics(inRail(find.bySemanticsLabel('Settings')))
|
|
.flagsCollection
|
|
.isSelected,
|
|
Tristate.isTrue,
|
|
);
|
|
// Opened from its rail item, Settings is not a page: no Back.
|
|
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
|
|
// The Pipelines item leaves it for the Pipelines tab.
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.pipelines')));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.widget<NavigationRail>(rail()).selectedIndex, 0);
|
|
semantics.dispose();
|
|
});
|
|
|
|
testWidgets('the running count stays on the Runs item of the rail', (
|
|
tester,
|
|
) async {
|
|
await pumpShell(tester, width: 1000, runningRunCount: 3);
|
|
final badge = find.byKey(const ValueKey('shell.badge.runs.running'));
|
|
expect(
|
|
find.descendant(of: badge, matching: find.text('3')),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
find.descendant(
|
|
of: find.byKey(const ValueKey('shell.destination.runs')),
|
|
matching: badge,
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
});
|
|
|
|
testWidgets('a list and its open item lay out to the right of the rail', (
|
|
tester,
|
|
) async {
|
|
await pumpShell(tester, width: 1000, withPanes: true);
|
|
final list = tester.getRect(find.byKey(const ValueKey('list-detail-list')));
|
|
final body = tester.getRect(find.byKey(const ValueKey('list-detail-body')));
|
|
expect(list.left, closeTo(kNavigationRailSpace, 0.5));
|
|
expect(body.right, closeTo(1000, 0.5));
|
|
expect(body.left, greaterThan(list.right));
|
|
});
|
|
|
|
testWidgets('the rail appears from the threshold width, and below it the '
|
|
'floating bar stays', (tester) async {
|
|
expect(
|
|
kNavigationRailMinWindowWidth,
|
|
kListDetailMinWidth + kNavigationRailSpace,
|
|
);
|
|
|
|
await pumpShell(tester, width: kNavigationRailMinWindowWidth - 1);
|
|
expect(rail(), findsNothing);
|
|
expect(find.byType(FloatingDestinationBar), findsOneWidget);
|
|
|
|
await pumpShell(tester, width: kNavigationRailMinWindowWidth);
|
|
expect(rail(), findsOneWidget);
|
|
expect(find.byType(FloatingDestinationBar), findsNothing);
|
|
});
|
|
|
|
testWidgets('at the threshold the body beside the rail meets the list-detail '
|
|
'minimum, so the list sits beside its detail', (tester) async {
|
|
await pumpShell(
|
|
tester,
|
|
width: kNavigationRailMinWindowWidth,
|
|
withPanes: true,
|
|
);
|
|
final list = tester.getRect(find.byKey(const ValueKey('list-detail-list')));
|
|
final body = tester.getRect(find.byKey(const ValueKey('list-detail-body')));
|
|
// The list and detail fill the window beside the rail, at the split
|
|
// threshold: the list starts after the rail and the detail ends at the
|
|
// window's right edge, with the detail to the right of the list.
|
|
expect(list.left, closeTo(kNavigationRailSpace, 0.5));
|
|
expect(body.right, closeTo(kNavigationRailMinWindowWidth, 0.5));
|
|
expect(body.left, greaterThan(list.right));
|
|
});
|
|
|
|
testWidgets('a phone shows the navigation bar with Settings and no rail', (
|
|
tester,
|
|
) async {
|
|
await pumpShell(tester, width: 390);
|
|
expect(rail(), findsNothing);
|
|
expect(find.byType(NavigationBar), findsOneWidget);
|
|
expect(
|
|
find.byKey(const ValueKey('shell.destination.settings')),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.byType(FloatingDestinationBar), findsNothing);
|
|
});
|
|
|
|
testWidgets('a narrow window below the rail keeps the floating bar, no rail '
|
|
'and no navigation bar', (tester) async {
|
|
// 640 is wide enough for the list beside its open item, which keeps the
|
|
// floating bar under the list column.
|
|
await pumpShell(tester, width: 640);
|
|
expect(rail(), findsNothing);
|
|
expect(find.byType(NavigationBar), findsNothing);
|
|
expect(find.byType(FloatingDestinationBar), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('floating windows keep to the right of the rail on a wide '
|
|
'window, and use the whole window without one', (tester) async {
|
|
final manager = probeManager();
|
|
manager.open('probe', 'a');
|
|
Future<void> pumpWindows(double width) async {
|
|
tester.view.physicalSize = Size(width, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
const SizedBox.expand(),
|
|
Positioned.fill(
|
|
child: WindowHost(manager: manager, reservesRail: true),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
await pumpWindows(1280);
|
|
// The probe window opens at x=100; beside the rail it starts after it.
|
|
expect(
|
|
windowRect(tester, 'Probe a').left,
|
|
closeTo(100 + kNavigationRailSpace, 0.5),
|
|
);
|
|
await pumpWindows(500);
|
|
expect(windowRect(tester, 'Probe a').left, closeTo(100, 0.5));
|
|
});
|
|
|
|
testWidgets('crossing the rail threshold keeps the destination mounted and '
|
|
'its state', (tester) async {
|
|
tester.view.physicalSize = Size(kNavigationRailMinWindowWidth - 1, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: AdaptiveShell(
|
|
destination: AppDestination.runs,
|
|
destinationBodies: {AppDestination.runs: (_) => const _Counter()},
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(const ValueKey('counter.increment')));
|
|
await tester.pump();
|
|
final state = tester.state(find.byType(_Counter));
|
|
|
|
for (final width in [kNavigationRailMinWindowWidth, 390.0]) {
|
|
tester.view.physicalSize = Size(width, 800);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.state(find.byType(_Counter)),
|
|
same(state),
|
|
reason: '$width',
|
|
);
|
|
expect(find.text('count 1'), findsOneWidget, reason: '$width');
|
|
}
|
|
});
|
|
|
|
// A tall terminal panel leaves the app (and the rail beside it) as little
|
|
// as 160 px: the tabs scroll, and below the pinned height Settings scrolls
|
|
// with them, so no two items ever overlap.
|
|
for (final height in const [160.0, 200.0, 260.0, 340.0, 420.0, 800.0]) {
|
|
testWidgets('a rail ${height.round()} px tall never overlaps its items', (
|
|
tester,
|
|
) async {
|
|
await pumpShell(tester, width: 1000, height: height);
|
|
expect(tester.takeException(), isNull);
|
|
final keys = [
|
|
for (final destination in [
|
|
...shellTabDestinations,
|
|
AppDestination.settings,
|
|
])
|
|
ValueKey('shell.destination.${destination.name}'),
|
|
];
|
|
// What shows of each: the scrolling group clips what is scrolled
|
|
// away.
|
|
final viewport = tester.getRect(
|
|
find.descendant(
|
|
of: find.byType(NavigationRail),
|
|
matching: find.byType(SingleChildScrollView),
|
|
),
|
|
);
|
|
Rect shown(Key key) {
|
|
final finder = find.byKey(key).first;
|
|
final rect = tester.getRect(finder);
|
|
final scrolls = find
|
|
.ancestor(of: finder, matching: find.byType(SingleChildScrollView))
|
|
.evaluate()
|
|
.isNotEmpty;
|
|
return scrolls ? rect.intersect(viewport) : rect;
|
|
}
|
|
|
|
final rects = [for (final key in keys) shown(key)];
|
|
for (var i = 0; i < rects.length; i++) {
|
|
for (var j = i + 1; j < rects.length; j++) {
|
|
expect(
|
|
rects[i].overlaps(rects[j]) &&
|
|
!rects[i].isEmpty &&
|
|
!rects[j].isEmpty,
|
|
isFalse,
|
|
reason: '${keys[i]} and ${keys[j]} at $height',
|
|
);
|
|
}
|
|
}
|
|
// Settings stays reachable: scrolled to, it is on screen and tappable.
|
|
await tester.dragUntilVisible(
|
|
find.byKey(keys.last),
|
|
find.descendant(
|
|
of: find.byType(NavigationRail),
|
|
matching: find.byType(SingleChildScrollView),
|
|
),
|
|
const Offset(0, -40),
|
|
);
|
|
expect(
|
|
tester.getRect(find.byKey(keys.last)).bottom,
|
|
lessThanOrEqualTo(height + 0.5),
|
|
);
|
|
});
|
|
}
|
|
}
|
|
|
|
class _Counter extends StatefulWidget {
|
|
const _Counter();
|
|
|
|
@override
|
|
State<_Counter> createState() => _CounterState();
|
|
}
|
|
|
|
class _CounterState extends State<_Counter> {
|
|
int _count = 0;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Center(
|
|
child: TextButton(
|
|
key: const ValueKey('counter.increment'),
|
|
onPressed: () => setState(() => _count += 1),
|
|
child: Text('count $_count'),
|
|
),
|
|
);
|
|
}
|