Files
pipelines/app/test/features/runs/ui/run_changes_status_test.dart
T
alan b7d5d026f4 fix(app): repair runs test wiring inherited from main
Main's Runs detail now requires the shared gateway, but three inherited
call sites (two Changes tests and the diff wiring probe) still constructed
it without one, and the Cupertino 2x detail test tapped Output before the
reveal scroll had been pumped. Pass the existing fake gateway at each call
site and settle after scrollUntilVisible. No production behaviour changes.
2026-10-21 21:01:09 +01:00

210 lines
6.3 KiB
Dart

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/runs/data/runs_repository.dart';
import 'package:pipelines_app/features/runs/ui/run_changes_action.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
import '../../changes/fixtures.dart';
enum _Platform { material, cupertino }
class _FakeGateway implements ApiGateway {
_FakeGateway(this.detail);
final 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});
}
}
JsonMap _run({
required String status,
JsonMap? fileChanges,
String stepStatus = 'completed',
}) => {
'id': 9,
'title': 'Wiring run',
'name': 'release',
'status': status,
'steps': [
stepFixture(
stage: 'implementer',
sequence: 1,
status: stepStatus,
fileChanges: fileChanges,
),
stepFixture(
stage: 'reviewer',
sequence: 2,
status: stepStatus,
fileChanges: null,
),
],
};
Future<void> _pumpDetail(
WidgetTester tester,
_Platform platform,
JsonMap run, {
Brightness brightness = Brightness.light,
}) async {
tester.view.physicalSize = const Size(500, 1200);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _FakeGateway(run);
final controller = RunsController(RunsRepository(gateway));
addTearDown(controller.dispose);
await controller.select(9);
final view = RunDetailView(
controller: controller,
gateway: gateway,
onBack: () {},
);
await tester.pumpWidget(
platform == _Platform.material
? MaterialApp(
theme: ThemeData(brightness: brightness),
home: Scaffold(body: view),
)
: CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
builder: (context, app) => Theme(
data: ThemeData(platform: TargetPlatform.iOS),
child: app!,
),
home: CupertinoPageScaffold(child: view),
),
);
await tester.pumpAndSettle();
}
Future<void> _openChanges(
WidgetTester tester,
_Platform platform,
JsonMap run, {
Brightness brightness = Brightness.light,
}) async {
await _pumpDetail(tester, platform, run, brightness: brightness);
await tester.tap(find.byKey(runChangesButtonKey));
await tester.pumpAndSettle();
}
void main() {
test('the Changes action waits for the run to stop executing', () {
for (final status in ['queued', 'running', 'waiting', ' RUNNING ']) {
expect(showRunChangesAction({'status': status}), isFalse, reason: status);
}
for (final status in ['succeeded', 'failed', 'canceled', 'interrupted']) {
expect(showRunChangesAction({'status': status}), isTrue, reason: status);
}
// The server can keep a failed run flagged while one of its steps is still
// active; the snapshot page would go stale, so the flag wins.
expect(
showRunChangesAction({'status': 'failed', 'executing': true}),
isFalse,
);
expect(
showRunChangesAction({'status': 'succeeded', 'executing': false}),
isTrue,
);
});
for (final platform in _Platform.values) {
testWidgets(
'${platform.name}: a failed run keeps visit evidence, not a summary',
(tester) async {
await _openChanges(
tester,
platform,
_run(
status: 'failed',
fileChanges: captureFixture(
files: [fileChangeFixture(path: 'lib/feature.dart')],
),
),
);
// The web client shows the aggregate only for succeeded runs.
expect(find.textContaining('file changed ·'), findsNothing);
expect(
find.textContaining('The summary counts each path once'),
findsNothing,
);
// The visit's own recorded capture stays reachable.
expect(find.text('lib/feature.dart'), findsOneWidget);
expect(find.text('Visit 1 · completed'), findsNWidgets(2));
expect(tester.takeException(), isNull);
},
);
testWidgets(
'${platform.name}: an active run offers no snapshot Changes page',
(tester) async {
await _pumpDetail(
tester,
platform,
_run(status: 'running', stepStatus: 'running'),
);
// The opened page would not follow live captures, so an executing run
// has no action until the live visit pane can show them.
expect(find.byKey(runChangesButtonKey), findsNothing);
expect(find.text('Changes'), findsNothing);
expect(tester.takeException(), isNull);
},
);
testWidgets(
'${platform.name}: the Changes page follows a dark host theme',
(tester) async {
await _openChanges(
tester,
platform,
_run(
status: 'succeeded',
fileChanges: captureFixture(
files: [fileChangeFixture(path: 'lib/feature.dart')],
),
),
brightness: Brightness.dark,
);
final header = tester.widget<Text>(
find.textContaining('1 file changed'),
);
final color = header.style?.color;
expect(color, isNotNull);
expect(
color!.computeLuminance(),
greaterThan(0.5),
reason: 'section text must be light on a dark host: $color',
);
// The diff opens on the app Navigator, above the page's theme, so its
// own header must follow the host brightness too.
await tester.tap(
find.byKey(const ValueKey('change-1-lib/feature.dart')),
);
await tester.pumpAndSettle();
final title = tester.widget<Text>(find.text('Modified'));
final titleColor = title.style?.color;
expect(titleColor, isNotNull);
expect(
titleColor!.computeLuminance(),
greaterThan(0.5),
reason: 'diff header must be light on a dark host: $titleColor',
);
expect(tester.takeException(), isNull);
},
);
}
}