feat(app): render run detail with native Material and Cupertino controls

This commit is contained in:
2026-10-21 14:20:43 +01:00
parent b2b2b56fd3
commit e14bb67825
6 changed files with 867 additions and 99 deletions
@@ -0,0 +1,264 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
enum AppPlatform { material, cupertino }
class FakeGateway implements ApiGateway {
FakeGateway(this.detail);
JsonMap detail;
Object? failure;
Completer<JsonMap>? hold;
@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);
if (hold != null) return hold!.future;
if (failure != null) return Future.error(failure!);
return Future.value({'run_detail': detail});
}
}
const prompt = ' keep\n\nspacing ';
JsonMap runFixture({JsonMap? usage, int steps = 2}) {
final run = <String, dynamic>{
'id': 7,
'title': 'Nightly build',
'name': 'release',
'status': 'succeeded',
'input': {
'prompt': prompt,
'nested': {
'alpha': 1,
'items': [1, 2],
},
},
'output': {
'result': {'ok': true},
},
'steps': [
for (var i = 0; i < steps; i++)
{
'stage': i == 0 ? 'build' : 'test',
'sequence': i + 3,
'status': 'completed',
'outcome': 'success',
'target': '#success',
},
],
};
if (usage != null) run['usage'] = usage;
return run;
}
JsonMap usageFixture({int known = 1}) => {
'stages': 1,
'tokens_total': 0,
'tokens_known_stages': known,
'tokens_in': 0,
'tokens_out': 0,
'split_known': true,
'cost_known_stages': known,
};
Future<void> pumpDetail(
WidgetTester tester,
AppPlatform platform,
RunsController controller, {
VoidCallback? onBack,
bool settle = true,
}) async {
tester.view.physicalSize = const Size(390, 1600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final view = RunDetailView(controller: controller, onBack: onBack ?? () {});
final page = MediaQuery(
data: MediaQueryData.fromView(
tester.view,
).copyWith(textScaler: const TextScaler.linear(2)),
child: view,
);
await tester.pumpWidget(
platform == AppPlatform.material
? MaterialApp(home: Scaffold(body: page))
: CupertinoApp(
home: CupertinoPageScaffold(child: SafeArea(child: page)),
),
);
if (settle) {
await tester.pumpAndSettle();
} else {
await tester.pump();
}
}
void mockClipboard(
WidgetTester tester,
List<String> copied, {
bool Function()? denied,
}) {
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
(call) async {
if (call.method != 'Clipboard.setData') return null;
if (denied?.call() ?? false) {
throw PlatformException(code: 'clipboard-denied');
}
copied.add((call.arguments as Map)['text'] as String);
return null;
},
);
addTearDown(
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
null,
),
);
}
void main() {
late FakeGateway gateway;
late RunsController controller;
setUp(() {
gateway = FakeGateway(runFixture());
controller = RunsController(RunsRepository(gateway));
});
tearDown(() => controller.dispose());
for (final platform in AppPlatform.values) {
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);
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));
} else {
expect(find.byType(Material), findsNothing);
expect(find.byType(Chip), findsNothing);
expect(find.byType(CupertinoExpansionTile), findsNWidgets(2));
}
await tester.tap(find.text('Input'));
await tester.pumpAndSettle();
expect(find.textContaining('"alpha": 1'), findsOneWidget);
await tester.scrollUntilVisible(
find.text('Output'),
200,
scrollable: find.byType(Scrollable).first,
);
await tester.tap(find.text('Output'));
await tester.pumpAndSettle();
expect(find.textContaining('"ok": true'), findsOneWidget);
await tester.scrollUntilVisible(
find.textContaining('build · visit 3'),
200,
scrollable: find.byType(Scrollable).first,
);
expect(find.textContaining('build · visit 3'), findsOneWidget);
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));
}
});
testWidgets('${platform.name} loading and error stay honest', (
tester,
) async {
gateway.hold = Completer<JsonMap>();
final pending = controller.select(1);
await pumpDetail(tester, platform, controller, settle: false);
expect(find.text('Loading run details…'), findsOneWidget);
expect(
find.byType(
platform == AppPlatform.material
? CircularProgressIndicator
: CupertinoActivityIndicator,
),
findsOneWidget,
);
gateway.hold!.complete({'run_detail': runFixture()});
await pending;
await tester.pumpAndSettle();
expect(find.text('Nightly build'), findsOneWidget);
controller.dispose();
gateway = FakeGateway(runFixture())
..failure = StateError('server unavailable');
controller = RunsController(RunsRepository(gateway));
await controller.select(1);
var backs = 0;
await pumpDetail(tester, platform, controller, onBack: () => backs++);
expect(find.textContaining('server unavailable'), findsOneWidget);
await tester.tap(find.text('Back to runs'));
expect(backs, 1);
});
testWidgets('${platform.name} copies the exact prompt and reports denial', (
tester,
) async {
final copied = <String>[];
var denied = false;
mockClipboard(tester, copied, denied: () => denied);
final copy = platform == AppPlatform.material
? find.byTooltip('Copy prompt')
: find.text('Copy prompt');
await controller.select(1);
await pumpDetail(tester, platform, controller);
await tester.tap(copy);
await tester.pumpAndSettle();
expect(copied.single, prompt);
expect(find.text('Prompt copied to clipboard.'), findsOneWidget);
if (platform == AppPlatform.material) {
await tester.pump(const Duration(seconds: 5));
await tester.pumpAndSettle();
}
denied = true;
await tester.tap(copy);
await tester.pumpAndSettle();
expect(find.text('Could not copy prompt to clipboard.'), findsOneWidget);
});
}
testWidgets('reported zero and missing usage stay distinct', (tester) async {
gateway.detail = runFixture(usage: usageFixture());
await controller.select(1);
await pumpDetail(tester, AppPlatform.material, controller);
await tester.tap(find.text('Metrics'));
await tester.pumpAndSettle();
expect(find.text('Unavailable'), findsNothing);
expect(find.text('0'), findsNWidgets(3));
expect(find.text('\$0.000000'), findsOneWidget);
gateway.detail = runFixture(usage: usageFixture(known: 0));
await controller.select(1);
await tester.pumpAndSettle();
expect(find.text('Unavailable'), findsNWidgets(4));
expect(find.text('0'), findsNothing);
});
}