feat(app): add the Graph tab and recorded-stage selection to run detail
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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/graph/widgets/graph_stage_node.dart';
|
||||
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_tab.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
|
||||
|
||||
/// Shared run-detail Graph fixtures and host helpers for the tab tests.
|
||||
enum RunDetailTestPlatform { material, cupertino }
|
||||
|
||||
class RunDetailFakeGateway implements ApiGateway {
|
||||
RunDetailFakeGateway(this.detail);
|
||||
|
||||
JsonMap detail;
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type != 'get_run') throw UnsupportedError(type);
|
||||
return Future.value({'run_detail': detail});
|
||||
}
|
||||
}
|
||||
|
||||
/// plan -> build -> audit, with an implicit failure fallback on plan.
|
||||
JsonMap graphFixture() => <String, dynamic>{
|
||||
'stages': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'key': 'plan',
|
||||
'type': 'model',
|
||||
'edges': <String, String?>{'success': 'build', 'error': '#'},
|
||||
'fallback_error': true,
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': 'build',
|
||||
'type': 'model',
|
||||
'edges': <String, String?>{'success': 'audit', 'error': '#'},
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': 'audit',
|
||||
'type': 'model',
|
||||
'edges': <String, String?>{'success': '#success', 'error': '#failure'},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/// A succeeded run that recorded plan and build; audit stays unvisited.
|
||||
JsonMap graphRunFixture({bool graph = true}) => <String, dynamic>{
|
||||
'id': 51,
|
||||
'title': 'Graph run',
|
||||
'name': 'release',
|
||||
'status': 'succeeded',
|
||||
'input': <String, dynamic>{'prompt': 'ship it'},
|
||||
'output': <String, dynamic>{'result': 'ok'},
|
||||
'steps': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'stage': 'plan',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'outcome': 'success',
|
||||
'target': 'build',
|
||||
},
|
||||
<String, dynamic>{
|
||||
'stage': 'build',
|
||||
'sequence': 2,
|
||||
'status': 'completed',
|
||||
'outcome': 'success',
|
||||
'target': 'audit',
|
||||
},
|
||||
],
|
||||
if (graph) 'graph': graphFixture(),
|
||||
};
|
||||
|
||||
Future<RunsController> pumpRunDetail(
|
||||
WidgetTester tester,
|
||||
RunDetailTestPlatform platform, {
|
||||
JsonMap? run,
|
||||
Size size = const Size(900, 1000),
|
||||
double scale = 1,
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = RunDetailFakeGateway(run ?? graphRunFixture());
|
||||
final controller = RunsController(RunsRepository(gateway));
|
||||
addTearDown(controller.dispose);
|
||||
await controller.select(51);
|
||||
final view = RunDetailView(
|
||||
controller: controller,
|
||||
gateway: gateway,
|
||||
onBack: () {},
|
||||
);
|
||||
final page = MediaQuery(
|
||||
data: MediaQueryData.fromView(
|
||||
tester.view,
|
||||
).copyWith(textScaler: TextScaler.linear(scale)),
|
||||
child: view,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
platform == RunDetailTestPlatform.material
|
||||
? MaterialApp(home: Scaffold(body: page))
|
||||
: CupertinoApp(
|
||||
home: CupertinoPageScaffold(child: SafeArea(child: page)),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return controller;
|
||||
}
|
||||
|
||||
Finder runDetailTab(RunDetailTab tab) =>
|
||||
find.byKey(ValueKey('run-detail-tab-${tab.name}'));
|
||||
|
||||
Future<void> openRunDetailTab(WidgetTester tester, RunDetailTab tab) async {
|
||||
await tester.ensureVisible(runDetailTab(tab));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(runDetailTab(tab));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Finder graphNode(String key) => find.byWidgetPredicate(
|
||||
(widget) => widget is GraphStageNode && widget.node.key == key,
|
||||
);
|
||||
|
||||
Future<void> tapGraphNode(WidgetTester tester, String key) async {
|
||||
final viewport = tester.getRect(find.byType(InteractiveViewer));
|
||||
final node = tester.getRect(graphNode(key));
|
||||
if (!viewport.contains(node.center)) {
|
||||
await tester.drag(
|
||||
find.byType(InteractiveViewer),
|
||||
viewport.center - node.center,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
await tester.tap(graphNode(key), warnIfMissed: false);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/run_graph_canvas.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_tab.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_timeline.dart';
|
||||
|
||||
import 'run_detail_graph_support.dart';
|
||||
|
||||
void main() {
|
||||
for (final platform in RunDetailTestPlatform.values) {
|
||||
testWidgets('${platform.name} Graph draws the recorded run with legend', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpRunDetail(tester, platform);
|
||||
await openRunDetailTab(tester, RunDetailTab.graph);
|
||||
|
||||
expect(find.byType(RunGraphView), findsOneWidget);
|
||||
expect(find.text(runGraphExecuted), findsOneWidget);
|
||||
expect(find.text(runGraphNotExecuted), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<GraphStageNode>(graphNode('plan')).recordedStatus,
|
||||
'completed',
|
||||
);
|
||||
expect(
|
||||
tester.widget<GraphStageNode>(graphNode('build')).recordedStatus,
|
||||
'completed',
|
||||
);
|
||||
expect(
|
||||
tester.widget<GraphStageNode>(graphNode('audit')).recordedStatus,
|
||||
isNull,
|
||||
);
|
||||
final layer = tester.widget<RunGraphEdgeLayer>(
|
||||
find.byType(RunGraphEdgeLayer),
|
||||
);
|
||||
expect(
|
||||
layer.executedRoutes.map((route) => '${route.source}/${route.target}'),
|
||||
['plan/build', 'build/audit'],
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('${platform.name} stage click highlights its recorded visit', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpRunDetail(tester, platform);
|
||||
await openRunDetailTab(tester, RunDetailTab.graph);
|
||||
await tapGraphNode(tester, 'plan');
|
||||
|
||||
// The Graph reports the stage and the detail moves to Timeline, where the
|
||||
// exact recorded visit is selected.
|
||||
expect(find.byType(RunGraphView), findsNothing);
|
||||
expect(
|
||||
find.byKey(const Key('run-detail-tab-body-timeline')),
|
||||
findsOneWidget,
|
||||
);
|
||||
final selected = tester.widget<RunTimelineRow>(
|
||||
find.byKey(const ValueKey('run-timeline-visit-1')),
|
||||
);
|
||||
expect(selected.selected, isTrue);
|
||||
expect(
|
||||
tester
|
||||
.widget<RunTimelineRow>(
|
||||
find.byKey(const ValueKey('run-timeline-visit-2')),
|
||||
)
|
||||
.selected,
|
||||
isFalse,
|
||||
);
|
||||
expect(find.textContaining('audit · visit'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('${platform.name} unvisited node invents no visit', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpRunDetail(tester, platform);
|
||||
await openRunDetailTab(tester, RunDetailTab.graph);
|
||||
// `audit` was never recorded: its node is not a control and a click must
|
||||
// leave the detail on the Graph tab.
|
||||
await tapGraphNode(tester, 'audit');
|
||||
expect(find.byType(RunGraphView), findsOneWidget);
|
||||
expect(
|
||||
find.byKey(const Key('run-detail-tab-body-timeline')),
|
||||
findsNothing,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'${platform.name} programmatic Timeline selection is revealed',
|
||||
(tester) async {
|
||||
await pumpRunDetail(
|
||||
tester,
|
||||
platform,
|
||||
size: const Size(320, 568),
|
||||
scale: 2,
|
||||
);
|
||||
await openRunDetailTab(tester, RunDetailTab.graph);
|
||||
await tapGraphNode(tester, 'plan');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// At 320/2x the strip scrolls. A Graph-driven switch must scroll the
|
||||
// selected Timeline segment into view, not leave Summary/Graph showing.
|
||||
final timeline = tester.getRect(runDetailTab(RunDetailTab.timeline));
|
||||
expect(timeline.left, greaterThanOrEqualTo(0));
|
||||
expect(timeline.right, lessThanOrEqualTo(320));
|
||||
expect(
|
||||
find.byKey(const Key('run-detail-tab-body-timeline')),
|
||||
findsOneWidget,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/title_wording.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_tab.dart';
|
||||
|
||||
import 'run_detail_graph_support.dart';
|
||||
|
||||
void main() {
|
||||
for (final platform in RunDetailTestPlatform.values) {
|
||||
testWidgets('${platform.name} tabs keep the web order and the actions', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpRunDetail(tester, platform);
|
||||
|
||||
for (final label in ['Summary', 'Graph', 'Input', 'Output', 'Timeline']) {
|
||||
expect(find.text(label), findsOneWidget);
|
||||
}
|
||||
var previous = double.negativeInfinity;
|
||||
for (final tab in RunDetailTab.values) {
|
||||
final center = tester.getCenter(runDetailTab(tab));
|
||||
expect(center.dx, greaterThan(previous));
|
||||
previous = center.dx;
|
||||
}
|
||||
expect(find.byKey(runTitleActionKey), findsOneWidget);
|
||||
|
||||
for (final tab in [
|
||||
RunDetailTab.graph,
|
||||
RunDetailTab.input,
|
||||
RunDetailTab.output,
|
||||
RunDetailTab.timeline,
|
||||
RunDetailTab.summary,
|
||||
]) {
|
||||
await openRunDetailTab(tester, tab);
|
||||
expect(find.byKey(runTitleActionKey), findsOneWidget);
|
||||
expect(find.text('Graph run'), findsOneWidget);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('${platform.name} missing graph states the exact wording', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpRunDetail(tester, platform, run: graphRunFixture(graph: false));
|
||||
await openRunDetailTab(tester, RunDetailTab.graph);
|
||||
|
||||
expect(find.text(runGraphMissing), findsOneWidget);
|
||||
expect(find.byType(InteractiveViewer), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('${platform.name} Graph stays bounded at 320 with 2x text', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpRunDetail(
|
||||
tester,
|
||||
platform,
|
||||
size: const Size(320, 568),
|
||||
scale: 2,
|
||||
);
|
||||
await openRunDetailTab(tester, RunDetailTab.graph);
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
final slot = tester.getSize(find.byType(RunGraphView));
|
||||
expect(slot.height, greaterThan(0));
|
||||
expect(slot.width, lessThanOrEqualTo(320));
|
||||
expect(find.byType(InteractiveViewer), findsOneWidget);
|
||||
expect(find.text(runGraphExecuted), findsOneWidget);
|
||||
expect(find.text(runGraphNotExecuted), findsOneWidget);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -79,8 +79,9 @@ Future<void> pumpDetail(
|
||||
FakeGateway gateway, {
|
||||
VoidCallback? onBack,
|
||||
bool settle = true,
|
||||
Size size = const Size(390, 1600),
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(390, 1600);
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
@@ -147,55 +148,68 @@ void main() {
|
||||
testWidgets('${platform.name} detail at 390 with 2x text', (tester) async {
|
||||
gateway.detail = runFixture(steps: 12);
|
||||
await controller.select(1);
|
||||
await pumpDetail(tester, platform, controller, gateway);
|
||||
await pumpDetail(
|
||||
tester,
|
||||
platform,
|
||||
controller,
|
||||
gateway,
|
||||
size: const Size(390, 1200),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text('Nightly build'), findsOneWidget);
|
||||
expect(find.textContaining('Original prompt'), findsOneWidget);
|
||||
if (platform == AppPlatform.material) {
|
||||
expect(find.byType(Chip), findsOneWidget);
|
||||
expect(find.byType(ExpansionTile), findsNWidgets(2));
|
||||
expect(find.byType(ExpansionTile), findsOneWidget);
|
||||
} else {
|
||||
expect(find.byType(Material), findsNothing);
|
||||
expect(find.byType(Chip), findsNothing);
|
||||
expect(find.byType(CupertinoExpansionTile), findsNWidgets(2));
|
||||
expect(find.byType(CupertinoExpansionTile), findsOneWidget);
|
||||
}
|
||||
|
||||
await tester.tap(find.text('Input'));
|
||||
await tester.pumpAndSettle();
|
||||
Future<void> tapTab(String label) async {
|
||||
await tester.ensureVisible(find.text(label));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(label));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
await tapTab('Input');
|
||||
expect(find.textContaining('"alpha": 1'), findsOneWidget);
|
||||
await tester.dragUntilVisible(
|
||||
find.text('Output').hitTestable(),
|
||||
find.byType(ListView).first,
|
||||
const Offset(0, -200),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Output'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.dragUntilVisible(
|
||||
find.textContaining('"ok": true').hitTestable(),
|
||||
find.byType(ListView).first,
|
||||
const Offset(0, -100),
|
||||
);
|
||||
|
||||
await tapTab('Output');
|
||||
expect(find.textContaining('"ok": true'), findsOneWidget);
|
||||
|
||||
await tapTab('Timeline');
|
||||
final timelineScroll = find.descendant(
|
||||
of: find.byKey(const Key('run-detail-tab-body-timeline')),
|
||||
matching: find.byType(Scrollable),
|
||||
);
|
||||
await tester.scrollUntilVisible(
|
||||
find.textContaining('build · visit 3'),
|
||||
200,
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
scrollable: timelineScroll,
|
||||
);
|
||||
expect(find.textContaining('build · visit 3'), findsOneWidget);
|
||||
await tester.scrollUntilVisible(
|
||||
find.textContaining('test · visit 4'),
|
||||
200,
|
||||
scrollable: timelineScroll,
|
||||
);
|
||||
expect(find.textContaining('test · visit 4'), findsOneWidget);
|
||||
if (platform == AppPlatform.material) {
|
||||
final scrollable = tester.state<ScrollableState>(
|
||||
find.byType(Scrollable).first,
|
||||
);
|
||||
final before = scrollable.position.pixels;
|
||||
expect(before, greaterThan(0));
|
||||
gateway.detail = runFixture(steps: 13);
|
||||
await controller.select(1);
|
||||
await tester.pumpAndSettle();
|
||||
expect(scrollable.position.pixels, closeTo(before, 0.1));
|
||||
}
|
||||
|
||||
final before = tester
|
||||
.state<ScrollableState>(timelineScroll)
|
||||
.position
|
||||
.pixels;
|
||||
expect(before, greaterThan(0));
|
||||
gateway.detail = runFixture(steps: 13);
|
||||
await controller.select(1);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.state<ScrollableState>(timelineScroll).position.pixels,
|
||||
closeTo(before, 0.1),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('${platform.name} loading and error stay honest', (
|
||||
|
||||
Reference in New Issue
Block a user