merge(app): land recorded artifact gallery in run detail
This commit is contained in:
@@ -0,0 +1,321 @@
|
||||
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/artifacts/domain/artifact_groups.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_gallery_page.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart';
|
||||
|
||||
import '../domain/artifact_fixtures.dart';
|
||||
|
||||
enum _Platform { material, cupertino }
|
||||
|
||||
JsonMap _recorded(
|
||||
String name, {
|
||||
String url = '',
|
||||
String contentType = 'text/csv',
|
||||
int sizeBytes = 2048,
|
||||
}) => artifact(
|
||||
name,
|
||||
url: url.isEmpty ? null : url,
|
||||
contentType: contentType,
|
||||
sizeBytes: sizeBytes,
|
||||
);
|
||||
|
||||
/// Two visits of `review` record the same filename; the second visit also
|
||||
/// records `notes.md`. `build` records one file.
|
||||
List<JsonMap> _steps() => <JsonMap>[
|
||||
step(
|
||||
stage: 'build',
|
||||
sequence: 1,
|
||||
visit: 1,
|
||||
artifacts: [_recorded('build.log', contentType: 'text/plain')],
|
||||
),
|
||||
step(
|
||||
stage: 'review',
|
||||
sequence: 2,
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
_recorded('result.csv'),
|
||||
_recorded('notes.md', contentType: 'text/markdown'),
|
||||
],
|
||||
),
|
||||
step(
|
||||
stage: 'review',
|
||||
sequence: 3,
|
||||
visit: 2,
|
||||
artifacts: [_recorded('result.csv', url: '/artifacts/1/2/result.csv')],
|
||||
),
|
||||
];
|
||||
|
||||
Future<void> _pumpGallery(
|
||||
WidgetTester tester,
|
||||
_Platform platform,
|
||||
List<JsonMap> steps, {
|
||||
String configuredEndpoint = '',
|
||||
bool executing = false,
|
||||
Future<bool> Function(Uri)? openExternal,
|
||||
}) async {
|
||||
final page = ArtifactGalleryPage(
|
||||
steps: steps,
|
||||
executing: executing,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
openExternal: openExternal ?? (_) async => true,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
platform == _Platform.material
|
||||
? MaterialApp(home: page)
|
||||
: CupertinoApp(home: page),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Finder _inDialog(_Platform platform, String text) => find.descendant(
|
||||
of: find.byType(
|
||||
platform == _Platform.material ? AlertDialog : CupertinoAlertDialog,
|
||||
),
|
||||
matching: find.text(text),
|
||||
);
|
||||
|
||||
void main() {
|
||||
for (final platform in _Platform.values) {
|
||||
testWidgets('${platform.name}: lists recorded groups and rows', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpGallery(tester, platform, _steps());
|
||||
expect(find.text('Artifacts · 4 recorded'), findsOneWidget);
|
||||
expect(find.text('build · visit 1'), findsOneWidget);
|
||||
expect(find.text('review · visit 1'), findsOneWidget);
|
||||
expect(find.text('review · visit 2'), findsOneWidget);
|
||||
expect(find.text('result.csv'), findsNWidgets(2));
|
||||
expect(find.text('notes.md'), findsOneWidget);
|
||||
expect(find.text('text/markdown · 2.0\u00a0KiB'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('${platform.name}: duplicate filename stays visit distinct', (
|
||||
tester,
|
||||
) async {
|
||||
final steps = _steps();
|
||||
await _pumpGallery(tester, platform, steps);
|
||||
await tester.tap(find.text('result.csv').at(1));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final groups = artifactGroups(steps);
|
||||
final visitTwo = groups.firstWhere(
|
||||
(group) => group.stageKey == 'review' && group.visit == 2,
|
||||
);
|
||||
final list = tester.widget<ArtifactVisitList>(
|
||||
find.byType(ArtifactVisitList),
|
||||
);
|
||||
expect(
|
||||
list.selectedIdentity,
|
||||
artifactVisitIdentity(visitTwo, visitTwo.artifacts.single),
|
||||
);
|
||||
expect(_inDialog(platform, 'review · visit 2'), findsOneWidget);
|
||||
expect(_inDialog(platform, 'review · visit 1'), findsNothing);
|
||||
expect(_inDialog(platform, 'Artifacts · 1 recorded'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('capture notes and partial label come from the visit step', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpGallery(tester, _Platform.material, [
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [_recorded('result.csv'), _recorded('notes.md')],
|
||||
skipped: 2,
|
||||
truncated: 3,
|
||||
),
|
||||
]);
|
||||
expect(
|
||||
find.text('Artifacts · 2 recorded · partial capture'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(find.text('result.csv'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
_inDialog(_Platform.material, 'Artifacts · 2 recorded · partial capture'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
_inDialog(_Platform.material, '2 files excluded from artifact capture.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
_inDialog(
|
||||
_Platform.material,
|
||||
'3 files omitted by artifact capture limits.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('an unavailable capture never claims nothing was recorded', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpGallery(tester, _Platform.material, [
|
||||
step(stage: 'review', visit: 1, includeArtifacts: false),
|
||||
]);
|
||||
expect(find.text('Artifacts · capture unavailable'), findsOneWidget);
|
||||
expect(find.text('No artifacts recorded for this run.'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a recorded empty capture says nothing was recorded', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpGallery(tester, _Platform.material, [
|
||||
step(stage: 'review', visit: 1, artifacts: const []),
|
||||
]);
|
||||
expect(find.text('No artifacts recorded for this run.'), findsOneWidget);
|
||||
expect(find.byType(ArtifactVisitList), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a page with no steps says so explicitly', (tester) async {
|
||||
await _pumpGallery(tester, _Platform.material, const []);
|
||||
expect(find.text('No steps recorded for this run.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Open uses the resolved recorded url only', (tester) async {
|
||||
final opened = <Uri>[];
|
||||
await _pumpGallery(
|
||||
tester,
|
||||
_Platform.material,
|
||||
[
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
_recorded('result.csv', url: '/artifacts/1/1/result.csv'),
|
||||
],
|
||||
),
|
||||
],
|
||||
configuredEndpoint: 'ws://127.0.0.1:8081/connect',
|
||||
openExternal: (uri) async {
|
||||
opened.add(uri);
|
||||
return true;
|
||||
},
|
||||
);
|
||||
await tester.tap(find.text('result.csv'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_inDialog(_Platform.material, 'Open'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(opened, [
|
||||
Uri.parse('http://127.0.0.1:8081/artifacts/1/1/result.csv'),
|
||||
]);
|
||||
expect(find.text('Link opened externally.'), findsOneWidget);
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('an unsafe recorded url offers no open or copy action', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpGallery(tester, _Platform.material, [
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [_recorded('result.csv', url: '//evil.test/result.csv')],
|
||||
),
|
||||
], configuredEndpoint: 'ws://127.0.0.1:8081/connect');
|
||||
await tester.tap(find.text('result.csv'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
_inDialog(
|
||||
_Platform.material,
|
||||
'The recorded artifact URL cannot be opened safely.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(_inDialog(_Platform.material, 'Open'), findsNothing);
|
||||
expect(_inDialog(_Platform.material, 'Copy link'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a record with no url is explicit and offers no action', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpGallery(tester, _Platform.material, [
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
<String, dynamic>{
|
||||
'name': 'result.csv',
|
||||
'url': '',
|
||||
'content_type': 'text/csv',
|
||||
'size_bytes': 10,
|
||||
},
|
||||
],
|
||||
),
|
||||
]);
|
||||
await tester.tap(find.text('result.csv'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
_inDialog(_Platform.material, 'No artifact URL recorded.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(_inDialog(_Platform.material, 'Open'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Copy link copies the resolved url, separate from Open', (
|
||||
tester,
|
||||
) async {
|
||||
final copied = <String>[];
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
copied.add((call.arguments as Map)['text'] as String);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
null,
|
||||
),
|
||||
);
|
||||
final opened = <Uri>[];
|
||||
await _pumpGallery(
|
||||
tester,
|
||||
_Platform.material,
|
||||
[
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
_recorded('result.csv', url: '/artifacts/1/1/result.csv'),
|
||||
],
|
||||
),
|
||||
],
|
||||
configuredEndpoint: 'ws://127.0.0.1:8081/connect',
|
||||
openExternal: (uri) async {
|
||||
opened.add(uri);
|
||||
return true;
|
||||
},
|
||||
);
|
||||
await tester.tap(find.text('result.csv'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_inDialog(_Platform.material, 'Copy link'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(copied, ['http://127.0.0.1:8081/artifacts/1/1/result.csv']);
|
||||
expect(opened, isEmpty);
|
||||
expect(find.text('Link copied.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('an executing run says capture pending', (tester) async {
|
||||
await _pumpGallery(tester, _Platform.material, [
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
includeArtifacts: false,
|
||||
status: 'running',
|
||||
),
|
||||
], executing: true);
|
||||
expect(find.text('Artifacts · capture pending'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
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/artifacts/ui/artifact_gallery_action.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';
|
||||
|
||||
import '../../artifacts/domain/artifact_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 List<JsonMap> steps}) => <String, dynamic>{
|
||||
'id': 21,
|
||||
'title': 'Artifacts wiring run',
|
||||
'name': 'gallery',
|
||||
'status': 'succeeded',
|
||||
'steps': steps,
|
||||
};
|
||||
|
||||
Future<void> _pumpDetail(
|
||||
WidgetTester tester,
|
||||
_Platform platform,
|
||||
RunsController controller,
|
||||
ApiGateway gateway,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(500, 1200);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final view = RunDetailView(
|
||||
controller: controller,
|
||||
gateway: gateway,
|
||||
onBack: () {},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
platform == _Platform.material
|
||||
? MaterialApp(home: Scaffold(body: view))
|
||||
: CupertinoApp(
|
||||
builder: (context, app) => Theme(
|
||||
data: ThemeData(platform: TargetPlatform.iOS),
|
||||
child: app!,
|
||||
),
|
||||
home: CupertinoPageScaffold(child: view),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<RunsController> _loaded(ApiGateway gateway) async {
|
||||
final controller = RunsController(RunsRepository(gateway));
|
||||
await controller.select(21);
|
||||
return controller;
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final platform in _Platform.values) {
|
||||
testWidgets('${platform.name}: the action opens the recorded groups', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _FakeGateway(
|
||||
_run(
|
||||
steps: [
|
||||
step(
|
||||
stage: 'implementer',
|
||||
sequence: 1,
|
||||
artifacts: [
|
||||
artifact(
|
||||
'build.log',
|
||||
contentType: 'text/plain',
|
||||
sizeBytes: 2337,
|
||||
),
|
||||
],
|
||||
),
|
||||
step(
|
||||
stage: 'reviewer',
|
||||
sequence: 2,
|
||||
artifacts: [
|
||||
artifact(
|
||||
'shot.png',
|
||||
contentType: 'image/png',
|
||||
sizeBytes: 80544,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
final controller = await _loaded(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
await _pumpDetail(tester, platform, controller, gateway);
|
||||
|
||||
expect(find.byKey(runArtifactsButtonKey), findsOneWidget);
|
||||
await tester.tap(find.byKey(runArtifactsButtonKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Artifacts · 2 recorded'), findsOneWidget);
|
||||
expect(find.text('build.log'), findsOneWidget);
|
||||
expect(find.text('shot.png'), findsOneWidget);
|
||||
expect(find.text('implementer · visit 1'), findsOneWidget);
|
||||
expect(find.text('reviewer · visit 1'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('the action is offered only when the detail has steps', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _FakeGateway(_run(steps: const []));
|
||||
final controller = await _loaded(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
await _pumpDetail(tester, _Platform.material, controller, gateway);
|
||||
expect(find.byKey(runArtifactsButtonKey), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a recorded empty capture keeps its explicit wording', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _FakeGateway(
|
||||
_run(
|
||||
steps: [step(stage: 'reviewer', visit: 1, artifacts: const [])],
|
||||
),
|
||||
);
|
||||
final controller = await _loaded(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
await _pumpDetail(tester, _Platform.material, controller, gateway);
|
||||
|
||||
await tester.tap(find.byKey(runArtifactsButtonKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('No artifacts recorded for this run.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('an unavailable capture is never reported as empty', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _FakeGateway(
|
||||
_run(steps: [step(stage: 'reviewer', visit: 1, includeArtifacts: false)]),
|
||||
);
|
||||
final controller = await _loaded(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
await _pumpDetail(tester, _Platform.material, controller, gateway);
|
||||
|
||||
await tester.tap(find.byKey(runArtifactsButtonKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Artifacts · capture unavailable'), findsOneWidget);
|
||||
expect(find.text('No artifacts recorded for this run.'), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user