Unify flexible list-detail panes and highlight active pipelines and runs
This commit is contained in:
@@ -0,0 +1,234 @@
|
||||
import 'dart:ui' show Tristate;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/pipelines/screen.dart';
|
||||
import 'package:pipelines_app/features/runs/screen.dart';
|
||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
|
||||
import '../features/pipelines/fixtures.dart';
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final brightness in Brightness.values) {
|
||||
for (final width in [640.0, 840.0, 1280.0]) {
|
||||
testWidgets('shared equal panes and selected rows: $cupertino '
|
||||
'$brightness at $width', (tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = Size(width, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final fixture = PipelineFixture();
|
||||
final gateway = FakeGateway(
|
||||
(type, fields) => switch (type) {
|
||||
'list_pipelines' => pipelineListReply(fixture.summaries),
|
||||
'get_pipeline' => pipelineDetailReply(
|
||||
fixture.detailFor(
|
||||
fields['pipeline_id'] as int,
|
||||
fields['version'] as int,
|
||||
)!,
|
||||
),
|
||||
'list_runs' => {
|
||||
'runs': [
|
||||
for (final id in [1, 2])
|
||||
{'id': id, 'title': 'Run item $id', 'status': 'succeeded'},
|
||||
],
|
||||
},
|
||||
'get_run' => {
|
||||
'run_detail': {
|
||||
'id': fields['run_id'],
|
||||
'title': 'Run item ${fields['run_id']}',
|
||||
'status': 'succeeded',
|
||||
'input': {'prompt': 'Recorded input'},
|
||||
},
|
||||
},
|
||||
'chat_sessions' => {
|
||||
'chat_sessions': [
|
||||
{
|
||||
'id': 'a',
|
||||
'title': 'Chat item a',
|
||||
'backend': 'claude',
|
||||
'model': 'claude-opus',
|
||||
'mode': 'auto',
|
||||
'mode_name': 'Auto',
|
||||
},
|
||||
{
|
||||
'id': 'b',
|
||||
'title': 'Chat item b',
|
||||
'backend': 'claude',
|
||||
'model': 'claude-opus',
|
||||
'mode': 'auto',
|
||||
'mode_name': 'Auto',
|
||||
},
|
||||
],
|
||||
},
|
||||
'chat_messages' => {
|
||||
'chat_history': {'messages': []},
|
||||
},
|
||||
_ => {},
|
||||
},
|
||||
);
|
||||
final shell = AdaptiveShell(
|
||||
cupertino: cupertino,
|
||||
destinationBodies: {
|
||||
AppDestination.pipelines: (_) =>
|
||||
PipelinesScreen(gateway: gateway, embedded: true),
|
||||
AppDestination.runs: (_) => RunsScreen(gateway: gateway),
|
||||
AppDestination.chat: (_) => ChatScreen(gateway: gateway),
|
||||
},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: brightness),
|
||||
home: shell,
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: brightness == Brightness.dark
|
||||
? appDarkTheme()
|
||||
: appLightTheme(),
|
||||
home: shell,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final paneWidths = <double>[];
|
||||
for (final destination in ['Pipelines', 'Runs', 'Chat']) {
|
||||
if (destination != 'Pipelines') {
|
||||
await tester.tap(find.text(destination).first);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.takeException(),
|
||||
isNull,
|
||||
reason: '$destination list',
|
||||
);
|
||||
}
|
||||
final list = find.byKey(const ValueKey('list-detail-list'));
|
||||
final detail = find.byKey(const ValueKey('list-detail-body'));
|
||||
expect(list, findsOneWidget);
|
||||
expect(detail, findsOneWidget);
|
||||
final before = tester.getSize(list).width;
|
||||
paneWidths.add(before);
|
||||
expect(before, closeTo(tester.getSize(detail).width, 0.01));
|
||||
final rowKeys = switch (destination) {
|
||||
'Pipelines' => ['pipeline-row-1', 'pipeline-row-2'],
|
||||
'Runs' => ['run-row-1', 'run-row-2'],
|
||||
_ => ['chat-row-a', 'chat-row-b'],
|
||||
};
|
||||
for (final key in rowKeys) {
|
||||
final target = find.byKey(ValueKey(key));
|
||||
// In a narrow Cupertino list the row center can be a star/menu
|
||||
// control. Open the chat through its title, not a trailing action.
|
||||
await tester.tap(
|
||||
destination == 'Chat'
|
||||
? find.descendant(
|
||||
of: target,
|
||||
matching: find.text('Chat item ${key.split('-').last}'),
|
||||
)
|
||||
: target,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.takeException(),
|
||||
isNull,
|
||||
reason: '$destination after opening $key',
|
||||
);
|
||||
expect(tester.getSize(list).width, closeTo(before, 0.01));
|
||||
expect(tester.getSize(detail).width, closeTo(before, 0.01));
|
||||
expect(
|
||||
tester.state<NavigatorState>(find.byType(Navigator)).canPop(),
|
||||
isFalse,
|
||||
);
|
||||
for (final rowKey in rowKeys) {
|
||||
final row = find.byKey(ValueKey(rowKey));
|
||||
expect(
|
||||
row,
|
||||
findsOneWidget,
|
||||
reason: 'the list must remain visible',
|
||||
);
|
||||
final selected = rowKey == key;
|
||||
expect(
|
||||
tester.getSemantics(row).flagsCollection.isSelected ==
|
||||
Tristate.isTrue,
|
||||
selected,
|
||||
reason: '$destination: $rowKey after opening $key',
|
||||
);
|
||||
final context = tester.element(row);
|
||||
if (cupertino) {
|
||||
final color = destination == 'Runs'
|
||||
? tester.widget<CupertinoButton>(row).color
|
||||
: tester.widget<CupertinoListTile>(row).backgroundColor;
|
||||
expect(
|
||||
color,
|
||||
selected
|
||||
? CupertinoColors.tertiarySystemFill.resolveFrom(
|
||||
context,
|
||||
)
|
||||
: isNull,
|
||||
);
|
||||
} else if (destination == 'Runs') {
|
||||
final id = rowKey.split('-').last;
|
||||
expect(
|
||||
tester
|
||||
.widget<Material>(
|
||||
find.byKey(ValueKey('run-row-surface-$id')),
|
||||
)
|
||||
.color,
|
||||
selected
|
||||
? Theme.of(context).colorScheme.secondaryContainer
|
||||
: Colors.transparent,
|
||||
);
|
||||
} else {
|
||||
final tile = tester.widget<ListTile>(row);
|
||||
expect(tile.selected, selected);
|
||||
expect(
|
||||
tile.selectedTileColor,
|
||||
Theme.of(context).colorScheme.secondaryContainer,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
// A phone still uses stock page navigation; returning to a wide
|
||||
// window must keep the selected item without clearing its route.
|
||||
tester.view.physicalSize = const Size(390, 900);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.state<NavigatorState>(find.byType(Navigator)).canPop(),
|
||||
isTrue,
|
||||
reason: '$destination should push its selected item on a phone',
|
||||
);
|
||||
expect(
|
||||
find.byKey(const ValueKey('list-detail-list')),
|
||||
findsNothing,
|
||||
);
|
||||
tester.view.physicalSize = Size(width, 900);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.state<NavigatorState>(find.byType(Navigator)).canPop(),
|
||||
isFalse,
|
||||
);
|
||||
expect(tester.getSize(list).width, closeTo(before, 0.01));
|
||||
expect(
|
||||
tester
|
||||
.getSemantics(find.byKey(ValueKey(rowKeys.last)))
|
||||
.flagsCollection
|
||||
.isSelected,
|
||||
Tristate.isTrue,
|
||||
);
|
||||
}
|
||||
expect(
|
||||
paneWidths,
|
||||
everyElement(closeTo(paneWidths.first, 0.01)),
|
||||
reason: 'Pipelines, Runs and Chat must use identical pane widths',
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,6 +143,9 @@ void main() {
|
||||
testWidgets('a /runs/1 boot link opens that run and Back returns to /runs', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
@@ -159,6 +162,7 @@ void main() {
|
||||
],
|
||||
);
|
||||
await replyDetail(tester, channel, 1);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Run 1'), findsWidgets);
|
||||
expect(findNativeBack(), findsOneWidget);
|
||||
@@ -166,7 +170,7 @@ void main() {
|
||||
expect(find.text('Pipelines — Not implemented'), findsNothing);
|
||||
|
||||
await tester.tap(findNativeBack());
|
||||
await tester.pump();
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/runs');
|
||||
expect(find.text('Deep-linked run'), findsWidgets);
|
||||
});
|
||||
@@ -259,7 +263,8 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/runs/2');
|
||||
await replyDetail(tester, channel, 2);
|
||||
expect(findNativeBack(), findsOneWidget);
|
||||
expect(findNativeBack(), findsNothing);
|
||||
expect(find.byKey(const ValueKey('run-detail-pane')), findsOneWidget);
|
||||
|
||||
// The engine's browser Back arrives as new route information.
|
||||
await provider.didPushRouteInformation(
|
||||
@@ -278,7 +283,8 @@ void main() {
|
||||
await tester.pump();
|
||||
await replyDetail(tester, channel, 2);
|
||||
await tester.pump();
|
||||
expect(findNativeBack(), findsOneWidget);
|
||||
expect(findNativeBack(), findsNothing);
|
||||
expect(find.byKey(const ValueKey('run-detail-pane')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a malformed boot path is corrected to /pipelines', (
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/runs/screen.dart';
|
||||
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import '../features/runs/ui/run_detail_finders.dart';
|
||||
|
||||
ServerEndpoint webServer() => ServerEndpoint.resolve(
|
||||
base: Uri.parse('http://127.0.0.1:8096/'),
|
||||
@@ -228,13 +229,13 @@ void main() {
|
||||
}),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text('Open run'), findsOneWidget);
|
||||
expect(find.text('Back to list'), findsOneWidget);
|
||||
expect(runDetailText('Open run'), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('run-row-1')), findsOneWidget);
|
||||
|
||||
first.incoming.addError(StateError('network drop'));
|
||||
await tester.pump();
|
||||
expect(find.byType(RunsScreen), findsOneWidget);
|
||||
expect(find.text('Open run'), findsOneWidget);
|
||||
expect(runDetailText('Open run'), findsOneWidget);
|
||||
expect(find.text('Reconnecting to Pipelines…'), findsOneWidget);
|
||||
|
||||
for (
|
||||
@@ -262,7 +263,7 @@ void main() {
|
||||
await tester.pump(const Duration(milliseconds: 10));
|
||||
}
|
||||
final refreshed = detailRequests(second, 1).single;
|
||||
expect(find.text('Open run'), findsOneWidget);
|
||||
expect(runDetailText('Open run'), findsOneWidget);
|
||||
second.incoming.add(
|
||||
jsonEncode({
|
||||
'id': refreshed['id'],
|
||||
@@ -271,8 +272,8 @@ void main() {
|
||||
}),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text('Open run'), findsOneWidget);
|
||||
expect(find.text('Back to list'), findsOneWidget);
|
||||
expect(runDetailText('Open run'), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('run-row-1')), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -324,7 +324,8 @@ void main() {
|
||||
|
||||
expect(provider.value.uri.path, '/runs/2');
|
||||
expect(find.byType(SearchScreen), findsNothing);
|
||||
expect(findNativeBack(), findsOneWidget);
|
||||
expect(findNativeBack(), findsNothing);
|
||||
expect(find.byKey(const ValueKey('run-detail-pane')), findsOneWidget);
|
||||
expect(find.text('Run 2'), findsWidgets);
|
||||
// The shell was never remounted, so the open run was not re-read.
|
||||
expect(requestsOf(channel, 'get_run'), hasLength(1));
|
||||
@@ -409,7 +410,8 @@ void main() {
|
||||
expect(provider.value.uri.path, '/runs/7');
|
||||
await replyRunDetail(tester, channel, 7, index: 1);
|
||||
expect(find.byType(SearchScreen), findsNothing);
|
||||
expect(findNativeBack(), findsOneWidget);
|
||||
expect(findNativeBack(), findsNothing);
|
||||
expect(find.byKey(const ValueKey('run-detail-pane')), findsOneWidget);
|
||||
expect(find.text('Run 7'), findsWidgets);
|
||||
// One app socket carried the search and the run reads.
|
||||
expect(sockets, 1);
|
||||
@@ -651,8 +653,8 @@ void main() {
|
||||
// leaves from the loading placeholder instead.
|
||||
await openArtifactHit(tester, channel);
|
||||
expect(provider.value.uri.path, '/runs/7');
|
||||
expect(findNativeBack(), findsOneWidget);
|
||||
await tester.tap(findNativeBack());
|
||||
expect(find.byKey(const ValueKey('run-detail-pane')), findsOneWidget);
|
||||
await tester.tap(find.text('Back to list'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/runs');
|
||||
@@ -711,7 +713,9 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('run-visit-back')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(findNativeBack());
|
||||
await provider.didPushRouteInformation(
|
||||
RouteInformation(uri: Uri.parse('/runs')),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/runs');
|
||||
|
||||
Reference in New Issue
Block a user