629c8c6091
After opening an artifact from search the pending flag was never cleared, so later visit selections stopped syncing. It is cleared once the visit page is installed. Adds widget tests: the hit opens the viewer on that artifact, Back lands on its visit and another visit still opens, and a missing artifact shows the notice. Finishes run #231.
364 lines
11 KiB
Dart
364 lines
11 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'run_detail_finders.dart';
|
|
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.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,
|
|
JsonMap? run,
|
|
}) async {
|
|
tester.view.physicalSize = const Size(900, 1000);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
final gateway = RunDetailFakeGateway(run ?? 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);
|
|
expectVisitHeading(tester, 'build', 1);
|
|
});
|
|
}
|
|
|
|
/// The search fixture with one recorded artifact on build (sequence 2).
|
|
JsonMap runWithArtifact() {
|
|
final run = searchSelectionRun();
|
|
final steps = [
|
|
for (final step in run['steps'] as List)
|
|
Map<String, dynamic>.from(step as Map),
|
|
];
|
|
steps[1]['artifacts'] = <dynamic>[
|
|
<String, dynamic>{
|
|
'name': 'release-report.txt',
|
|
'content_type': 'text/plain',
|
|
'size_bytes': 12,
|
|
'url': '/artifacts/77/2/release-report.txt',
|
|
},
|
|
];
|
|
return {...run, 'steps': steps};
|
|
}
|
|
|
|
for (final platform in RunDetailTestPlatform.values) {
|
|
testWidgets('${platform.name} artifact hit opens that artifact, and the '
|
|
'timeline keeps working afterwards', (tester) async {
|
|
final pending = await pumpLiveSelection(
|
|
tester,
|
|
platform,
|
|
const RunSearchSelection(
|
|
runId: 77,
|
|
sequence: 2,
|
|
artifactUrl: '/artifacts/77/2/release-report.txt',
|
|
),
|
|
run: runWithArtifact(),
|
|
);
|
|
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
|
expect(find.text('release-report.txt'), findsWidgets);
|
|
|
|
// Back from the viewer lands on the artifact's visit.
|
|
Navigator.of(tester.element(find.byType(ArtifactViewerPage))).pop();
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(ArtifactViewerPage), findsNothing);
|
|
expectVisitHeading(tester, 'build', 1);
|
|
|
|
// Selecting another visit afterwards still opens it.
|
|
pending.value = const RunSearchSelection(runId: 77, sequence: 5);
|
|
await tester.pumpAndSettle();
|
|
expectVisitHeading(tester, 'plan', 2);
|
|
});
|
|
}
|
|
|
|
testWidgets('a missing artifact opens the run with a notice', (tester) async {
|
|
await pumpSelection(
|
|
tester,
|
|
RunDetailTestPlatform.material,
|
|
const RunSearchSelection(
|
|
runId: 77,
|
|
sequence: 2,
|
|
artifactUrl: '/artifacts/77/2/gone.txt',
|
|
),
|
|
);
|
|
expect(find.byType(ArtifactViewerPage), findsNothing);
|
|
expect(find.text('That artifact is no longer available.'), 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 artifact selection keeps its URL while naming the visit', () {
|
|
final target = resolveRunSearchSelection(
|
|
const RunSearchSelection(
|
|
runId: 77,
|
|
sequence: 2,
|
|
artifactUrl: '/artifacts/77/2/release-report.txt',
|
|
),
|
|
searchSelectionRun(),
|
|
);
|
|
|
|
expect(target, isA<RunArtifactTarget>());
|
|
final artifact = target as RunArtifactTarget;
|
|
expect(artifact.url, '/artifacts/77/2/release-report.txt');
|
|
expect(artifact.visit.stageKey, 'build');
|
|
expect(artifact.visit.timelineIndex, 1);
|
|
});
|
|
|
|
test('an unrecorded sequence falls back to the plain Summary', () {
|
|
_expectSummarySection(
|
|
resolveRunSearchSelection(
|
|
const RunSearchSelection(runId: 77, sequence: 99),
|
|
searchSelectionRun(),
|
|
),
|
|
null,
|
|
);
|
|
});
|
|
});
|
|
}
|