Files
pipelines/app/test/features/runs/ui/run_search_selection_test.dart
T

283 lines
8.4 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_detail_view.dart';
import 'package:pipelines_app/features/runs/ui/run_search_selection.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
import 'run_detail_graph_support.dart';
/// plan visits 5 and 1 around one build visit 2: the server's sequence is not
/// the step's row index, so resolution must read the recorded sequence.
JsonMap searchSelectionRun() => <String, dynamic>{
'id': 77,
'title': 'Search selection run',
'name': 'release',
'status': 'succeeded',
'input': <String, dynamic>{'prompt': 'ship it'},
'output': <String, dynamic>{'result': 'ok'},
'steps': <dynamic>[
<String, dynamic>{
'stage': 'plan',
'sequence': 5,
'status': 'completed',
'outcome': 'success',
},
<String, dynamic>{
'stage': 'build',
'sequence': 2,
'status': 'completed',
'outcome': 'success',
},
<String, dynamic>{
'stage': 'plan',
'sequence': 1,
'status': 'completed',
'outcome': 'success',
},
],
};
/// Pumps one mounted detail under a mutable search scope, returning the notifier
/// that applies a later request to the same detail state.
Future<ValueNotifier<RunSearchSelection?>> pumpLiveSelection(
WidgetTester tester,
RunDetailTestPlatform platform,
RunSearchSelection selection, {
VoidCallback? onConsumed,
}) async {
tester.view.physicalSize = const Size(900, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = RunDetailFakeGateway(searchSelectionRun());
final controller = RunsController(RunsRepository(gateway));
addTearDown(controller.dispose);
await controller.select(77);
final pending = ValueNotifier<RunSearchSelection?>(selection);
addTearDown(pending.dispose);
final page = MediaQuery(
data: MediaQueryData.fromView(tester.view),
child: ValueListenableBuilder<RunSearchSelection?>(
valueListenable: pending,
builder: (context, current, _) => RunSearchSelectionScope(
selection: current,
onConsumed: onConsumed ?? () {},
child: RunDetailView(
controller: controller,
gateway: gateway,
onBack: () {},
),
),
),
);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pumpWidget(
platform == RunDetailTestPlatform.material
? MaterialApp(home: Scaffold(body: page))
: CupertinoApp(
home: CupertinoPageScaffold(child: SafeArea(child: page)),
),
);
await tester.pumpAndSettle();
return pending;
}
Future<void> pumpSelection(
WidgetTester tester,
RunDetailTestPlatform platform,
RunSearchSelection selection, {
VoidCallback? onConsumed,
}) async {
await pumpLiveSelection(tester, platform, selection, onConsumed: onConsumed);
}
/// The browser's `searchFieldTab` mapping, independent of whether a detail is
/// mounted: every text hit names a Summary, expanding only a current section.
void _expectSummarySection(RunSearchTarget target, RunSummarySection? section) {
expect(target, isA<RunSummaryTarget>());
expect((target as RunSummaryTarget).section, section);
}
void main() {
for (final platform in RunDetailTestPlatform.values) {
testWidgets('${platform.name} artifact hit opens its recorded visit', (
tester,
) async {
await pumpSelection(
tester,
platform,
const RunSearchSelection(runId: 77, sequence: 2),
);
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expect(find.text('build · visit 2'), findsOneWidget);
});
}
testWidgets('an unknown artifact sequence opens the plain run', (
tester,
) async {
await pumpSelection(
tester,
RunDetailTestPlatform.material,
const RunSearchSelection(runId: 77, sequence: 99),
);
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
expect(
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
});
for (final platform in RunDetailTestPlatform.values) {
testWidgets('${platform.name} input field expands only the input section', (
tester,
) async {
await pumpSelection(
tester,
platform,
const RunSearchSelection(runId: 77, sequence: 5, field: 'input'),
);
expect(
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
expect(find.text('ship it'), findsOneWidget);
expect(find.text('ok'), findsNothing);
});
testWidgets(
'${platform.name} output field expands only the output section',
(tester) async {
await pumpSelection(
tester,
platform,
const RunSearchSelection(runId: 77, sequence: 5, field: 'output'),
);
expect(
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
expect(find.text('ok'), findsOneWidget);
expect(find.text('ship it'), findsNothing);
},
);
}
testWidgets('a retired field opens the plain Summary', (tester) async {
await pumpSelection(
tester,
RunDetailTestPlatform.material,
const RunSearchSelection(runId: 77, sequence: 5, field: 'evidence'),
);
expect(
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
expect(find.text('ship it'), findsNothing);
expect(find.text('ok'), findsNothing);
});
for (final platform in RunDetailTestPlatform.values) {
testWidgets(
'${platform.name} retired field replaces an open visit with Summary',
(tester) async {
final pending = await pumpLiveSelection(
tester,
platform,
const RunSearchSelection(runId: 77, sequence: 2),
);
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
pending.value = const RunSearchSelection(
runId: 77,
sequence: 5,
field: 'evidence',
);
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
expect(
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
expect(find.text('ship it'), findsNothing);
expect(find.text('ok'), findsNothing);
},
);
}
testWidgets('the search request is consumed once it has been applied', (
tester,
) async {
var consumed = 0;
await pumpSelection(
tester,
RunDetailTestPlatform.material,
const RunSearchSelection(runId: 77, sequence: 2),
onConsumed: () => consumed++,
);
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expect(consumed, 1);
});
group('resolveRunSearchSelection', () {
test('input and output name their Summary section', () {
_expectSummarySection(
resolveRunSearchSelection(
const RunSearchSelection(runId: 77, field: 'input'),
searchSelectionRun(),
),
RunSummarySection.input,
);
_expectSummarySection(
resolveRunSearchSelection(
const RunSearchSelection(runId: 77, field: 'output'),
searchSelectionRun(),
),
RunSummarySection.output,
);
});
test('a retired or unknown field still names the plain Summary', () {
for (final field in ['evidence', 'transcript', 'unknown']) {
_expectSummarySection(
resolveRunSearchSelection(
RunSearchSelection(runId: 77, field: field),
searchSelectionRun(),
),
null,
);
}
});
test('a recorded sequence names its own detail row', () {
final target = resolveRunSearchSelection(
const RunSearchSelection(runId: 77, sequence: 2),
searchSelectionRun(),
);
expect(target, isA<RunVisitTarget>());
expect((target as RunVisitTarget).stageKey, 'build');
expect(target.timelineIndex, 1);
});
test('an unrecorded sequence falls back to the plain Summary', () {
_expectSummarySection(
resolveRunSearchSelection(
const RunSearchSelection(runId: 77, sequence: 99),
searchSelectionRun(),
),
null,
);
});
});
}