Merge commit '6569908f9139eef75c52e73db3402bebc2e2f5b6' into pipelines/run-20261112-1022-obvious-ways-to-start-a-run-f077

This commit is contained in:
2026-11-12 11:04:22 +00:00
31 changed files with 1396 additions and 276 deletions
@@ -0,0 +1,57 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_adaptive.dart';
import 'package:pipelines_app/features/terminal/terminal_shortcut_bubble.dart';
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import 'pipelines_app_test.dart' show pumpApp;
/// On a phone the Chat tab has exactly one terminal entry: the bar's own
/// Terminal action. The floating shortcut bubble must not appear over the
/// chat list's header, nor beside an open chat's bar that already has it.
Future<void> _pumpAt(WidgetTester tester, String location) async {
tester.view.physicalSize = const Size(430, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse(location)),
);
addTearDown(provider.dispose);
await pumpApp(tester, channel: channel, client: client, provider: provider);
await tester.pump();
await tester.pump();
}
/// The bar's Terminal actions on screen (a [ChatBarAction] carrying the
/// terminal toggle's label).
Finder _barTerminal() => find.byWidgetPredicate(
(w) => w is ChatBarAction && w.label == TerminalToggleButton.label,
);
void main() {
testWidgets('phone chat list: one terminal entry, no floating bubble', (
tester,
) async {
await _pumpAt(tester, '/chat');
expect(find.byType(TerminalShortcutBubble), findsNothing);
expect(_barTerminal(), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('phone open chat: one terminal entry, no floating bubble', (
tester,
) async {
await _pumpAt(tester, '/chat/abc123');
expect(find.byType(TerminalShortcutBubble), findsNothing);
expect(_barTerminal(), findsOneWidget);
expect(tester.takeException(), isNull);
});
}
+50 -66
View File
@@ -7,15 +7,16 @@ import 'package:pipelines_app/features/settings/settings_screen.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../bar_action.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import '../features/pipelines/fixtures.dart';
import 'pipelines_app_test.dart' show webServer;
import 'pipelines_replies.dart';
/// Settings is not a tab: it opens as a page (from the gear in the Pipelines
/// bar on a phone, from the rail's foot on a wide window), keeps its
/// `/settings` route (and deep link), and closes back to Pipelines. The tab bar keeps Pipelines selected meanwhile.
/// Settings is a navigation destination: the phone's bar and the wide rail
/// offer it, and the floating tab bar's width (between the list-detail and rail
/// widths) keeps the Pipelines bar's gear. Settings reached from a nav control
/// has no Back; reached as a pushed page (the gear, the /settings deep link) it
/// has Back, which returns to Pipelines.
void main() {
Future<PlatformRouteInformationProvider> pumpApp(
WidgetTester tester, {
@@ -50,61 +51,47 @@ void main() {
int selectedTab(WidgetTester tester) =>
tester.widget<NavigationBar>(find.byType(NavigationBar)).selectedIndex;
// A phone's Pipelines bar keeps the gear; a wide window's rail offers
// Settings instead (see the wide test below).
for (final size in [const Size(390, 844)]) {
testWidgets('${size.width}: the Pipelines bar gear opens Settings '
'as a page and Back returns', (tester) async {
final provider = await pumpApp(
tester,
location: '/pipelines',
size: size,
);
// Four tabs and Settings as the bar's last destination.
expect(
tester
.widget<NavigationBar>(find.byType(NavigationBar))
.destinations
.map((item) => (item as NavigationDestination).label),
['Pipelines', 'Runs', 'Chat', 'Search', 'Settings'],
);
expect(
find.byKey(const ValueKey('shell.destination.settings')),
findsOneWidget,
);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
testWidgets('390: the bar offers Settings and no gear; Settings from the bar '
'has no Back and the Pipelines item leaves it', (tester) async {
final provider = await pumpApp(
tester,
location: '/pipelines',
size: const Size(390, 844),
);
// Four tabs and Settings as the bar's last destination.
expect(
tester
.widget<NavigationBar>(find.byType(NavigationBar))
.destinations
.map((item) => (item as NavigationDestination).label),
['Pipelines', 'Runs', 'Chat', 'Search', 'Settings'],
);
expect(find.byKey(const Key('pipelines-open-settings')), findsNothing);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
await tapBarAction(
tester,
find.byKey(const Key('pipelines-open-settings')),
'Settings',
);
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/settings');
expect(find.byType(SettingsScreen), findsOneWidget);
expect(find.text('Quick switch animation'), findsOneWidget);
await openSettingsSection(tester, 'Connection');
expect(find.text('Server URL'), findsOneWidget);
// A page of Pipelines: Back in its bar, Settings selected in the bar.
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
expect(find.byKey(const ValueKey('shell.search')), findsNothing);
expect(selectedTab(tester), 4);
expect(tester.takeException(), isNull);
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/settings');
expect(find.byType(SettingsScreen), findsOneWidget);
expect(find.text('Quick switch animation'), findsOneWidget);
await openSettingsSection(tester, 'Connection');
expect(find.text('Server URL'), findsOneWidget);
// A destination: no Back, and Settings is the selected item of the bar.
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
expect(find.byKey(const ValueKey('shell.search')), findsNothing);
expect(selectedTab(tester), 4);
expect(tester.takeException(), isNull);
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/pipelines');
expect(find.byKey(const Key('pipelines-open-settings')), findsWidgets);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
}
await tester.tap(find.byKey(const ValueKey('shell.destination.pipelines')));
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/pipelines');
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
testWidgets('1200: the rail offers Settings at its foot and no gear is '
'left in the Pipelines toolbar; Settings is a page and Back returns', (
'left in the Pipelines toolbar; Settings from the rail has no Back', (
tester,
) async {
final provider = await pumpApp(
@@ -129,21 +116,19 @@ void main() {
}
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
await tester.pump();
await tester.pump();
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/settings');
expect(find.byType(SettingsScreen), findsOneWidget);
// Settings is a page of Pipelines: the rail marks Settings, not a tab.
// Settings is a destination: the rail marks Settings, not a tab.
expect(
tester.widget<NavigationRail>(find.byType(NavigationRail)).selectedIndex,
isNull,
);
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
expect(tester.takeException(), isNull);
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pump();
await tester.pump();
await tester.tap(find.byKey(const ValueKey('shell.destination.pipelines')));
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/pipelines');
expect(find.byKey(const Key('pipelines-open-settings')), findsNothing);
expect(
@@ -154,8 +139,8 @@ void main() {
await tester.pump();
});
testWidgets('the /settings deep link opens the Settings page and '
'the system Back closes it to Pipelines', (tester) async {
testWidgets('the /settings deep link opens Settings as a pushed page with '
'Back, and the system Back closes it to Pipelines', (tester) async {
final provider = await pumpApp(
tester,
location: '/settings',
@@ -168,8 +153,7 @@ void main() {
final handled = await tester.binding.handlePopRoute();
expect(handled, isTrue, reason: 'Back closes the page, not the app');
await tester.pump();
await tester.pump();
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/pipelines');
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
@@ -7,7 +7,6 @@ import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../bar_action.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import '../features/pipelines/fixtures.dart';
import 'pipelines_app_test.dart' show webServer, requestOf;
@@ -45,11 +44,7 @@ void main() {
);
await replyPipelines(tester, channel, PipelineFixture());
await tapBarAction(
tester,
find.byKey(const Key('pipelines-open-settings')),
'Settings',
);
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/settings');
@@ -11,7 +11,6 @@ import 'package:pipelines_app/features/settings/settings_screen.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
import 'package:pipelines_app/shell/destination.dart';
import '../bar_action.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import '../features/pipelines/fixtures.dart';
import 'pipelines_app_test.dart' show webServer;
@@ -63,13 +62,10 @@ void main() {
final app = await mount(tester);
await replyPipelines(tester, app.channel, PipelineFixture());
await tester.pumpAndSettle();
await tapBarAction(
tester,
find.byKey(const Key('pipelines-open-settings')),
'Settings',
);
await tester.pumpAndSettle();
await tab(tester, 'settings');
expect(app.provider.value.uri.path, '/settings');
// A destination opened from its nav item: no Back.
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
final settingsState = tester.state(find.byType(SettingsScreen));
await tab(tester, 'chat');
expect(app.provider.value.uri.path, '/chat');
@@ -77,19 +73,12 @@ void main() {
expect(app.provider.value.uri.path, '/settings');
expect(tester.state(find.byType(SettingsScreen)), same(settingsState));
await tab(tester, 'pipelines');
expect(
app.provider.value.uri.path,
'/settings',
reason: 'tab retap is not Back',
);
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(
app.provider.value.uri.path,
'/pipelines',
reason: 'explicit Back still exits Settings',
reason: 'the Pipelines item leaves Settings for its list',
);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
expect(tester.takeException(), isNull);
});
testWidgets(
@@ -191,8 +180,8 @@ void main() {
await tab(tester, 'pipelines');
expect(app.provider.value.uri.path, '/settings');
expect(tester.widget<PipelinesScreen>(hidden).initialPipelineId, 1);
await tester.tap(find.byKey(const Key('shell.back')));
await tester.pumpAndSettle();
// Settings has no Back; the Pipelines item returns to the open pipeline.
await tab(tester, 'pipelines');
expect(app.provider.value.uri.path, '/pipelines/1');
expect(tester.state(find.byType(PipelinesScreen)), same(pipelineState));
expect(
@@ -673,11 +673,18 @@ void main() {
});
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(find.byTooltip('2 tasks, 12 automations'), findsOneWidget);
expect(find.byTooltip('Background tasks (2 running)'), findsOneWidget);
final counter = find.byKey(const Key('chat-background-tasks-button'));
// One '2' is the count inside the ring, one is the compact caption.
expect(
tester
.widget<Text>(find.byKey(const Key('chat-background-tasks-count')))
.data,
'2',
);
expect(
find.descendant(of: counter, matching: find.text('2')),
findsOneWidget,
findsNWidgets(2),
);
expect(
find.descendant(of: counter, matching: find.text('12')),
@@ -6,19 +6,23 @@ import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/conversation/chat_background_tasks.dart';
import 'package:pipelines_app/features/chat/conversation/chat_task_spinner.dart';
RotationTransition _rotation(WidgetTester tester) =>
tester.widget<RotationTransition>(
find.byKey(const Key('chat-background-tasks-spinner')),
final _spinnerFinder = find.byKey(const Key('chat-background-tasks-spinner'));
CircularProgressIndicator _ring(WidgetTester tester) =>
tester.widget<CircularProgressIndicator>(
find.descendant(
of: _spinnerFinder,
matching: find.byType(CircularProgressIndicator),
),
);
Widget _spinner(bool spinning) => MaterialApp(
home: Scaffold(
body: ChatTaskSpinner(
spinning: spinning,
child: const Icon(Icons.layers_outlined, size: 16),
),
),
);
Widget _spinner(int running, {Brightness brightness = Brightness.light}) =>
MaterialApp(
theme: ThemeData(colorSchemeSeed: Colors.indigo, brightness: brightness),
home: Scaffold(
body: Center(child: ChatTaskSpinner(running: running)),
),
);
void _reducedMotion(bool reduced) =>
TestWidgetsFlutterBinding.ensureInitialized()
@@ -51,58 +55,99 @@ class _TasksGateway implements ApiGateway {
void main() {
tearDown(() => _reducedMotion(false));
testWidgets('turns once every period while spinning', (tester) async {
testWidgets(
'a running task shows an indeterminate primary ring with the count',
(tester) async {
_reducedMotion(false);
await tester.pumpWidget(_spinner(2));
final ring = _ring(tester);
expect(ring.value, isNull);
expect(ring.strokeWidth, 2);
expect(
ring.color,
ThemeData(colorSchemeSeed: Colors.indigo).colorScheme.primary,
);
expect(
find.descendant(of: _spinnerFinder, matching: find.text('2')),
findsOneWidget,
);
expect(
find.descendant(
of: _spinnerFinder,
matching: find.byIcon(Icons.layers_outlined),
),
findsNothing,
);
// The ring keeps turning: time advances the animation.
await tester.pump(const Duration(milliseconds: 300));
expect(tester.binding.transientCallbackCount, greaterThan(0));
await tester.pumpWidget(const SizedBox.shrink());
expect(tester.binding.transientCallbackCount, 0);
},
);
testWidgets('dark theme uses the dark primary for the ring', (tester) async {
_reducedMotion(false);
await tester.pumpWidget(_spinner(true));
expect(_rotation(tester).turns.value, 0);
await tester.pump(ChatTaskSpinner.period ~/ 4);
expect(_rotation(tester).turns.value, closeTo(0.25, 0.01));
// Past one full lap the turn starts again from the top.
await tester.pump(
ChatTaskSpinner.period ~/ 4 * 3 + const Duration(milliseconds: 100),
await tester.pumpWidget(_spinner(1, brightness: Brightness.dark));
expect(
_ring(tester).color,
ThemeData(
colorSchemeSeed: Colors.indigo,
brightness: Brightness.dark,
).colorScheme.primary,
);
expect(_rotation(tester).turns.value, closeTo(0.04, 0.01));
await tester.pumpWidget(const SizedBox.shrink());
expect(tester.binding.transientCallbackCount, 0);
});
testWidgets('stays still when not spinning, and stops when it stops', (
testWidgets('no running task shows the static icon with no ring', (
tester,
) async {
_reducedMotion(false);
await tester.pumpWidget(_spinner(false));
await tester.pump(const Duration(seconds: 2));
expect(_rotation(tester).turns.value, 0);
expect(tester.binding.transientCallbackCount, 0);
await tester.pumpWidget(_spinner(true));
await tester.pump(const Duration(milliseconds: 625));
expect(_rotation(tester).turns.value, greaterThan(0));
await tester.pumpWidget(_spinner(false));
await tester.pump();
expect(_rotation(tester).turns.value, 0);
await tester.pump(const Duration(seconds: 2));
expect(_rotation(tester).turns.value, 0);
await tester.pumpWidget(_spinner(0));
expect(
find.descendant(
of: _spinnerFinder,
matching: find.byType(CircularProgressIndicator),
),
findsNothing,
);
expect(
find.descendant(
of: _spinnerFinder,
matching: find.byIcon(Icons.layers_outlined),
),
findsOneWidget,
);
expect(tester.binding.transientCallbackCount, 0);
});
testWidgets('reduced motion keeps the icon static even while spinning', (
testWidgets('every state keeps the same square size', (tester) async {
_reducedMotion(false);
for (final running in [0, 1, 12]) {
await tester.pumpWidget(_spinner(running));
expect(tester.getSize(_spinnerFinder), const Size(16, 16));
}
});
testWidgets('reduced motion holds one static ring segment while running', (
tester,
) async {
_reducedMotion(true);
await tester.pumpWidget(_spinner(true));
await tester.pumpWidget(_spinner(3));
expect(_ring(tester).value, ChatTaskSpinner.reducedSegment);
await tester.pump(const Duration(seconds: 1));
expect(_rotation(tester).turns.value, 0);
expect(_ring(tester).value, ChatTaskSpinner.reducedSegment);
expect(tester.binding.transientCallbackCount, 0);
});
testWidgets('the tasks icon rotates only while a task runs', (tester) async {
testWidgets('the composer button shows the count ring and its tooltip', (
tester,
) async {
_reducedMotion(false);
final gateway = _TasksGateway();
addTearDown(gateway.close);
gateway.running = const [
{'id': 'sh1', 'status': 'running', 'command': 'go test ./...'},
{'id': 'sh2', 'status': 'running', 'command': 'make'},
];
await tester.pumpWidget(
MaterialApp(
@@ -111,12 +156,15 @@ void main() {
),
),
);
// The spinning icon repeats forever, so settle by pumping, never by waiting.
// The ring repeats forever, so settle by pumping, never by waiting.
await tester.pump();
await tester.pump();
expect(find.text('1 task'), findsOneWidget);
final before = _rotation(tester).turns.value;
await tester.pump(const Duration(milliseconds: 300));
expect(_rotation(tester).turns.value, greaterThan(before));
expect(find.text('2 tasks'), findsOneWidget);
expect(find.byTooltip('Background tasks (2 running)'), findsOneWidget);
expect(_ring(tester).value, isNull);
expect(
find.descendant(of: _spinnerFinder, matching: find.text('2')),
findsOneWidget,
);
});
}
@@ -0,0 +1,127 @@
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/ui/sessions/chat_sessions_screen.dart';
import 'package:pipelines_app/features/terminal/terminal_scope.dart';
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
import 'package:pipelines_app/ui/layout/section_heading.dart';
import 'chat_test_harness.dart';
import 'fake_chat_gateway.dart';
/// The chat list's top bar carries Terminal beside New chat and Refresh on a
/// narrow layout, so the phone header below it has no floating terminal
/// shortcut over its count and collapse chevron.
class _Actions implements TerminalActions {
int toggles = 0;
@override
void toggle() => toggles++;
@override
bool get claimsTabKeys => false;
@override
Future<String?> openAt(ApiGateway gateway, String cwd) async => null;
}
const _terminalIdentifier = 'chat-terminal-toggle';
Future<void> _pumpList(
WidgetTester tester, {
required Size size,
TerminalActions? actions,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
final list = ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: MediaQuery(
data: MediaQueryData(size: size),
child: actions == null
? list
: TerminalScope(actions: actions, child: list),
),
),
);
await tester.pumpAndSettle();
}
void main() {
testWidgets('phone: Terminal sits in the top bar beside New chat and '
'Refresh, and is the only terminal entry on the list', (tester) async {
final actions = _Actions();
await _pumpList(tester, size: const Size(430, 900), actions: actions);
final bar = find.byType(SegmentedBar);
expect(
find.descendant(
of: bar,
matching: find.byKey(const Key('chat-new-chat')),
),
findsOneWidget,
);
expect(
find.descendant(of: bar, matching: find.byKey(const Key('chat-refresh'))),
findsOneWidget,
);
final terminal = find.descendant(
of: bar,
matching: find.bySemanticsIdentifier(_terminalIdentifier),
);
expect(terminal, findsOneWidget);
expect(find.byTooltip(TerminalToggleButton.label), findsOneWidget);
expect(find.byType(FloatingActionButton), findsNothing);
await tester.tap(terminal);
await tester.pump();
expect(actions.toggles, 1);
});
testWidgets('phone: the top bar sits above the Chats header, which keeps its '
'count and collapse chevron clear of it', (tester) async {
await _pumpList(tester, size: const Size(430, 900), actions: _Actions());
final bar = tester.getRect(find.byType(SegmentedBar));
final heading = find.descendant(
of: find.byKey(const ValueKey('chat-section-Chats')),
matching: find.byType(SectionHeading),
);
expect(heading, findsOneWidget);
final headerRect = tester.getRect(heading);
expect(
headerRect.top,
greaterThanOrEqualTo(bar.bottom),
reason: 'no top-bar control may cover the section header',
);
expect(tester.takeException(), isNull);
});
testWidgets('a wide layout keeps Terminal on the shell bar, not the list '
'bar', (tester) async {
await _pumpList(tester, size: const Size(1200, 800), actions: _Actions());
expect(find.bySemanticsIdentifier(_terminalIdentifier), findsNothing);
});
testWidgets('with no terminal surface the list bar has no terminal entry', (
tester,
) async {
await _pumpList(tester, size: const Size(430, 900));
expect(find.bySemanticsIdentifier(_terminalIdentifier), findsNothing);
expect(find.byKey(const Key('chat-new-chat')), findsOneWidget);
});
}
@@ -0,0 +1,182 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/workspace/chat_pane_dim.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/ui/motion/motion.dart';
Widget host(
ChatWorkspaceController controller, {
bool disableAnimations = false,
}) => MaterialApp(
home: Scaffold(
body: SizedBox(
width: 1200,
height: 900,
child: Builder(
builder: (context) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(disableAnimations: disableAnimations),
child: ChatWorkspace(
controller: controller,
paneBuilder: (_, pane, active) =>
TextField(key: ValueKey('input-${pane.sessionId}')),
),
),
),
),
),
);
/// The dim overlay wrapping the pane that shows [session].
Finder dimOf(String session) => find.ancestor(
of: find.byKey(ValueKey('input-$session')),
matching: find.byType(ChatPaneDim),
);
/// The alpha of the scrim over [session]'s pane: zero when the pane is clear.
double scrimAlpha(WidgetTester tester, String session) {
final scrim = find.descendant(
of: dimOf(session),
matching: find.byKey(const ValueKey('chat-pane-dim-scrim')),
);
// AnimatedContainer builds a Container whose BoxDecoration holds the colour.
final container = tester.widget<Container>(
find.descendant(of: scrim, matching: find.byType(Container)),
);
final decoration = container.decoration as BoxDecoration?;
return (decoration?.color ?? container.color ?? const Color(0x00000000)).a;
}
void usePhoneSizedView(WidgetTester tester) {
tester.view.physicalSize = const Size(1200, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
}
void main() {
testWidgets('two panes: the inactive pane is dimmed and the active is not', (
tester,
) async {
final controller = ChatWorkspaceController()
..open('one')
..splitActive('two', ChatSplitAxis.horizontal);
addTearDown(controller.dispose);
await tester.pumpWidget(host(controller));
await tester.pumpAndSettle();
expect(controller.activePane?.sessionId, 'two');
expect(scrimAlpha(tester, 'one'), closeTo(chatPaneDimOpacity, 0.001));
expect(scrimAlpha(tester, 'two'), 0);
});
testWidgets('three panes: every inactive pane is dimmed, the active is not', (
tester,
) async {
final controller = ChatWorkspaceController()
..open('one')
..splitActive('two', ChatSplitAxis.horizontal)
..splitActive('three', ChatSplitAxis.horizontal);
addTearDown(controller.dispose);
await tester.pumpWidget(host(controller));
await tester.pumpAndSettle();
expect(controller.activePane?.sessionId, 'three');
expect(scrimAlpha(tester, 'one'), closeTo(chatPaneDimOpacity, 0.001));
expect(scrimAlpha(tester, 'two'), closeTo(chatPaneDimOpacity, 0.001));
expect(scrimAlpha(tester, 'three'), 0);
});
testWidgets('a single pane is never dimmed', (tester) async {
final controller = ChatWorkspaceController()..open('one');
addTearDown(controller.dispose);
await tester.pumpWidget(host(controller));
await tester.pumpAndSettle();
expect(scrimAlpha(tester, 'one'), 0);
});
testWidgets('tapping an inactive pane activates it and focuses its input', (
tester,
) async {
usePhoneSizedView(tester);
final controller = ChatWorkspaceController()
..open('one')
..splitActive('two', ChatSplitAxis.horizontal);
addTearDown(controller.dispose);
await tester.pumpWidget(host(controller));
await tester.pumpAndSettle();
final first = controller.panes.first.id;
expect(controller.activePaneId, isNot(first));
await tester.tap(find.byKey(const ValueKey('input-one')));
await tester.pumpAndSettle();
expect(controller.activePaneId, first);
expect(scrimAlpha(tester, 'one'), 0);
expect(scrimAlpha(tester, 'two'), closeTo(chatPaneDimOpacity, 0.001));
final editable = tester.widget<EditableText>(
find.descendant(
of: find.byKey(const ValueKey('input-one')),
matching: find.byType(EditableText),
),
);
expect(editable.focusNode.hasFocus, isTrue);
});
testWidgets('a tap on bare space in an inactive pane activates it', (
tester,
) async {
usePhoneSizedView(tester);
final controller = ChatWorkspaceController()
..open('one')
..splitActive('two', ChatSplitAxis.horizontal);
addTearDown(controller.dispose);
await tester.pumpWidget(host(controller));
await tester.pumpAndSettle();
final first = controller.panes.first.id;
final corner = tester.getTopLeft(dimOf('one')) + const Offset(2, 2);
await tester.tapAt(corner);
await tester.pumpAndSettle();
expect(controller.activePaneId, first);
});
testWidgets('reduced motion switches the dim at once, without a fade', (
tester,
) async {
final controller = ChatWorkspaceController()
..open('one')
..splitActive('two', ChatSplitAxis.horizontal);
addTearDown(controller.dispose);
await tester.pumpWidget(host(controller, disableAnimations: true));
await tester.pumpAndSettle();
final scrim = find.byKey(const ValueKey('chat-pane-dim-scrim')).first;
expect(tester.widget<AnimatedContainer>(scrim).duration, Duration.zero);
controller.activate(controller.panes.first.id);
await tester.pump();
expect(scrimAlpha(tester, 'one'), 0);
expect(scrimAlpha(tester, 'two'), closeTo(chatPaneDimOpacity, 0.001));
});
testWidgets('motion is on by default: the dim fades over the standard time', (
tester,
) async {
final controller = ChatWorkspaceController()
..open('one')
..splitActive('two', ChatSplitAxis.horizontal);
addTearDown(controller.dispose);
await tester.pumpWidget(host(controller));
await tester.pumpAndSettle();
final scrim = find.byKey(const ValueKey('chat-pane-dim-scrim')).first;
expect(
tester.widget<AnimatedContainer>(scrim).duration,
Motion.standard,
);
});
}
@@ -0,0 +1,73 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'fixtures.dart';
import 'test_helpers.dart';
/// The Pipelines bar's Settings gear inside the shell: it is kept only where the
/// floating tab bar is the shell's sole navigation (between the list-detail and
/// rail widths), because only there Settings has no nav entry. Elsewhere the
/// phone's bar or the rail offers Settings, so the bar has no gear.
void main() {
// Returns how many times the gear opened Settings.
Future<int Function()> pumpInShell(WidgetTester tester, Size size) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
var opened = 0;
final gateway = gatewayFor(PipelineFixture());
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.pipelines,
destinationBodies: {
// The app's Pipelines destination embeds the screen in the shell.
AppDestination.pipelines: (_) => PipelinesScreen(
gateway: gateway,
embedded: true,
onOpenSettings: () => opened++,
),
},
),
),
);
await tester.pumpAndSettle();
return () => opened;
}
testWidgets('a phone bar offers Settings, so the Pipelines bar has no gear', (
tester,
) async {
await pumpInShell(tester, const Size(390, 844));
expect(find.byType(NavigationBar), findsOneWidget);
expect(find.byKey(const Key('pipelines-open-settings')), findsNothing);
});
testWidgets('a rail offers Settings, so the Pipelines bar has no gear', (
tester,
) async {
await pumpInShell(tester, const Size(1200, 800));
expect(find.byType(NavigationRail), findsOneWidget);
expect(find.byKey(const Key('pipelines-open-settings')), findsNothing);
});
testWidgets('the floating tab bar lists tabs only, so the Pipelines bar '
'keeps the gear and it opens Settings', (tester) async {
final opened = await pumpInShell(tester, const Size(650, 844));
expect(find.byType(FloatingDestinationBar), findsOneWidget);
expect(find.byKey(const Key('pipelines-open-settings')), findsOneWidget);
// At this width the bar folds the gear into its More menu, so it is not
// hit-testable here; its handler is what opens Settings.
final gear = tester.widget<IconButton>(
find.byKey(const Key('pipelines-open-settings')),
);
expect(gear.tooltip, 'Settings');
gear.onPressed!();
expect(opened(), 1);
});
}
@@ -0,0 +1,63 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/navigation_rail.dart';
/// The rail's surface runs from the window's top edge. The system's top inset
/// is kept clear for the rail's content, but it is painted with the rail's
/// surface, so no unpainted strip (white in the app's canvas) shows above it.
void main() {
for (final brightness in Brightness.values) {
testWidgets('the rail top under a system inset is the rail surface '
'(${brightness.name})', (tester) async {
tester.view.physicalSize = const Size(1000, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final theme = ThemeData(
colorSchemeSeed: Colors.purple,
brightness: brightness,
);
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Scaffold(
body: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ShellNavigationRail(
selected: AppDestination.pipelines,
icon: (destination) =>
Icon(destinationDetails(destination).icon),
onSelected: (_) {},
padding: const EdgeInsets.only(top: 8),
),
],
),
),
),
);
await tester.pumpAndSettle();
final surface = theme.colorScheme.surface;
final cover = find.byKey(const ValueKey('shell.navigation-rail.surface'));
final rail = find.byKey(const ValueKey('shell.navigation-rail'));
// The cover and the rail's own background are the same surface colour.
expect(tester.widget<ColoredBox>(cover).color, surface);
expect(tester.widget<NavigationRail>(rail).backgroundColor, surface);
// The rail's content starts below the inset, and the cover starts at the
// window's top edge, so the inset strip is covered.
final coverRect = tester.getRect(cover);
final railRect = tester.getRect(rail);
expect(coverRect.top, 0);
expect(railRect.top, 8);
expect(
coverRect.contains(Offset(railRect.center.dx, 2)),
isTrue,
reason: 'the strip above the rail content is painted',
);
});
}
}
+6 -4
View File
@@ -90,8 +90,8 @@ void main() {
expect(find.text('runs body'), findsOneWidget);
});
testWidgets('Settings opens from the rail foot as a page and no tab is '
'selected meanwhile', (tester) async {
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);
@@ -106,8 +106,10 @@ void main() {
.isSelected,
Tristate.isTrue,
);
// The page's own Back returns to Pipelines, the tab it belongs to.
await tester.tap(find.byKey(const ValueKey('shell.back')));
// 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();
+90
View File
@@ -0,0 +1,90 @@
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';
/// Settings' Back: a destination reached from a shell control has none; a page
/// pushed by a route (a first load or a route change, such as a deep link or
/// the Pipelines gear) has one that returns to Pipelines.
void main() {
AdaptiveShell shellAt(AppDestination destination) => AdaptiveShell(
destination: destination,
destinationBodies: {
for (final value in AppDestination.values)
value: (_) => Text('${value.name} body'),
},
);
Future<void> pumpAt(
WidgetTester tester,
AppDestination destination, {
double width = 1000,
}) async {
tester.view.physicalSize = Size(width, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(MaterialApp(home: shellAt(destination)));
await tester.pumpAndSettle();
}
testWidgets('Settings selected from a rail item has no Back', (tester) async {
await pumpAt(tester, AppDestination.pipelines);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
await tester.pumpAndSettle();
expect(find.text('settings body'), findsOneWidget);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
});
testWidgets('Settings selected from a phone bar item has no Back', (
tester,
) async {
await pumpAt(tester, AppDestination.pipelines, width: 390);
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
await tester.pumpAndSettle();
expect(find.text('settings body'), findsOneWidget);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
});
testWidgets('Settings pushed by a route change has Back, which returns to '
'Pipelines', (tester) async {
await pumpAt(tester, AppDestination.pipelines);
// The route moves to Settings (as a gear or a deep link does).
await tester.pumpWidget(
MaterialApp(home: shellAt(AppDestination.settings)),
);
await tester.pumpAndSettle();
expect(find.text('settings body'), findsOneWidget);
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pumpAndSettle();
expect(find.text('pipelines body'), findsOneWidget);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
});
testWidgets('a first load on Settings (a deep link) has Back', (
tester,
) async {
await pumpAt(tester, AppDestination.settings);
expect(find.text('settings body'), findsOneWidget);
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
});
testWidgets('a nav selection after a pushed Settings clears its Back', (
tester,
) async {
await pumpAt(tester, AppDestination.settings);
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
await tester.pumpAndSettle();
expect(find.text('chat body'), findsOneWidget);
// Settings opened again from its rail item is a destination, not a page.
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
});
}
@@ -0,0 +1,98 @@
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/windows/window_manager.dart';
import 'windows/window_test_harness.dart';
/// The shell bar's trailing action island is drawn only with actions. The
/// Windows button is one of them only while a floating window is open, so
/// Search and Settings (and every other route) show no empty pill at any size.
void main() {
Future<void> pumpShell(
WidgetTester tester, {
required AppDestination destination,
required double width,
WindowManager? windowManager,
}) async {
tester.view.physicalSize = Size(width, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: destination,
windowManager: windowManager,
destinationBodies: {
for (final value in AppDestination.values)
value: (_) => Text('${value.name} body'),
},
),
),
);
await tester.pumpAndSettle();
}
final actionIsland = find.byKey(const ValueKey('segmented.actions'));
for (final width in [1000.0, 430.0]) {
for (final destination in [
AppDestination.search,
AppDestination.settings,
AppDestination.pipelines,
]) {
testWidgets(
'${destination.name} at width ${width.toInt()} draws no empty action '
'island with no floating window',
(tester) async {
await pumpShell(
tester,
destination: destination,
width: width,
windowManager: probeManager(),
);
expect(actionIsland, findsNothing);
expect(find.byKey(const ValueKey('shell.windows')), findsNothing);
},
);
}
}
testWidgets('a shell without a window manager draws no action island', (
tester,
) async {
await pumpShell(tester, destination: AppDestination.settings, width: 1000);
expect(actionIsland, findsNothing);
});
testWidgets('the Windows button is the island only while a window is open', (
tester,
) async {
final manager = probeManager();
await pumpShell(
tester,
destination: AppDestination.search,
width: 1000,
windowManager: manager,
);
expect(actionIsland, findsNothing);
final entry = manager.open('probe', 'a');
await tester.pumpAndSettle();
expect(actionIsland, findsOneWidget);
expect(
find.descendant(
of: actionIsland,
matching: find.byKey(const ValueKey('shell.windows')),
),
findsOneWidget,
);
manager.close(entry.id);
await tester.pumpAndSettle();
expect(actionIsland, findsNothing);
expect(find.byKey(const ValueKey('shell.windows')), findsNothing);
});
}