Merge commit '40623991e8709e5c1ab3e875b51d4de55f0c20a5' into pipelines/run-20261112-0206-composer-border-shows-the-agent-working-fd87

This commit is contained in:
2026-11-12 02:58:45 +00:00
130 changed files with 5209 additions and 813 deletions
@@ -0,0 +1,65 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/app_terminals.dart';
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
import '../features/terminal/terminal_fixtures.dart';
void main() {
late TerminalGateway gateway;
late AppTerminals terminals;
setUp(() {
gateway = TerminalGateway();
terminals = AppTerminals(
pool: null,
connection: ValueNotifier<int>(0),
connected: () => true,
gateway: gateway,
machineId: 'mac',
machineName: 'Mac',
layout: TerminalLayout(store: MemoryLayoutStore()),
);
});
tearDown(() {
terminals.dispose();
gateway.close();
});
/// Pumps [AppTerminals.barToggle] at [width] and returns what it built.
Future<Widget?> barToggleAt(WidgetTester tester, double width) async {
Widget? built;
await tester.pumpWidget(
MaterialApp(
home: MediaQuery(
data: MediaQueryData(size: Size(width, 800)),
child: Builder(
builder: (context) {
built = terminals.barToggle(context);
return const SizedBox.shrink();
},
),
),
),
);
return built;
}
testWidgets('the Chat shell bar offers the terminal toggle on a wide layout', (
tester,
) async {
final built = await barToggleAt(tester, 1000);
expect(built, isA<TerminalToggleButton>());
});
testWidgets('a narrow layout has no terminal toggle in the shell bar', (
tester,
) async {
// Covers both a narrow chat list and an open narrow chat: the open chat's
// own bar carries the terminal (terminal_chat_bar_action_test.dart).
final built = await barToggleAt(tester, 390);
expect(built, isNull);
});
}
@@ -285,12 +285,12 @@ void main() {
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
expect(find.text('Kept behind a native disclosure.'), findsNothing);
// The shell bar stays over the list and tabs; the open chat draws its
// own floating bar in its pane, with no Back: the list beside it is the
// way out.
// The destination rail sits at the left edge; the shell bar stays over
// the list, and the open chat draws its own floating bar in its pane,
// with no Back: the list beside it is the way out.
expect(find.byType(ChatSessionsScreen), findsOneWidget);
expect(find.byType(NavigationRail), findsNothing);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
expect(find.byType(NavigationRail), findsOneWidget);
expect(find.byType(FloatingDestinationBar), findsNothing);
// The shell's bar and the conversation's own header.
expect(find.byType(SegmentedBar), findsNWidgets(2));
expect(find.byType(AppBar), findsNothing);
+57 -4
View File
@@ -13,9 +13,9 @@ 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, keeps its `/settings` route (and deep link), and closes back to
/// Pipelines. The tab bar keeps Pipelines selected meanwhile.
/// 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.
void main() {
Future<PlatformRouteInformationProvider> pumpApp(
WidgetTester tester, {
@@ -50,7 +50,9 @@ void main() {
.widget<FloatingDestinationBar>(find.byType(FloatingDestinationBar))
.currentIndex;
for (final size in [const Size(390, 844), const Size(1200, 800)]) {
// 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(
@@ -101,6 +103,57 @@ void main() {
});
}
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', (
tester,
) async {
final provider = await pumpApp(
tester,
location: '/pipelines',
size: const Size(1200, 800),
);
expect(find.byType(NavigationRail), findsOneWidget);
expect(find.byKey(const Key('pipelines-open-settings')), findsNothing);
expect(find.byType(FloatingDestinationBar), findsNothing);
final rail = tester.widget<NavigationRail>(find.byType(NavigationRail));
expect(rail.selectedIndex, 0);
for (final label in ['Pipelines', 'Runs', 'Chat', 'Search', 'Settings']) {
expect(
find.descendant(
of: find.byType(NavigationRail),
matching: find.text(label),
),
findsOneWidget,
reason: label,
);
}
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/settings');
expect(find.byType(SettingsScreen), findsOneWidget);
// Settings is a page of Pipelines: 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(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')), findsNothing);
expect(
tester.widget<NavigationRail>(find.byType(NavigationRail)).selectedIndex,
0,
);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
testWidgets('the /settings deep link opens the Settings page and '
'the system Back closes it to Pipelines', (tester) async {
final provider = await pumpApp(
@@ -179,11 +179,9 @@ void main() {
final before = tester.widget<PipelinesScreen>(find.byType(PipelinesScreen));
expect(before.initialPipelineId, 1);
final pipelineState = tester.state(find.byType(PipelinesScreen));
await tapBarAction(
tester,
find.byKey(const Key('pipelines-open-settings')),
'Settings',
);
// Wide: the rail offers Settings (the toolbar gear is gone).
expect(find.byKey(const Key('pipelines-open-settings')), findsNothing);
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
await tester.pumpAndSettle();
expect(app.provider.value.uri.path, '/settings');
final hidden = find.byType(PipelinesScreen, skipOffstage: false);
@@ -133,9 +133,8 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('single pane focuses input; empty workspace does not consume', (
tester,
) async {
testWidgets('single pane with no shown window does nothing; empty workspace '
'does not consume', (tester) async {
await _setup(tester, open: false);
await _chord(tester);
expect(find.byType(ChatWorkspace), findsNothing);
@@ -144,7 +143,9 @@ void main() {
_focusSidebar(tester);
await tester.pumpAndSettle();
await _chord(tester);
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isTrue);
expect(find.byType(ChatWorkspace), findsOneWidget);
expect(_workspace(tester).paneCount, 1);
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isFalse);
expect(_editable(tester, 'a').controller.text, isEmpty);
await tester.pumpWidget(const SizedBox.shrink());
});
@@ -531,25 +531,36 @@ void main() {
await tester.pumpAndSettle();
expect(app.floating, ['b', 'c', 'a']);
// The cycle follows the order the windows were opened in (b, c, a), not
// the stacking order, which each raise changes. From a (opened last) the
// next is b, the first opened.
await _tab(tester);
expect(app.floating, ['c', 'a', 'b']);
expect(_composerFocused(tester, 'b'), isTrue);
// Past the top, the bottom window comes up again.
await _tab(tester);
expect(app.floating, ['a', 'b', 'c']);
expect(_composerFocused(tester, 'c'), isTrue);
await _tab(tester);
expect(app.floating, ['b', 'c', 'a']);
expect(_composerFocused(tester, 'a'), isTrue);
await _tab(tester, shift: true);
expect(app.floating, ['b', 'a', 'c']);
expect(_composerFocused(tester, 'c'), isTrue);
await _tab(tester, shift: true);
expect(app.floating, ['a', 'c', 'b']);
expect(_composerFocused(tester, 'b'), isTrue);
// Back past the first opened: the last opened (a) comes up.
await _tab(tester, shift: true);
expect(app.floating, ['a', 'b', 'c']);
expect(_composerFocused(tester, 'c'), isTrue);
expect(app.floating, ['c', 'b', 'a']);
expect(_composerFocused(tester, 'a'), isTrue);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('with the tiling focused Ctrl+Tab cycles its panes and leaves '
'the windows alone', (tester) async {
testWidgets('with the tiling focused Ctrl+Tab goes to the top-most shown '
'window, and cycles the panes only when no window is shown', (
tester,
) async {
await _saved('a', 'b', 'c');
final app = _App(_Store());
await app.start(tester);
@@ -557,26 +568,61 @@ void main() {
expect(app.floating, ['c']);
final controller = _workspace(tester);
// A window is shown: from the tiling, Ctrl+Tab takes the keyboard to it
// and the panes stay where they are.
await tester.tapAt(tester.getCenter(_input('a')));
await tester.pump();
expect(controller.activePane?.sessionId, 'a');
await _tab(tester);
expect(controller.activePane?.sessionId, 'b');
expect(_composerFocused(tester, 'b'), isTrue);
expect(controller.activePane?.sessionId, 'a');
expect(_composerFocused(tester, 'c'), isTrue);
expect(app.floating, ['c']);
// With a window focused, the panes stay where they are; a single window
// has nothing to cycle to.
await tester.tapAt(tester.getCenter(_input('c')));
await tester.pump();
// A single shown window has nothing to cycle to.
await _tab(tester);
expect(controller.activePane?.sessionId, 'a');
expect(_composerFocused(tester, 'c'), isTrue);
expect(app.floating, ['c']);
// No window shown: the panes cycle and the hidden window stays hidden.
await _chord(tester);
expect(_shown('Chat c'), findsNothing);
await tester.tapAt(tester.getCenter(_input('a')));
await tester.pump();
await _tab(tester);
expect(controller.activePane?.sessionId, 'b');
expect(_composerFocused(tester, 'b'), isTrue);
expect(_shown('Chat c'), findsNothing);
expect(app.floating, ['c']);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('with one tiled pane and no shown window Ctrl+Tab does nothing; '
'a minimised chat is not brought up', (tester) async {
await _saved('a', 'b');
final app = _App(_Store());
await app.start(tester);
await _menu(tester, 'b', 'Float (Alt+Y)');
await tester.tap(find.byTooltip('Minimise'));
await tester.pumpAndSettle();
expect(_shown('Chat b'), findsNothing);
final controller = _workspace(tester);
expect(controller.panes.map((p) => p.sessionId), ['a']);
await tester.tapAt(tester.getCenter(_input('a')));
await tester.pump();
await _tab(tester);
await _tab(tester, shift: true);
expect(controller.panes.map((p) => p.sessionId), ['a']);
expect(controller.activePane?.sessionId, 'a');
expect(_shown('Chat b'), findsNothing);
expect(app.floating, ['b']);
expect(app.opened, isEmpty);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('a terminal that claims tab keys keeps Ctrl+Tab over a focused '
'floating chat', (tester) async {
await _saved('a', 'b', 'c');
@@ -150,38 +150,29 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Control Tab over one pane returns to the previous chat', (
tester,
) async {
testWidgets('Control Tab over one pane does nothing: it never brings up '
'another chat', (tester) async {
await _setup(tester);
await _openRow(tester, 'a');
final workspace = _workspace(tester);
// Nothing shown before: the chord only focuses the composer.
await _controlTab(tester);
expect(workspace.activePane?.sessionId, 'a');
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isTrue);
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isFalse);
// Opening b replaces the lone pane; a is no longer shown anywhere.
await _openRow(tester, 'b');
await tester.enterText(_input('b'), 'Draft B');
await _focusSidebar(tester);
for (final id in ['a', 'b', 'a']) {
await _controlTab(tester);
for (final shift in [false, true]) {
await _controlTab(tester, shift: shift);
expect(workspace.paneCount, 1);
expect(workspace.activePane?.sessionId, id);
expect(_editable(tester, id).focusNode.hasPrimaryFocus, isTrue);
expect(workspace.activePane?.sessionId, 'b');
expect(_editable(tester, 'b').focusNode.hasPrimaryFocus, isFalse);
expect(_editable(tester, 'b').controller.text, 'Draft B');
}
await _controlTab(tester, shift: true);
expect(workspace.activePane?.sessionId, 'b');
expect(_editable(tester, 'b').controller.text, 'Draft B');
// A third chat makes the pair c and b; a is no longer one step away.
// Two panes cycle the panes, not the history.
await _openRow(tester, 'c');
await _controlTab(tester);
expect(workspace.activePane?.sessionId, 'b');
await _controlTab(tester);
expect(workspace.activePane?.sessionId, 'c');
// Two panes cycle the panes as before, not the history.
await tester.tap(_actions('a'));
await tester.pumpAndSettle();
await tester.tap(find.text('Open to the right'));
@@ -50,7 +50,7 @@ Future<void> _pumpShell(WidgetTester tester, Size size) async {
void main() {
for (final size in [const Size(1280, 800), const Size(800, 830)]) {
testWidgets('a wide window keeps the tab bar and list beside the open chat '
testWidgets('a wide window keeps the rail and list beside the open chat '
'at $size', (tester) async {
await _pumpShell(tester, size);
expect(
@@ -68,8 +68,10 @@ void main() {
find.byType(Navigator).first,
);
expect(navigator.canPop(), isFalse, reason: 'No page covers the shell');
expect(find.byType(NavigationRail), findsNothing);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
// Both sizes are wide enough for the rail (the shell's own bar and list
// beside the open chat sit to its right).
expect(find.byType(NavigationRail), findsOneWidget);
expect(find.byType(FloatingDestinationBar), findsNothing);
expect(find.byKey(const ValueKey('chat-thread-a')), findsOneWidget);
expect(find.text('Second chat'), findsOneWidget);
expect(
@@ -11,7 +11,7 @@ void main() {
testWidgets('chat list stays above labeled navigation ($scale)', (
tester,
) async {
tester.view.physicalSize = const Size(1200, 900);
tester.view.physicalSize = const Size(640, 900);
tester.view.devicePixelRatio = 1;
tester.platformDispatcher.textScaleFactorTestValue = scale;
addTearDown(tester.view.reset);
@@ -87,7 +87,13 @@ void main() {
),
same(scrollable),
);
expect(scrollable.position.pixels, closeTo(retainedOffset, .5));
// The list is narrower at 640 (no rail) than beside the rail, so its
// rows re-wrap into a shorter scroll extent: the offset is kept up to
// that extent, and no further.
final kept = retainedOffset < scrollable.position.maxScrollExtent
? retainedOffset
: scrollable.position.maxScrollExtent;
expect(scrollable.position.pixels, closeTo(kept, .5));
expect(tester.takeException(), isNull);
});
}
@@ -106,7 +106,16 @@ void main() {
expect(find.text('Menu'), findsOneWidget);
await tester.tap(find.text('Menu'));
await tester.pumpAndSettle();
await tester.tap(find.text('Runs'));
// The menu's own row: the rail labels Runs too, so take the text that
// is not in the rail.
await tester.tap(
find.byElementPredicate(
(element) =>
element.widget is Text &&
(element.widget as Text).data == 'Runs' &&
element.findAncestorWidgetOfExactType<NavigationRail>() == null,
),
);
await tester.pumpAndSettle();
expect(find.text('Runs destination'), findsOneWidget);
await tester.tap(find.byTooltip('Chat'));
@@ -16,6 +16,7 @@ class FakeNotificationService implements NotificationServiceBridge {
);
NotificationServiceStatus current;
List<NotificationConnectionEvent> events = const [];
final calls = <(String, Map<String, Object?>)>[];
final _changes = StreamController<NotificationServiceStatus>.broadcast();
bool batteryGranted = true;
@@ -85,4 +86,9 @@ class FakeNotificationService implements NotificationServiceBridge {
if (batteryGranted) current = copy(batteryExempt: true);
return true;
}
// Not recorded in [calls]: the log is re-read after every action, and the
// tests assert on the action calls themselves.
@override
Future<List<NotificationConnectionEvent>> connectionEvents() async => events;
}
@@ -92,5 +92,39 @@ void main() {
final bridge = createNotificationServiceBridge();
expect(bridge.supported, isFalse);
expect((await bridge.status()).state, DeliveryState.off);
expect(await bridge.connectionEvents(), isEmpty);
});
test('a refused session reports sign_in_required', () {
expect(
NotificationServiceStatus.fromMap({'status': 'sign_in_required'}).state,
DeliveryState.signInRequired,
);
});
test('connectionEvents reads the service log, newest first', () async {
messenger.setMockMethodCallHandler(channel, (call) async {
if (call.method == 'connectionEvents') {
return [
{
'time': 2000,
'event': 'failed',
'error': 'Expected HTTP 101',
'code': 403,
},
{'time': 1000, 'event': 'connected'},
];
}
return reply();
});
final bridge = MethodChannelNotificationServiceBridge(channel);
final events = await bridge.connectionEvents();
expect(events.map((event) => event.event), ['failed', 'connected']);
expect(events.first.code, 403);
expect(events.first.error, 'Expected HTTP 101');
expect(events.first.detail, 'HTTP 403 · Expected HTTP 101');
expect(events.last.code, isNull);
expect(events.last.error, isNull);
expect(events.last.time, DateTime.fromMillisecondsSinceEpoch(1000));
});
}
@@ -244,10 +244,9 @@ void main() {
await tester.pumpAndSettle();
expect(find.text('No input recorded.'), findsOneWidget);
// Output starts open, so its empty sentence shows without a tap.
await tester.ensureVisible(find.text('Output'));
await tester.pumpAndSettle();
await tester.tap(find.text('Output'));
await tester.pumpAndSettle();
expect(find.text('No output recorded.'), findsOneWidget);
});
@@ -266,5 +265,35 @@ void main() {
await tester.pumpAndSettle();
expect(find.text('ship it'), findsOneWidget);
});
testWidgets('${platform.name} summary output starts expanded and '
'collapses for this view', (tester) async {
await pumpRunDetail(
tester,
platform,
run: recordedRunFixture(),
size: const Size(900, 1600),
);
final output = find.byKey(const ValueKey('run-detail-summary-output'));
final outputTitle = find.descendant(
of: output,
matching: find.text('Output'),
);
final outputBody = find.descendant(of: output, matching: find.text('ok'));
// Output opens with its recorded value; Input stays closed.
expect(outputBody, findsOneWidget);
expect(find.text('ship it'), findsNothing);
await tester.ensureVisible(outputTitle.first);
await tester.pumpAndSettle();
await tester.tap(outputTitle.first);
await tester.pumpAndSettle();
expect(outputBody, findsNothing);
await tester.tap(outputTitle.first);
await tester.pumpAndSettle();
expect(outputBody, findsOneWidget);
});
}
}
@@ -49,21 +49,77 @@ void main() {
}
});
testWidgets('${platform.name} visit Output starts expanded and collapses', (
tester,
) async {
await openVisit(tester, platform);
final output = find.byKey(const ValueKey('run-visit-section-Output'));
final outputTitle = find.descendant(
of: output,
matching: find.text('Output'),
);
final outputBody = find.descendant(of: output, matching: find.text('ok'));
final input = find.byKey(const ValueKey('run-visit-section-Input'));
// Output opens expanded; Input stays closed.
expect(find.text('result'), findsOneWidget);
expect(outputBody, findsOneWidget);
expect(find.text('Ship it.'), findsNothing);
// The operator can collapse Output, and open it again.
await tester.ensureVisible(outputTitle.first);
await tester.tap(outputTitle.first);
await tester.pumpAndSettle();
expect(outputBody, findsNothing);
expect(find.text('result'), findsNothing);
await tester.tap(outputTitle.first);
await tester.pumpAndSettle();
expect(outputBody, findsOneWidget);
expect(input, findsOneWidget);
});
testWidgets('${platform.name} long visit Output opens lazily and still '
'scrolls to its last field', (tester) async {
final run = visitRunFixture();
firstVisitStep(run)['output'] = <String, dynamic>{
for (var i = 0; i < 500; i++) 'field$i': 'value $i',
};
await openVisit(tester, platform, run: run);
// Open by default, yet only the fields on screen are built.
expect(find.text('value 0'), findsOneWidget);
expect(find.text('value 499'), findsNothing);
// Scrolling the page reaches the rest of the Output.
await tester.scrollUntilVisible(
find.text('value 499'),
500,
// The page's own scroll view is the outermost of its scrollables.
scrollable: find
.descendant(
of: find.byKey(const Key('run-visit-body-summary')),
matching: find.byType(Scrollable),
)
.first,
);
expect(find.text('value 499'), findsOneWidget);
});
testWidgets('${platform.name} tabs show recorded values and exact empty '
'wording', (tester) async {
await openVisit(tester, platform);
// Each field by name with its value, never raw JSON.
// Each field by name with its value, never raw JSON. Output is open at
// once; Input's value shows only after its tap.
expect(find.text('Ship it.'), findsNothing);
expect(find.text('ok'), findsNothing);
expect(find.text('ok'), findsOneWidget);
await tester.tap(find.text('Input'));
await tester.pumpAndSettle();
expect(find.text('prompt'), findsOneWidget);
expect(find.text('Ship it.'), findsOneWidget);
expect(find.textContaining('"prompt"'), findsNothing);
// Output is open as the visit opens; no tap is needed to read it.
await openVisitTab(tester, RunVisitSection.output);
await tester.tap(find.text('Output'));
await tester.pumpAndSettle();
expect(find.text('result'), findsOneWidget);
expect(find.text('ok'), findsOneWidget);
@@ -127,13 +183,12 @@ void main() {
await openVisit(tester, platform, run: run);
expect(find.text(visitEmptyInput), findsNothing);
expect(find.text(visitEmptyOutput), findsNothing);
// Output is open, so its empty sentence is already there.
expect(find.text(visitEmptyOutput), findsOneWidget);
await tester.tap(find.text('Input'));
await tester.pumpAndSettle();
expect(find.text(visitEmptyInput), findsOneWidget);
await openVisitTab(tester, RunVisitSection.output);
await tester.tap(find.text('Output'));
await tester.pumpAndSettle();
expect(find.text(visitEmptyOutput), findsOneWidget);
await openVisitTab(tester, RunVisitSection.artifacts);
expect(
@@ -172,7 +172,17 @@ void main() {
expect(find.text('alpha=1, items=1, 2'), findsOneWidget);
expect(find.textContaining('"alpha"'), findsNothing);
await openSummarySection('Output');
// Output starts open: its value is there to scroll to, without a tap.
await tester.scrollUntilVisible(
find.text('ok=true'),
200,
scrollable: find
.descendant(
of: find.byKey(const Key('run-detail-tab-body-summary')),
matching: find.byType(Scrollable),
)
.first,
);
expect(find.text('ok=true'), findsOneWidget);
await tapTab('Timeline');
@@ -263,7 +263,7 @@ void main() {
});
for (final platform in RunDetailTestPlatform.values) {
testWidgets('${platform.name} input field expands only the input section', (
testWidgets('${platform.name} input field expands the input section', (
tester,
) async {
await pumpSelection(
@@ -277,7 +277,8 @@ void main() {
findsOneWidget,
);
expect(find.text('ship it'), findsOneWidget);
expect(find.text('ok'), findsNothing);
// Output keeps its default: open, as every Summary opens.
expect(find.text('ok'), findsOneWidget);
});
testWidgets(
@@ -310,8 +311,9 @@ void main() {
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
// The plain Summary shows its default sections: Output open, Input closed.
expect(find.text('ship it'), findsNothing);
expect(find.text('ok'), findsNothing);
expect(find.text('ok'), findsOneWidget);
});
for (final platform in RunDetailTestPlatform.values) {
@@ -337,8 +339,9 @@ void main() {
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
// The Summary's default sections: Output open, Input closed.
expect(find.text('ship it'), findsNothing);
expect(find.text('ok'), findsNothing);
expect(find.text('ok'), findsOneWidget);
},
);
}
@@ -40,6 +40,19 @@ void main() {
},
);
test('Runs and Pipelines switch is Ctrl+A on every platform', () {
for (final platform in TargetPlatform.values) {
final entry = KeyboardShortcutRegistry(platform: platform, web: false)
.entries
.firstWhere(
(entry) => entry.action == 'Switch between Runs and Pipelines',
);
expect(entry.keys, 'Ctrl+A', reason: platform.name);
expect(entry.caveat, contains('Pipelines'));
expect(entry.caveat, contains('text field'));
}
});
test('uses the shell primary modifier rule on iOS', () {
final entries = const KeyboardShortcutRegistry(
platform: TargetPlatform.iOS,
@@ -18,6 +18,9 @@ Widget _host(
return MaterialApp(home: Scaffold(body: body));
}
int _requests(FakeNotificationService service) =>
service.calls.where((call) => call.$1 == 'requestBatteryExemption').length;
bool _switchValue(WidgetTester tester) {
final tile = find.byKey(DeviceDeliveryKeys.toggle);
return tester.widget<SwitchListTile>(tile).value;
@@ -62,9 +65,11 @@ void main() {
testWidgets('allow background delivery asks for the exemption', (
tester,
) async {
final service = FakeNotificationService();
final service = FakeNotificationService()..batteryGranted = false;
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
// The open-time prompt was declined; the row is the user's second try.
service.batteryGranted = true;
await tester.tap(find.text(deviceDeliveryBatteryLabel));
await tester.pumpAndSettle();
expect(
@@ -125,6 +130,157 @@ void main() {
await tester.pumpAndSettle();
expect(find.byKey(DeviceDeliveryKeys.error), findsOneWidget);
});
testWidgets(
'a missing battery exemption keeps a warning row with the Samsung note',
(tester) async {
// The open-time prompt is declined, so the exemption stays missing.
final service = FakeNotificationService()..batteryGranted = false;
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
expect(find.byKey(DeviceDeliveryKeys.batteryWarning), findsOneWidget);
expect(find.text(deviceDeliveryWarningTitle), findsOneWidget);
expect(find.textContaining(deviceDeliverySamsungNote), findsOneWidget);
},
);
testWidgets('the warning goes away once the exemption is granted', (
tester,
) async {
final service = FakeNotificationService()..batteryGranted = false;
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
expect(find.byKey(DeviceDeliveryKeys.batteryWarning), findsOneWidget);
service.batteryGranted = true;
await tester.tap(find.text(deviceDeliveryBatteryLabel));
await tester.pumpAndSettle();
expect(find.byKey(DeviceDeliveryKeys.batteryWarning), findsNothing);
});
testWidgets('switching on asks for the battery exemption before starting', (
tester,
) async {
final service = FakeNotificationService();
service.current = service.copy(enabled: false, state: DeliveryState.off);
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
await tester.tap(find.byKey(DeviceDeliveryKeys.toggle));
await tester.pumpAndSettle();
final names = service.calls.map((call) => call.$1).toList();
expect(names, contains('requestBatteryExemption'));
expect(
names.indexOf('requestBatteryExemption'),
lessThan(names.indexOf('setEnabled')),
);
});
testWidgets(
'opening Settings with delivery on and no exemption asks right away',
(tester) async {
final service = FakeNotificationService();
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
expect(_requests(service), 1);
expect(
find.text('Allowed: battery optimisation will not pause delivery'),
findsOneWidget,
);
expect(find.byKey(DeviceDeliveryKeys.batteryWarning), findsNothing);
},
);
testWidgets('a declined open-time prompt is not repeated on resume', (
tester,
) async {
final service = FakeNotificationService()..batteryGranted = false;
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
expect(_requests(service), 1);
expect(find.byKey(DeviceDeliveryKeys.batteryWarning), findsOneWidget);
// Returning from the system screen re-reads the status only.
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
await tester.pumpAndSettle();
expect(_requests(service), 1);
expect(find.byKey(DeviceDeliveryKeys.batteryWarning), findsOneWidget);
});
testWidgets('no open-time prompt when the exemption is already granted', (
tester,
) async {
final service = FakeNotificationService();
service.current = service.copy(batteryExempt: true);
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
expect(_requests(service), 0);
});
testWidgets('no open-time prompt while delivery is off', (tester) async {
final service = FakeNotificationService();
service.current = service.copy(enabled: false, state: DeliveryState.off);
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
expect(_requests(service), 0);
});
testWidgets('no warning while delivery is off', (tester) async {
final service = FakeNotificationService();
service.current = service.copy(enabled: false, state: DeliveryState.off);
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
expect(find.byKey(DeviceDeliveryKeys.batteryWarning), findsNothing);
});
testWidgets('a refused session says the user must sign in again', (
tester,
) async {
final service = FakeNotificationService();
service.current = service.copy(state: DeliveryState.signInRequired);
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
expect(
find.text('Sign in to Pipelines again to keep notifications'),
findsOneWidget,
);
});
testWidgets(
'the connection log lists the service events, failures included',
(tester) async {
final service = FakeNotificationService();
service.events = [
NotificationConnectionEvent(
time: DateTime(2026, 11, 12, 9, 30, 5),
event: 'failed',
error: 'Expected HTTP 101',
code: 403,
),
NotificationConnectionEvent(
time: DateTime(2026, 11, 12, 9, 29),
event: 'connected',
),
];
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
await tester.tap(find.text(deviceDeliveryLogTitle));
await tester.pumpAndSettle();
expect(find.text('Socket failed'), findsOneWidget);
expect(
find.textContaining('HTTP 403 · Expected HTTP 101'),
findsOneWidget,
);
expect(find.text('Socket opened'), findsOneWidget);
},
);
testWidgets('an empty connection log says so', (tester) async {
final service = FakeNotificationService();
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
await tester.tap(find.text(deviceDeliveryLogTitle));
await tester.pumpAndSettle();
expect(find.text(deviceDeliveryLogEmpty), findsOneWidget);
});
}
class _FailingService extends FakeNotificationService {
@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/settings/settings_keys.dart';
import 'package:pipelines_app/features/settings/settings_walkthrough_section.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
void main() {
testWidgets('Settings reopens the walkthrough on the first page', (
tester,
) async {
tester.view.devicePixelRatio = 1;
tester.view.physicalSize = const Size(390, 844);
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
theme: appLightTheme(),
home: const Scaffold(body: SettingsWalkthroughSection()),
),
);
expect(find.text('Show the walkthrough'), findsOneWidget);
expect(find.text('Welcome to Pipelines'), findsNothing);
await tester.tap(find.byKey(SettingsKeys.walkthrough));
await tester.pumpAndSettle();
expect(find.text('Welcome to Pipelines'), findsOneWidget);
expect(find.text('Step 1 of 4'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey<String>('walkthrough.skip')));
await tester.pumpAndSettle();
expect(find.text('Welcome to Pipelines'), findsNothing);
});
}
@@ -0,0 +1,149 @@
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_adaptive.dart';
import 'package:pipelines_app/features/terminal/terminal_open_action.dart';
import 'package:pipelines_app/features/terminal/terminal_scope.dart';
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
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 _filesKey = ValueKey('files');
const _terminalIdentifier = 'chat-terminal-toggle';
/// Pumps an open chat's bar at [width]: Files, then whatever
/// [terminalChatBarAction] builds (null on wide or with no terminal surface).
/// Returns what it built.
Future<Widget?> _pumpBar(
WidgetTester tester, {
required double width,
required ThemeData theme,
_Actions? actions,
}) async {
Widget? built;
final bar = MediaQuery(
data: MediaQueryData(size: Size(width, 800)),
child: Scaffold(
body: Builder(
builder: (context) {
built = terminalChatBarAction(context);
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ChatBarAction(
key: _filesKey,
label: 'Files',
onPressed: () {},
materialIcon: Icons.folder_outlined,
),
?built,
],
);
},
),
),
);
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: actions == null
? bar
: TerminalScope(actions: actions, child: bar),
),
);
await tester.pump();
return built;
}
/// The colour an icon inside [finder] resolves to in the current theme.
Color? _iconColor(WidgetTester tester, Finder finder) {
final icon = find.descendant(of: finder, matching: find.byType(Icon));
final element = tester.element(icon);
return tester.widget<Icon>(icon).color ?? IconTheme.of(element).color;
}
void main() {
for (final theme in [
ThemeData(brightness: Brightness.light, useMaterial3: true),
ThemeData(brightness: Brightness.dark, useMaterial3: true),
]) {
final mode = theme.brightness.name;
testWidgets('$mode, phone: an open chat has a terminal button beside '
'Files, styled as Files', (tester) async {
final actions = _Actions();
final built = await _pumpBar(
tester,
width: 390,
theme: theme,
actions: actions,
);
expect(built, isA<ChatBarAction>());
final terminal = find.bySemanticsIdentifier(_terminalIdentifier);
final files = find.byKey(_filesKey);
expect(terminal, findsOneWidget);
expect(
tester.getSize(terminal),
tester.getSize(files),
reason: 'the terminal button must be the same size as Files',
);
expect(
_iconColor(tester, terminal),
_iconColor(tester, files),
reason: 'the terminal icon must share the colour of Files',
);
expect(
tester
.widget<IconButton>(
find.descendant(of: terminal, matching: find.byType(IconButton)),
)
.isSelected,
isNull,
reason: 'the terminal must not be a selected (tinted) button',
);
expect(find.byTooltip(TerminalToggleButton.label), findsOneWidget);
});
testWidgets('$mode, phone: tapping the terminal button toggles the '
'terminal', (tester) async {
final actions = _Actions();
await _pumpBar(tester, width: 390, theme: theme, actions: actions);
await tester.tap(find.byTooltip(TerminalToggleButton.label));
await tester.pump();
expect(actions.toggles, 1);
});
testWidgets('$mode, wide: the open chat bar has no terminal button (the '
'shell bar keeps it)', (tester) async {
final built = await _pumpBar(
tester,
width: 1000,
theme: theme,
actions: _Actions(),
);
expect(built, isNull);
expect(find.bySemanticsIdentifier(_terminalIdentifier), findsNothing);
});
testWidgets('$mode, phone without a terminal surface: no terminal button', (
tester,
) async {
final built = await _pumpBar(tester, width: 390, theme: theme);
expect(built, isNull);
expect(find.bySemanticsIdentifier(_terminalIdentifier), findsNothing);
});
}
}
@@ -0,0 +1,123 @@
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/semantics.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_adaptive.dart';
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
import 'package:pipelines_app/features/terminal/terminal_scope.dart';
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
import 'terminal_fixtures.dart';
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 _filesKey = ValueKey('files');
const _terminalKey = ValueKey('shell.terminal');
/// A chat's bar: Files beside the terminal toggle, as the shell shows them.
Widget _bar(TerminalLayout layout, _Actions actions, ThemeData theme) =>
MaterialApp(
theme: theme,
home: TerminalScope(
actions: actions,
child: Scaffold(
body: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ChatBarAction(
key: _filesKey,
label: 'Files',
onPressed: () {},
materialIcon: Icons.folder_outlined,
),
TerminalToggleButton(layout: layout),
],
),
),
),
);
/// The colour an icon inside [finder] resolves to in the current theme.
Color? _iconColor(WidgetTester tester, Finder finder) {
final icon = find.descendant(of: finder, matching: find.byType(Icon));
final element = tester.element(icon);
return tester.widget<Icon>(icon).color ?? IconTheme.of(element).color;
}
/// Whether the terminal button's semantics (or one of its merged parents)
/// is announced as toggled on.
bool _toggled(WidgetTester tester) {
for (
SemanticsNode? node = tester.getSemantics(
find.byTooltip(TerminalToggleButton.label),
);
node != null;
node = node.parent
) {
if (node.flagsCollection.isToggled == ui.Tristate.isTrue) return true;
}
return false;
}
void main() {
for (final theme in [
ThemeData(brightness: Brightness.light, useMaterial3: true),
ThemeData(brightness: Brightness.dark, useMaterial3: true),
]) {
final mode = theme.brightness.name;
testWidgets('$mode: the terminal button is a plain bar button, shown or '
'hidden, like Files', (tester) async {
final layout = TerminalLayout(store: MemoryLayoutStore());
final actions = _Actions();
await tester.pumpWidget(_bar(layout, actions, theme));
await tester.pump();
final files = find.byKey(_filesKey);
final terminal = find.byKey(_terminalKey);
for (final shown in [false, true]) {
if (shown) layout.show();
await tester.pump();
final button = tester.widget<IconButton>(terminal);
expect(button.isSelected, isNull, reason: 'shown: $shown');
expect(
_iconColor(tester, terminal),
_iconColor(tester, files),
reason: 'icon colour differs from Files (shown: $shown)',
);
expect(tester.getSize(terminal), tester.getSize(files));
}
});
testWidgets('$mode: the shown state is announced without a tint', (
tester,
) async {
final handle = tester.ensureSemantics();
final layout = TerminalLayout(store: MemoryLayoutStore());
final actions = _Actions();
await tester.pumpWidget(_bar(layout, actions, theme));
await tester.pump();
expect(_toggled(tester), isFalse);
layout.show();
await tester.pump();
expect(_toggled(tester), isTrue);
await tester.tap(find.byKey(_terminalKey));
expect(actions.toggles, 1);
handle.dispose();
});
}
}
@@ -0,0 +1,202 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/walkthrough/first_run_walkthrough.dart';
import 'package:pipelines_app/features/walkthrough/walkthrough_steps.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
const _nextKey = ValueKey<String>('walkthrough.next');
const _backKey = ValueKey<String>('walkthrough.back');
const _skipKey = ValueKey<String>('walkthrough.skip');
const _copyKey = ValueKey<String>('walkthrough.copy');
const _commandKey = ValueKey<String>('walkthrough.command');
const _launchKey = ValueKey<String>('launch');
Widget _launcher({ThemeMode mode = ThemeMode.light, double textScale = 1}) =>
MaterialApp(
theme: appLightTheme(),
darkTheme: appDarkTheme(),
themeMode: mode,
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(textScale)),
child: child!,
),
home: Scaffold(
body: Builder(
builder: (context) => Center(
child: FilledButton(
key: _launchKey,
onPressed: () => showFirstRunWalkthrough(context),
child: const Text('Open'),
),
),
),
),
);
Future<void> _open(WidgetTester tester) async {
await tester.tap(find.byKey(_launchKey));
await tester.pumpAndSettle();
}
void _useViewport(WidgetTester tester, Size size) {
tester.view.devicePixelRatio = 1;
tester.view.physicalSize = size;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
}
void main() {
group('phone layout', () {
testWidgets('opens as a bottom sheet with the first page', (tester) async {
_useViewport(tester, const Size(390, 844));
await tester.pumpWidget(_launcher());
await _open(tester);
expect(find.byType(BottomSheet), findsOneWidget);
expect(find.byType(Dialog), findsNothing);
expect(find.text('Step 1 of 4'), findsOneWidget);
expect(find.text(walkthroughSteps.first.title), findsOneWidget);
});
testWidgets('Back is disabled on the first page; Next advances', (
tester,
) async {
_useViewport(tester, const Size(390, 844));
await tester.pumpWidget(_launcher());
await _open(tester);
expect(tester.widget<TextButton>(find.byKey(_backKey)).onPressed, isNull);
await tester.tap(find.byKey(_nextKey));
await tester.pumpAndSettle();
expect(find.text('Step 2 of 4'), findsOneWidget);
expect(
tester.widget<TextButton>(find.byKey(_backKey)).onPressed,
isNotNull,
);
await tester.tap(find.byKey(_backKey));
await tester.pumpAndSettle();
expect(find.text('Step 1 of 4'), findsOneWidget);
});
testWidgets('walks four pages, Done on the last, Skip on every page', (
tester,
) async {
_useViewport(tester, const Size(390, 844));
await tester.pumpWidget(_launcher());
await _open(tester);
for (var page = 0; page < 3; page++) {
expect(find.byKey(_skipKey), findsOneWidget);
expect(find.text('Next'), findsOneWidget);
await tester.tap(find.byKey(_nextKey));
await tester.pumpAndSettle();
}
expect(find.text('Step 4 of 4'), findsOneWidget);
expect(find.text('Done'), findsOneWidget);
expect(find.byKey(_skipKey), findsOneWidget);
expect(find.text(walkthroughSteps.last.title), findsOneWidget);
await tester.tap(find.text('Done'));
await tester.pumpAndSettle();
expect(find.text(walkthroughSteps.last.title), findsNothing);
});
testWidgets('Skip closes from the middle of the walkthrough', (
tester,
) async {
_useViewport(tester, const Size(390, 844));
await tester.pumpWidget(_launcher());
await _open(tester);
await tester.tap(find.byKey(_nextKey));
await tester.pumpAndSettle();
await tester.tap(find.byKey(_skipKey));
await tester.pumpAndSettle();
expect(find.byType(BottomSheet), findsNothing);
});
});
testWidgets('wide windows open the walkthrough as a dialog', (tester) async {
_useViewport(tester, const Size(1280, 900));
await tester.pumpWidget(_launcher());
await _open(tester);
expect(find.byType(Dialog), findsOneWidget);
expect(find.byType(BottomSheet), findsNothing);
expect(find.text('Step 1 of 4'), findsOneWidget);
await tester.tap(find.byKey(_nextKey));
await tester.pumpAndSettle();
expect(find.text(walkthroughSteps[1].title), findsOneWidget);
});
testWidgets('the harness page offers each agent and copies its command', (
tester,
) async {
_useViewport(tester, const Size(390, 844));
final copied = <String>[];
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform, (call) async {
if (call.method == 'Clipboard.setData') {
copied.add((call.arguments as Map)['text'] as String);
}
return null;
});
addTearDown(
() => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform, null),
);
await tester.pumpWidget(_launcher());
await _open(tester);
await tester.tap(find.byKey(_nextKey));
await tester.pumpAndSettle();
expect(
tester.widget<SelectableText>(find.byKey(_commandKey)).data,
'pipelines harness setup claude',
);
await tester.tap(
find.byKey(const ValueKey<String>('walkthrough.agent.pi')),
);
await tester.pumpAndSettle();
expect(
tester.widget<SelectableText>(find.byKey(_commandKey)).data,
'pipelines harness setup pi',
);
await tester.tap(find.byKey(_copyKey));
await tester.pumpAndSettle();
expect(copied, ['pipelines harness setup pi']);
expect(
find.descendant(
of: find.byKey(_copyKey),
matching: find.byIcon(Icons.check),
),
findsOneWidget,
);
});
testWidgets('large text and dark mode lay out without overflow', (
tester,
) async {
_useViewport(tester, const Size(360, 740));
await tester.pumpWidget(_launcher(mode: ThemeMode.dark, textScale: 2));
await _open(tester);
for (var page = 0; page < walkthroughSteps.length; page++) {
expect(tester.takeException(), isNull, reason: 'page $page');
expect(find.text(walkthroughSteps[page].title), findsOneWidget);
if (page < walkthroughSteps.length - 1) {
// At 2x text the phone sheet scrolls, so Next can start off screen.
await tester.ensureVisible(find.byKey(_nextKey));
await tester.tap(find.byKey(_nextKey));
await tester.pumpAndSettle();
}
}
expect(tester.takeException(), isNull);
});
}
@@ -0,0 +1,341 @@
import 'dart:async';
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/walkthrough/walkthrough_gate.dart';
import 'package:pipelines_app/features/walkthrough/walkthrough_store.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
import 'package:shared_preferences/shared_preferences.dart';
const _welcome = 'Welcome to Pipelines';
Future<SharedPreferences?> _noPreferences() async => null;
/// A gateway that answers the three empty-server list calls from fixed lists.
class _FakeGateway implements ApiGateway {
_FakeGateway({this.runs = const <Object>[], this.failing = false});
/// Runs the server reports; pipelines and chats are always empty here.
final List<Object> runs;
bool failing;
final calls = <String>[];
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
calls.add(type);
if (failing) throw StateError('offline');
return switch (type) {
'list_pipelines' => <String, dynamic>{'pipelines': const <Object>[]},
'list_runs' => <String, dynamic>{'runs': runs},
'chat_sessions' => <String, dynamic>{'chat_sessions': const <Object>[]},
_ => <String, dynamic>{'type': 'error'},
};
}
@override
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
}
/// Delegates to [inner], but holds [isSeen] until [release] so a test can
/// change the page visibility while an offer is still in flight.
class _HeldStore implements WalkthroughStore {
_HeldStore(this.inner);
final MemoryWalkthroughStore inner;
Completer<void>? _gate;
void hold() => _gate = Completer<void>();
void release() {
_gate?.complete();
_gate = null;
}
@override
Future<bool> isSeen() async {
await _gate?.future;
return inner.isSeen();
}
@override
Future<void> markSeen() => inner.markSeen();
@override
Future<bool> wasOffered(String serverScope) =>
inner.wasOffered(serverScope);
@override
Future<void> markOffered(String serverScope) =>
inner.markOffered(serverScope);
}
/// [link] stands in for the session: its value is whether the server connected,
/// and notifying it is the connection transition. Defaults to connected.
Widget _host({
required WalkthroughStore store,
ApiGateway? gateway,
bool enabled = true,
ValueNotifier<bool>? link,
}) {
final session = link ?? ValueNotifier<bool>(true);
return MaterialApp(
theme: appLightTheme(),
darkTheme: appDarkTheme(),
home: Scaffold(
body: FirstRunWalkthroughGate(
store: store,
enabled: enabled,
serverScope: 'server-a',
connection: session,
connected: () => session.value,
gateway: gateway,
child: const Text('Pipelines page'),
),
),
);
}
Future<void> _finishWalkthrough(WidgetTester tester) async {
for (var page = 0; page < 3; page++) {
await tester.tap(find.byKey(const ValueKey<String>('walkthrough.next')));
await tester.pumpAndSettle();
}
await tester.tap(find.text('Done'));
await tester.pumpAndSettle();
}
void main() {
testWidgets('first launch shows the walkthrough once per device', (
tester,
) async {
final store = MemoryWalkthroughStore();
await tester.pumpWidget(_host(store: store));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
await _finishWalkthrough(tester);
expect(find.text(_welcome), findsNothing);
expect(store.seen, isTrue);
// A later launch on the same device does not show it again.
await tester.pumpWidget(const SizedBox());
await tester.pumpWidget(_host(store: store));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(find.text('Pipelines page'), findsOneWidget);
});
testWidgets('Done persists the seen record and no server query runs', (
tester,
) async {
final store = MemoryWalkthroughStore();
final gateway = _FakeGateway();
await tester.pumpWidget(_host(store: store, gateway: gateway));
await tester.pumpAndSettle();
await _finishWalkthrough(tester);
expect(store.seen, isTrue);
expect(
gateway.calls,
isEmpty,
reason: 'first launch needs no server check',
);
});
testWidgets('Skip on the first page persists the seen record', (
tester,
) async {
final store = MemoryWalkthroughStore();
await tester.pumpWidget(_host(store: store));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey<String>('walkthrough.skip')));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(store.seen, isTrue);
});
testWidgets('a seen device on an empty server is offered it once', (
tester,
) async {
final store = MemoryWalkthroughStore(seen: true);
final gateway = _FakeGateway();
await tester.pumpWidget(_host(store: store, gateway: gateway));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
expect(store.offered, {'server-a'});
expect(
gateway.calls,
containsAll(['list_pipelines', 'list_runs', 'chat_sessions']),
);
await tester.tap(find.byKey(const ValueKey<String>('walkthrough.skip')));
await tester.pumpAndSettle();
// The server was offered already, so a fresh mount stays quiet.
await tester.pumpWidget(const SizedBox());
await tester.pumpWidget(_host(store: store, gateway: gateway));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
});
testWidgets(
'a seen device that starts disconnected is offered once it connects',
(tester) async {
// Startup order in the app: the Pipelines page mounts before the session
// has connected. The server must not be asked yet, and the offer must
// still happen after the connection arrives.
final store = MemoryWalkthroughStore(seen: true);
final gateway = _FakeGateway();
final link = ValueNotifier<bool>(false);
await tester.pumpWidget(
_host(store: store, gateway: gateway, link: link),
);
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(
gateway.calls,
isEmpty,
reason: 'no server call while disconnected',
);
expect(store.offered, isEmpty);
link.value = true;
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
expect(store.offered, {'server-a'});
expect(
gateway.calls,
containsAll(['list_pipelines', 'list_runs', 'chat_sessions']),
);
},
);
testWidgets('an unreadable check is retried on the next connection', (
tester,
) async {
final store = MemoryWalkthroughStore(seen: true);
final gateway = _FakeGateway(failing: true);
final link = ValueNotifier<bool>(true);
await tester.pumpWidget(_host(store: store, gateway: gateway, link: link));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(store.offered, isEmpty);
final callsAfterFailure = gateway.calls.length;
// A repeated notification while still connected does not re-query.
link.notifyListeners();
await tester.pumpAndSettle();
expect(gateway.calls.length, callsAfterFailure);
// The server recovers; a fresh connection runs the check and offers it.
gateway.failing = false;
link.value = false;
await tester.pumpAndSettle();
link.value = true;
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
expect(store.offered, {'server-a'});
});
testWidgets('a seen device on a server with work is not offered', (
tester,
) async {
final store = MemoryWalkthroughStore(seen: true);
final gateway = _FakeGateway(
runs: <Object>[
<String, dynamic>{'id': 'run-1'},
],
);
await tester.pumpWidget(_host(store: store, gateway: gateway));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(store.offered, isEmpty);
});
testWidgets('an unreadable server never triggers the walkthrough', (
tester,
) async {
final store = MemoryWalkthroughStore(seen: true);
await tester.pumpWidget(
_host(store: store, gateway: _FakeGateway(failing: true)),
);
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(store.offered, isEmpty);
});
testWidgets('the Pipelines page being hidden defers the check', (
tester,
) async {
final store = MemoryWalkthroughStore();
await tester.pumpWidget(_host(store: store, enabled: false));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(store.seen, isFalse);
await tester.pumpWidget(_host(store: store, enabled: true));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
});
testWidgets(
'hiding Pipelines while an offer is pending keeps the walkthrough closed',
(tester) async {
final inner = MemoryWalkthroughStore();
final store = _HeldStore(inner)..hold();
await tester.pumpWidget(_host(store: store));
await tester.pump();
// The Pipelines page is hidden while the offer is still reading the store.
await tester.pumpWidget(_host(store: store, enabled: false));
store.release();
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(inner.seen, isFalse);
// Showing Pipelines again offers it once, on the same mount.
await tester.pumpWidget(_host(store: store, enabled: true));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
},
);
test('an unavailable preference store reports seen and offered', () async {
// The opener yields no preferences, as when the platform store is absent:
// every read reports "seen" and every write is quietly dropped.
const store = SharedPreferencesWalkthroughStore(open: _noPreferences);
expect(await store.isSeen(), isTrue);
expect(await store.wasOffered('server-a'), isTrue);
await store.markSeen();
await store.markOffered('server-a');
expect(await store.isSeen(), isTrue);
});
test(
'SharedPreferences store records seen and offered under the keys',
() async {
SharedPreferences.setMockInitialValues(<String, Object>{});
const store = SharedPreferencesWalkthroughStore();
expect(await store.isSeen(), isFalse);
await store.markSeen();
expect(await store.isSeen(), isTrue);
expect(await store.wasOffered('server-a'), isFalse);
await store.markOffered('server-a');
expect(await store.wasOffered('server-a'), isTrue);
expect(await store.wasOffered('server-b'), isFalse);
},
);
}
+6 -3
View File
@@ -22,13 +22,16 @@ void main() {
}
for (final width in [390.0, 1000.0]) {
final mount = width < 600 ? 'bottom bar' : 'wide bar';
final mount = width < 600 ? 'bottom bar' : 'rail';
// The rail (wide) or the floating bar (phone) carries the same counts.
final navigation = width < 600
? find.byType(FloatingDestinationBar)
: find.byType(NavigationRail);
testWidgets('$mount shows the count on the Runs tab', (tester) async {
final semantics = tester.ensureSemantics();
await pumpShell(tester, width: width, count: 3);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
expect(find.byType(NavigationRail), findsNothing);
expect(navigation, findsOneWidget);
final badge = find.byKey(const ValueKey('shell.badge.runs.running'));
expect(badge, findsOneWidget);
expect(
+8 -7
View File
@@ -110,22 +110,23 @@ void main() {
testWidgets('wide leading bar under the list, content '
'keeps the width and taps beside the bar reach it', (tester) async {
taps = 0;
await setSize(tester, const Size(1200, 800));
await setSize(tester, const Size(640, 800));
await tester.pumpWidget(shell());
final rect = tester.getRect(pill());
// With no item open the bar still sits under the list column, where it
// sits beside an open item, so it never jumps sides.
expect(rect.left, moreOrLessEquals(kFloatingBarMargin, epsilon: 0.5));
expect(rect.bottom, 800 - 16);
expect(rect.width, lessThan(1200 * 0.6));
expect(rect.width, lessThan(640 * 0.6));
// Captions participate in the bar's content-driven width.
await expectLabeledTargets(tester, rect);
await expectNoSharedBackdrop(tester);
expect(
rect.width,
lessThanOrEqualTo(listDetailListWidth(1200, 1200, null) - 2 * 16),
lessThanOrEqualTo(listDetailListWidth(640, 640, null) - 2 * 16),
);
// No rail or sidebar: the content starts at the left edge.
// Below the rail's window width (see kNavigationRailMinWindowWidth) the
// floating bar still sits under the list: no rail, content at the left edge.
expect(find.byType(NavigationRail), findsNothing);
expect(tester.getRect(find.byKey(const Key('content'))).left, 0);
// Beside the bar, at the bar's height, the content takes the tap.
@@ -141,7 +142,7 @@ void main() {
testWidgets('content learns the bar height as bottom padding', (
tester,
) async {
for (final size in const [Size(390, 844), Size(1200, 800)]) {
for (final size in const [Size(390, 844), Size(640, 800)]) {
await setSize(tester, size);
await tester.pumpWidget(shell());
await tester.pump();
@@ -166,13 +167,13 @@ void main() {
expect(find.text('taps 1'), findsOneWidget);
final state = tester.state(find.byType(StatefulBuilder));
tester.view.physicalSize = const Size(1200, 800);
tester.view.physicalSize = const Size(640, 800);
await tester.pump();
expect(
tester.getRect(pill()).left,
moreOrLessEquals(kFloatingBarMargin, epsilon: 0.5),
);
expect(tester.getRect(pill()).width, lessThan(1200 * 0.6));
expect(tester.getRect(pill()).width, lessThan(640 * 0.6));
expect(tester.state(find.byType(StatefulBuilder)), same(state));
tester.view.physicalSize = const Size(390, 844);
+14 -7
View File
@@ -8,6 +8,7 @@ import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/list_detail.dart';
import 'package:pipelines_app/shell/list_pane_divider.dart';
import 'package:pipelines_app/shell/list_pane_widths.dart';
import 'package:pipelines_app/shell/navigation_rail.dart';
import 'package:pipelines_app/shell/shell_bar.dart';
import 'package:pipelines_app/ui/adaptive/resize_grip.dart';
@@ -66,6 +67,7 @@ void main() {
testWidgets('dragging resizes the list live, the shell bar '
'follows, and the width clamps', (tester) async {
await setSize(tester, const Size(1200, 800));
const body = 1200 - kNavigationRailSpace;
final store = MemoryListPaneWidthStore();
await tester.pumpWidget(shell(store: store));
await settle(tester);
@@ -79,7 +81,7 @@ void main() {
// Live, before the drag ends; nothing saved yet.
expect(listWidth(tester), closeTo(340, 0.5));
expect(shellBarWidth(tester), closeTo(340, 0.5));
expect(bodyWidth(tester), closeTo(1200 - 1 - 340, 0.5));
expect(bodyWidth(tester), closeTo(body - 1 - 340, 0.5));
expect(store.values, isEmpty);
await gesture.up();
await tester.pump();
@@ -92,9 +94,10 @@ void main() {
// ...nor wider than leaves the open item half the window.
await tester.drag(divider, const Offset(900, 0));
await settle(tester);
expect(listWidth(tester), closeTo(1200 - 1 - 600, 0.5));
expect(shellBarWidth(tester), closeTo(599, 0.5));
expect(store.values['runs'], closeTo(599, 0.5));
// Half of the body for the open item, the list the rest.
expect(listWidth(tester), closeTo(body - 1 - body * 0.5, 0.5));
expect(shellBarWidth(tester), closeTo(body - 1 - body * 0.5, 0.5));
expect(store.values['runs'], closeTo(body - 1 - body * 0.5, 0.5));
});
testWidgets('a double tap returns to the default policy', (tester) async {
@@ -143,8 +146,11 @@ void main() {
final store = MemoryListPaneWidthStore({'runs': 600});
await tester.pumpWidget(shell(store: store));
await settle(tester);
expect(listWidth(tester), closeTo(1000 - 1 - 500, 0.5));
expect(shellBarWidth(tester), closeTo(499, 0.5));
// Beside the destination rail the panes lay out in the window's width
// less the rail, so the clamp is the body's: half of it for the open item.
const body = 1000 - kNavigationRailSpace;
expect(listWidth(tester), closeTo(body - 1 - body * 0.5, 0.5));
expect(shellBarWidth(tester), closeTo(body - 1 - body * 0.5, 0.5));
expect(store.values['runs'], 600);
await setSize(tester, const Size(1600, 800));
@@ -212,7 +218,8 @@ void main() {
expect(grip().emphasized, isFalse);
Focus.of(tester.element(divider)).requestFocus();
await tester.pump();
// The focus change reaches the grip one frame later beside the rail.
await tester.pumpAndSettle();
expect(grip().emphasized, isTrue);
});
+283
View File
@@ -0,0 +1,283 @@
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 page 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,
);
// The page's own Back returns to Pipelines, the tab it belongs to.
await tester.tap(find.byKey(const ValueKey('shell.back')));
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('phone and narrow windows keep the floating bar and no rail', (
tester,
) async {
for (final width in [390.0, 640.0]) {
await pumpShell(tester, width: width);
expect(rail(), findsNothing, reason: '$width');
expect(
find.byKey(const ValueKey('shell.destination.settings')),
findsNothing,
reason: '$width',
);
expect(
find.byType(FloatingDestinationBar),
findsOneWidget,
reason: '$width',
);
}
});
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');
}
});
}
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'),
),
);
}
+3 -3
View File
@@ -140,9 +140,9 @@ void main() {
expect(find.text('Its context'), findsOneWidget);
});
testWidgets('1200: the item\'s tabs float at the bottom of its '
testWidgets('640: the item\'s tabs float at the bottom of its '
'pane, the shell\'s tab bar under the list', (tester) async {
await setSize(tester, const Size(1200, 800));
await setSize(tester, const Size(640, 800));
await tester.pumpWidget(shell());
await tester.pump();
await tester.pump();
@@ -168,7 +168,7 @@ void main() {
expect(shellTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
expect(shellTabs.right, lessThanOrEqualTo(list.right));
expect(itemTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
expect(itemTabs.right, closeTo(1200 - kFloatingBarMargin, 0.5));
expect(itemTabs.right, closeTo(640 - kFloatingBarMargin, 0.5));
expect(itemTabs.left, greaterThanOrEqualTo(body.left));
expect(itemTabs.overlaps(shellTabs), isFalse);
// The item's list starts below its bar and clears its tabs at rest.
@@ -0,0 +1,208 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.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/shell_runs_pipelines_shortcut.dart';
import 'package:pipelines_app/ui/input/keyboard_owner.dart';
const _a = KeyDownEvent(
physicalKey: PhysicalKeyboardKey.keyA,
logicalKey: LogicalKeyboardKey.keyA,
timeStamp: Duration.zero,
);
void main() {
test('Ctrl+A matches only with Ctrl alone', () {
bool chord(Set<LogicalKeyboardKey> held, [KeyEvent event = _a]) =>
shellRunsPipelinesShortcut(event, _FakeKeyboard(held));
expect(chord({}), isFalse);
expect(chord({LogicalKeyboardKey.controlLeft}), isTrue);
expect(chord({LogicalKeyboardKey.controlRight}), isTrue);
expect(
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.altLeft}),
isFalse,
);
expect(
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft}),
isFalse,
);
expect(
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.metaLeft}),
isFalse,
);
expect(chord({LogicalKeyboardKey.altLeft}), isFalse);
expect(chord({LogicalKeyboardKey.metaLeft}), isFalse);
expect(
shellRunsPipelinesShortcut(
const KeyUpEvent(
physicalKey: PhysicalKeyboardKey.keyA,
logicalKey: LogicalKeyboardKey.keyA,
timeStamp: Duration.zero,
),
_FakeKeyboard({LogicalKeyboardKey.controlLeft}),
),
isFalse,
);
});
test('Runs goes to Pipelines; every other destination goes to Runs', () {
expect(
shellRunsPipelinesTarget(AppDestination.runs),
AppDestination.pipelines,
);
expect(
shellRunsPipelinesTarget(AppDestination.pipelines),
AppDestination.runs,
);
expect(shellRunsPipelinesTarget(AppDestination.chat), AppDestination.runs);
expect(
shellRunsPipelinesTarget(AppDestination.search),
AppDestination.runs,
);
expect(
shellRunsPipelinesTarget(AppDestination.settings),
AppDestination.runs,
);
});
testWidgets('Ctrl+A bounces Chat, Runs, Pipelines, Runs', (tester) async {
await _onAndroid(() async {
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destinationBodies: {
for (final destination in shellTabDestinations)
destination: (_) => Text('${destination.name} body'),
},
),
),
);
expect(find.text('pipelines body'), isOnstage);
Future<void> pressCtrl(LogicalKeyboardKey key) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(key);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
}
// Reach Chat first with Ctrl+K, then start the Ctrl+A sequence.
await pressCtrl(LogicalKeyboardKey.keyK);
expect(find.text('chat body'), isOnstage);
expect(find.text('pipelines body'), findsNothing);
await pressCtrl(LogicalKeyboardKey.keyA);
expect(find.text('runs body'), isOnstage);
expect(find.text('chat body'), findsNothing);
await pressCtrl(LogicalKeyboardKey.keyA);
expect(find.text('pipelines body'), isOnstage);
expect(find.text('runs body'), findsNothing);
await pressCtrl(LogicalKeyboardKey.keyA);
expect(find.text('runs body'), isOnstage);
expect(find.text('pipelines body'), findsNothing);
expect(tester.takeException(), isNull);
});
});
testWidgets('Ctrl+A is left to a focused text field', (tester) async {
await _onAndroid(() async {
final field = TextEditingController(text: 'draft message');
final focus = FocusNode();
addTearDown(field.dispose);
addTearDown(focus.dispose);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destinationBodies: {
AppDestination.pipelines: (_) =>
TextField(controller: field, focusNode: focus),
AppDestination.runs: (_) => const Text('runs body'),
},
),
),
);
focus.requestFocus();
await tester.pump();
expect(focus.hasPrimaryFocus, isTrue);
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyA);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
// Destination unchanged; the field took the chord (select all on this
// platform), so the text is still there and fully selected.
expect(find.text('runs body'), findsNothing);
expect(field.text, 'draft message');
expect(field.selection.baseOffset, 0);
expect(field.selection.extentOffset, field.text.length);
expect(tester.takeException(), isNull);
});
});
testWidgets('Ctrl+A is left to the terminal while it has focus', (
tester,
) async {
await _onAndroid(() async {
final terminal = FocusNode();
addTearDown(terminal.dispose);
final received = <KeyEvent>[];
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destinationBodies: {
AppDestination.pipelines: (_) => TypingSurface(
child: Focus(
focusNode: terminal,
onKeyEvent: (node, event) {
if (event.logicalKey == LogicalKeyboardKey.keyA) {
received.add(event);
}
return KeyEventResult.ignored;
},
child: const Text('terminal'),
),
),
AppDestination.runs: (_) => const Text('runs body'),
},
),
),
);
terminal.requestFocus();
await tester.pump();
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyA);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
expect(find.text('runs body'), findsNothing);
expect(find.text('terminal'), isOnstage);
expect(received.whereType<KeyDownEvent>(), hasLength(1));
expect(tester.takeException(), isNull);
});
});
}
/// Runs [body] with the platform pinned to Android, so Ctrl+A in a text field
/// means select all everywhere. flutter_test requires the debug override to be
/// cleared before the test body returns, hence the `finally`.
Future<void> _onAndroid(Future<void> Function() body) async {
debugDefaultTargetPlatformOverride = TargetPlatform.android;
try {
await body();
} finally {
debugDefaultTargetPlatformOverride = null;
}
}
class _FakeKeyboard extends HardwareKeyboard {
_FakeKeyboard(this.pressed);
final Set<LogicalKeyboardKey> pressed;
@override
bool isLogicalKeyPressed(LogicalKeyboardKey key) => pressed.contains(key);
}
+12 -11
View File
@@ -106,7 +106,7 @@ void main() {
.first,
);
for (final width in [1200.0, 1600.0]) {
for (final width in [600.0, 640.0]) {
testWidgets('$width split: the destination bar sits under the '
'list and the composer at the detail\'s bottom edge', (tester) async {
await setSize(tester, Size(width, 800));
@@ -211,11 +211,12 @@ void main() {
});
}
testWidgets('1200 split: the bar follows a dragged list width', (
testWidgets('640 split: the bar follows a dragged list width', (
tester,
) async {
await setSize(tester, const Size(1200, 800));
for (final width in [300.0, 520.0]) {
await setSize(tester, const Size(640, 800));
// Within a 640 window's list bounds (at most 0.6 of it, less the body).
for (final width in [260.0, 300.0]) {
final store = MemoryListPaneWidthStore({'chat': width});
await tester.pumpWidget(
KeyedSubtree(
@@ -235,26 +236,26 @@ void main() {
}
});
testWidgets('1200 Settings: a page without a list keeps the bar '
testWidgets('640 Settings: a page without a list keeps the bar '
'at the right edge', (tester) async {
await setSize(tester, const Size(1200, 800));
await setSize(tester, const Size(640, 800));
await tester.pumpWidget(shell(destination: AppDestination.settings));
await tester.pump();
final pill = destinationPill(tester);
expect(pill.right, closeTo(1200 - kFloatingBarMargin, 0.5));
expect(pill.right, closeTo(640 - kFloatingBarMargin, 0.5));
});
testWidgets('1200 unsplit: the bar stays under the list column', (
testWidgets('640 unsplit: the bar stays under the list column', (
tester,
) async {
await setSize(tester, const Size(1200, 800));
await setSize(tester, const Size(640, 800));
await tester.pumpWidget(shell(split: false));
await tester.pump();
final pill = destinationPill(tester);
// Same place as beside an open item (Search has no split), so opening
// or closing an item never moves the bar across the window.
expect(pill.left, closeTo(kFloatingBarMargin, 0.5));
expect(pill.width, lessThan(1200 * 0.6));
expect(pill.width, lessThan(640 * 0.6));
});
testWidgets('390: the bar hugs its tabs at the phone\'s bottom '
@@ -277,7 +278,7 @@ void main() {
expect(pill.right, closeTo(390 - kFloatingBarMargin, 0.5));
});
for (final width in [600.0, 840.0]) {
for (final width in [600.0, 640.0]) {
testWidgets('$width split at 2x: the bar fits the list pane and '
'the item tabs the detail, without overflow', (tester) async {
await setSize(tester, Size(width, 800));
+3 -3
View File
@@ -36,7 +36,7 @@ void main() {
);
Future<void> pumpSplitRun(WidgetTester tester) async {
tester.view.physicalSize = const Size(1200, 800);
tester.view.physicalSize = const Size(640, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = RunDetailFakeGateway(visitRunFixture());
@@ -71,7 +71,7 @@ void main() {
await tester.pumpAndSettle();
}
testWidgets('1200: run tabs float at the pane\'s bottom beside the '
testWidgets('640: run tabs float at the pane\'s bottom beside the '
'shell bar under the list, and the stage page opens in the pane', (
tester,
) async {
@@ -84,7 +84,7 @@ void main() {
final runTabs = pillOf(tester, find.byKey(const Key('run-detail-tabs')));
expect(runTabs.left, greaterThanOrEqualTo(body.left));
expect(runTabs.right, closeTo(1200 - kFloatingBarMargin, 0.5));
expect(runTabs.right, closeTo(640 - kFloatingBarMargin, 0.5));
expect(runTabs.overlaps(main), isFalse);
expect(runTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
+2 -2
View File
@@ -158,7 +158,7 @@ void main() {
testWidgets('split: the item tabs sit at the bottom right of the '
'detail pane, the shell tab bar under the list', (tester) async {
// A gesture-navigation inset as on the unfolded foldable.
await setUp(tester, const Size(1200, 800), bottom: 24);
await setUp(tester, const Size(640, 800), bottom: 24);
await tester.pumpWidget(shell(tabbedItem()));
await tester.pump();
await tester.pump();
@@ -188,7 +188,7 @@ void main() {
expect(shellTabs.bottom, closeTo(800 - 24, 0.5));
expect(shellTabs.right, lessThanOrEqualTo(listPane.right));
expect(tabs.bottom, closeTo(800 - 24, 0.5));
expect(tabs.right, closeTo(1200 - kFloatingBarMargin, 0.5));
expect(tabs.right, closeTo(640 - kFloatingBarMargin, 0.5));
expect(shellTabs.overlaps(tabs), isFalse);
// The item's list clears its tabs at rest.
final list = tester.element(find.byKey(const Key('item-list')));
@@ -0,0 +1,141 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/detail_page.dart';
import 'package:pipelines_app/shell/shell_bar.dart';
import 'package:pipelines_app/ui/motion/container_transform_flight.dart';
import 'package:pipelines_app/ui/motion/container_transform_source.dart';
import 'package:pipelines_app/ui/motion/motion.dart';
const _screen = Size(390, 844);
/// A phone-style owner: its selected row opens a detail page that grows from
/// the row, as the chat screen's page does.
class _Owner extends StatefulWidget {
const _Owner({required this.selection, required this.sources});
final ValueNotifier<String?> selection;
final ContainerTransformSources sources;
@override
State<_Owner> createState() => _OwnerState();
}
class _OwnerState extends State<_Owner> {
final DetailPageHost page = DetailPageHost();
/// Stands in for work the owner might await when the page closes (a draft
/// or scroll save). It never completes, so any pop that waited on it would
/// never start.
final Completer<void> neverSaved = Completer<void>();
int closed = 0;
@override
void dispose() {
page.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => ValueListenableBuilder<String?>(
valueListenable: widget.selection,
builder: (context, selected, _) {
page.sync(
context,
selected: selected != null,
destination: AppDestination.chat,
growFrom: widget.sources.link(() => widget.selection.value),
onClosed: () {
closed++;
unawaited(_save());
widget.selection.value = null;
},
builder: (context) =>
ShellBar(title: 'Chat', child: const Text('chat body')),
);
return ContainerTransformScope(
sources: widget.sources,
child: const Column(
children: [
SizedBox(height: 200),
ContainerTransformSource(
id: '7',
color: Color(0xFFE3F2FD),
child: SizedBox(
key: Key('row-7'),
height: 72,
child: Text('row 7'),
),
),
],
),
);
},
);
Future<void> _save() => neverSaved.future;
}
Future<void> _pumpOwner(
WidgetTester tester,
ValueNotifier<String?> selection,
ContainerTransformSources sources,
) async {
tester.view.physicalSize = _screen;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
home: _Owner(selection: selection, sources: sources),
),
);
}
void main() {
testWidgets(
'system Back changes the route in one frame and shrinks the page at once',
(tester) async {
final selection = ValueNotifier<String?>(null);
final sources = ContainerTransformSources();
await _pumpOwner(tester, selection, sources);
selection.value = '7';
await tester.pumpAndSettle();
final row = tester.getRect(
find.byKey(const Key('row-7'), skipOffstage: false),
);
final route = ModalRoute.of(
tester.element(find.byKey(containerTransformSurfaceKey)),
)!;
expect(route.isCurrent, isTrue);
// The owner's close work never completes, yet Back starts at once.
await tester.binding.handlePopRoute();
await tester.pump();
expect(route.isCurrent, isFalse);
expect(route.animation!.status, AnimationStatus.reverse);
// Two frames after the pop the page is visibly shrinking toward the row.
await tester.pump(const Duration(milliseconds: 16));
final height = tester
.getRect(find.byKey(containerTransformSurfaceKey))
.height;
final travel = _screen.height - row.height;
final shrunk = (_screen.height - height) / travel;
expect(shrunk, greaterThan(0.1));
expect(shrunk, lessThan(1));
// The reverse stays within the standard Material container transform.
expect(
Motion.containerTransformReverse,
lessThanOrEqualTo(const Duration(milliseconds: 300)),
);
await tester.pumpAndSettle();
expect(find.text('chat body'), findsNothing);
expect(selection.value, isNull);
expect(tester.state<_OwnerState>(find.byType(_Owner)).closed, 1);
},
);
}