feat(app): add read-only native artifact visit list
Render recorded artifact groups for the active host, with visit-scoped selection and an explicit selection callback. Material uses ListTile, Cupertino uses inset grouped sections with separate heading semantics. Recorded names, MIME and size are shown verbatim with honest fallbacks; nothing is resolved, fetched, previewed, downloaded or fabricated. Adds widget, host and semantics regressions plus an isolated browser probe.
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart';
|
||||
|
||||
import '../domain/artifact_fixtures.dart';
|
||||
|
||||
/// A recorded name long enough to wrap at large text sizes.
|
||||
const longArtifactName =
|
||||
'a-very-long-recorded-artifact-file-name-that-must-wrap-across-'
|
||||
'several-lines-at-large-text-sizes.csv';
|
||||
|
||||
/// The non-breaking space the row inserts between a size value and its unit.
|
||||
const nonBreakingSpace = '\u00a0';
|
||||
|
||||
/// One recorded artifact. An empty [url] falls back to the fixture's url; use
|
||||
/// [unaddressedArtifact] for a record the server sent without one.
|
||||
ArtifactRecord recordedArtifact(
|
||||
String name, {
|
||||
String url = '',
|
||||
String contentType = '',
|
||||
int sizeBytes = 0,
|
||||
}) {
|
||||
return ArtifactRecord.fromJson(
|
||||
artifact(
|
||||
name,
|
||||
url: url.isEmpty ? null : url,
|
||||
contentType: contentType,
|
||||
sizeBytes: sizeBytes,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// A record with no recorded url or content type, never completed locally.
|
||||
///
|
||||
/// [name] defaults to empty, so the record is otherwise entirely unaddressed.
|
||||
ArtifactRecord unaddressedArtifact({String name = ''}) {
|
||||
return ArtifactRecord.fromJson(<String, dynamic>{
|
||||
'name': name,
|
||||
'url': '',
|
||||
'content_type': '',
|
||||
'size_bytes': 0,
|
||||
});
|
||||
}
|
||||
|
||||
ArtifactGroup visitGroup({
|
||||
String stageKey = 'review',
|
||||
int visit = 1,
|
||||
List<ArtifactRecord> artifacts = const <ArtifactRecord>[],
|
||||
}) {
|
||||
return ArtifactGroup(stageKey: stageKey, visit: visit, artifacts: artifacts);
|
||||
}
|
||||
|
||||
/// The list under the native host it is composed into, with the optional
|
||||
/// grouped page colour a gallery must supply.
|
||||
Widget artifactListHost({
|
||||
required bool cupertino,
|
||||
required List<ArtifactGroup> groups,
|
||||
String? selectedIdentity,
|
||||
ArtifactSelected? onSelected,
|
||||
double textScale = 1,
|
||||
}) {
|
||||
final list = ArtifactVisitList(
|
||||
groups: groups,
|
||||
selectedIdentity: selectedIdentity,
|
||||
onSelected: onSelected,
|
||||
);
|
||||
Widget scaled(BuildContext context, Widget? child) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: child ?? const SizedBox.shrink(),
|
||||
);
|
||||
return cupertino
|
||||
? CupertinoApp(
|
||||
builder: scaled,
|
||||
home: CupertinoPageScaffold(
|
||||
backgroundColor: CupertinoColors.systemGroupedBackground,
|
||||
child: list,
|
||||
),
|
||||
)
|
||||
: MaterialApp(
|
||||
builder: scaled,
|
||||
home: Scaffold(body: list),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart';
|
||||
|
||||
import 'artifact_visit_list_fixture.dart';
|
||||
|
||||
List<ArtifactGroup> _threeGroups() => [
|
||||
visitGroup(
|
||||
stageKey: 'build',
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
recordedArtifact(longArtifactName, url: '/artifacts/7/3/long.xlsx'),
|
||||
],
|
||||
),
|
||||
visitGroup(
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
recordedArtifact('result.csv', url: '/artifacts/7/1/result.csv'),
|
||||
recordedArtifact('notes.md', url: '/artifacts/7/1/notes.md'),
|
||||
],
|
||||
),
|
||||
visitGroup(
|
||||
visit: 2,
|
||||
artifacts: [
|
||||
recordedArtifact('result.csv', url: '/artifacts/7/2/result.csv'),
|
||||
],
|
||||
),
|
||||
];
|
||||
|
||||
void main() {
|
||||
testWidgets('every group heading is a header node under both hosts', (
|
||||
tester,
|
||||
) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
|
||||
for (final cupertino in <bool>[false, true]) {
|
||||
await tester.pumpWidget(
|
||||
artifactListHost(cupertino: cupertino, groups: _threeGroups()),
|
||||
);
|
||||
for (final label in <String>[
|
||||
'build · visit 1',
|
||||
'review · visit 1',
|
||||
'review · visit 2',
|
||||
]) {
|
||||
expect(
|
||||
tester.getSemantics(find.text(label)),
|
||||
isSemantics(label: label, isHeader: true),
|
||||
reason:
|
||||
'${cupertino ? 'Cupertino' : 'Material'} must expose $label as a '
|
||||
'heading',
|
||||
);
|
||||
}
|
||||
}
|
||||
handle.dispose();
|
||||
});
|
||||
|
||||
testWidgets('a Cupertino heading stays separate from its single row', (
|
||||
tester,
|
||||
) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
final group = visitGroup(
|
||||
visit: 2,
|
||||
artifacts: [
|
||||
recordedArtifact(
|
||||
'result.csv',
|
||||
url: '/artifacts/7/2/result.csv',
|
||||
contentType: 'text/csv',
|
||||
sizeBytes: 4096,
|
||||
),
|
||||
],
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
artifactListHost(cupertino: true, groups: [group], onSelected: (_, _) {}),
|
||||
);
|
||||
|
||||
final heading = tester.getSemantics(find.text('review · visit 2'));
|
||||
expect(heading, isSemantics(label: 'review · visit 2', isHeader: true));
|
||||
expect(
|
||||
heading.getSemanticsData().hasAction(SemanticsAction.tap),
|
||||
isFalse,
|
||||
reason: 'a heading must never activate the artifact below it',
|
||||
);
|
||||
|
||||
final button = tester.getSemantics(find.byType(CupertinoButton));
|
||||
expect(button, isSemantics(isButton: true, hasTapAction: true));
|
||||
expect(button.label, contains('result.csv'));
|
||||
expect(
|
||||
button.label,
|
||||
isNot(contains('review · visit 2')),
|
||||
reason: 'the row accessible name must not repeat the group heading',
|
||||
);
|
||||
|
||||
final headingRect = tester.getRect(find.text('review · visit 2'));
|
||||
final rowRect = tester.getRect(find.byType(CupertinoButton));
|
||||
expect(
|
||||
rowRect.top,
|
||||
greaterThanOrEqualTo(headingRect.bottom),
|
||||
reason: 'the row must not cover the heading',
|
||||
);
|
||||
handle.dispose();
|
||||
});
|
||||
|
||||
testWidgets('rows without a callback expose no tap action under both hosts', (
|
||||
tester,
|
||||
) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
final group = visitGroup(
|
||||
artifacts: [
|
||||
recordedArtifact('result.csv', url: '/artifacts/7/1/result.csv'),
|
||||
],
|
||||
);
|
||||
|
||||
for (final cupertino in <bool>[false, true]) {
|
||||
await tester.pumpWidget(
|
||||
artifactListHost(cupertino: cupertino, groups: [group]),
|
||||
);
|
||||
final row = tester.getSemantics(find.text('result.csv'));
|
||||
expect(
|
||||
row.getSemanticsData().hasAction(SemanticsAction.tap),
|
||||
isFalse,
|
||||
reason: 'without onSelected the row is read-only',
|
||||
);
|
||||
expect(
|
||||
row,
|
||||
isSemantics(isButton: false),
|
||||
reason: 'a read-only row must not expose a button role',
|
||||
);
|
||||
await tester.tap(find.text('result.csv'));
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
handle.dispose();
|
||||
});
|
||||
|
||||
testWidgets('the selected row carries the selected semantics state', (
|
||||
tester,
|
||||
) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
final first = visitGroup(
|
||||
visit: 1,
|
||||
artifacts: [recordedArtifact('result.csv', url: '/artifacts/7/1/a.csv')],
|
||||
);
|
||||
final second = visitGroup(
|
||||
visit: 2,
|
||||
artifacts: [recordedArtifact('result.csv', url: '/artifacts/7/2/b.csv')],
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
artifactListHost(
|
||||
cupertino: true,
|
||||
groups: [first, second],
|
||||
selectedIdentity: artifactVisitIdentity(
|
||||
second,
|
||||
second.artifacts.single,
|
||||
),
|
||||
onSelected: (_, _) {},
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
tester.getSemantics(find.text('result.csv').last),
|
||||
isSemantics(isSelected: true),
|
||||
);
|
||||
expect(
|
||||
tester.getSemantics(find.text('result.csv').first),
|
||||
isSemantics(isSelected: false),
|
||||
);
|
||||
handle.dispose();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart';
|
||||
|
||||
import 'artifact_visit_list_fixture.dart';
|
||||
|
||||
void main() {
|
||||
test('a shared filename in two visits has distinct identities', () {
|
||||
const url = '/artifacts/7/result.csv';
|
||||
final first = visitGroup(
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
recordedArtifact('result.csv', url: url, contentType: 'text/csv'),
|
||||
],
|
||||
);
|
||||
final second = visitGroup(
|
||||
visit: 2,
|
||||
artifacts: [
|
||||
recordedArtifact('result.csv', url: url, contentType: 'text/csv'),
|
||||
],
|
||||
);
|
||||
|
||||
expect(
|
||||
artifactVisitIdentity(first, first.artifacts.single),
|
||||
isNot(artifactVisitIdentity(second, second.artifacts.single)),
|
||||
);
|
||||
expect(
|
||||
artifactVisitIdentity(first, first.artifacts.single),
|
||||
artifactVisitIdentity(first, first.artifacts.single),
|
||||
);
|
||||
});
|
||||
|
||||
test('an unaddressed record is identified by its recorded name', () {
|
||||
final addressed = visitGroup(
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
recordedArtifact('result.csv', url: '/artifacts/7/1/result.csv'),
|
||||
],
|
||||
);
|
||||
final unaddressed = visitGroup(
|
||||
visit: 1,
|
||||
artifacts: [unaddressedArtifact(name: 'result.csv')],
|
||||
);
|
||||
|
||||
expect(
|
||||
artifactVisitIdentity(unaddressed, unaddressed.artifacts.single),
|
||||
'review\u00001\u0000result.csv',
|
||||
);
|
||||
expect(
|
||||
artifactVisitIdentity(unaddressed, unaddressed.artifacts.single),
|
||||
isNot(artifactVisitIdentity(addressed, addressed.artifacts.single)),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Material rows show recorded visit, MIME and size', (
|
||||
tester,
|
||||
) async {
|
||||
final first = visitGroup(
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
recordedArtifact(
|
||||
'result.csv',
|
||||
url: '/artifacts/7/1/result.csv',
|
||||
contentType: 'text/csv',
|
||||
sizeBytes: 2048,
|
||||
),
|
||||
],
|
||||
);
|
||||
final second = visitGroup(
|
||||
visit: 2,
|
||||
artifacts: [
|
||||
recordedArtifact(
|
||||
'result.csv',
|
||||
url: '/artifacts/7/2/result.csv',
|
||||
contentType: 'text/csv; charset=utf-8',
|
||||
sizeBytes: 4096,
|
||||
),
|
||||
],
|
||||
);
|
||||
ArtifactGroup? pickedGroup;
|
||||
ArtifactRecord? pickedArtifact;
|
||||
await tester.pumpWidget(
|
||||
artifactListHost(
|
||||
cupertino: false,
|
||||
groups: [first, second],
|
||||
selectedIdentity: artifactVisitIdentity(
|
||||
second,
|
||||
second.artifacts.single,
|
||||
),
|
||||
onSelected: (selectedGroup, selectedArtifact) {
|
||||
pickedGroup = selectedGroup;
|
||||
pickedArtifact = selectedArtifact;
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('review · visit 1'), findsOneWidget);
|
||||
expect(find.text('review · visit 2'), findsOneWidget);
|
||||
expect(find.text('result.csv'), findsNWidgets(2));
|
||||
expect(find.text('text/csv · 2.0${nonBreakingSpace}KiB'), findsOneWidget);
|
||||
expect(find.text('text/csv · 4.0${nonBreakingSpace}KiB'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.check), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('result.csv').first);
|
||||
expect(pickedGroup, same(first));
|
||||
expect(pickedArtifact, same(first.artifacts.single));
|
||||
|
||||
await tester.tap(find.text('result.csv').last);
|
||||
expect(pickedGroup, same(second));
|
||||
expect(pickedArtifact!.url, '/artifacts/7/2/result.csv');
|
||||
});
|
||||
|
||||
testWidgets('Cupertino uses grouped native controls and selects per visit', (
|
||||
tester,
|
||||
) async {
|
||||
final first = visitGroup(
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
recordedArtifact('result.csv', url: '/artifacts/7/1/result.csv'),
|
||||
],
|
||||
);
|
||||
final second = visitGroup(
|
||||
visit: 2,
|
||||
artifacts: [
|
||||
recordedArtifact('result.csv', url: '/artifacts/7/2/result.csv'),
|
||||
],
|
||||
);
|
||||
ArtifactGroup? pickedGroup;
|
||||
await tester.pumpWidget(
|
||||
artifactListHost(
|
||||
cupertino: true,
|
||||
groups: [first, second],
|
||||
selectedIdentity: artifactVisitIdentity(first, first.artifacts.single),
|
||||
onSelected: (selectedGroup, _) => pickedGroup = selectedGroup,
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CupertinoListSection), findsNWidgets(2));
|
||||
expect(find.byType(CupertinoButton), findsNWidgets(2));
|
||||
expect(find.byType(ListTile), findsNothing);
|
||||
expect(find.byIcon(CupertinoIcons.check_mark), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('result.csv').last);
|
||||
expect(pickedGroup, same(second));
|
||||
});
|
||||
|
||||
testWidgets('long names wrap at 2x under both native hosts', (tester) async {
|
||||
tester.view.devicePixelRatio = 2;
|
||||
tester.view.physicalSize = const Size(780, 1560);
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final withLongName = visitGroup(
|
||||
visit: 3,
|
||||
artifacts: [
|
||||
recordedArtifact(
|
||||
longArtifactName,
|
||||
url: '/artifacts/7/3/$longArtifactName',
|
||||
contentType:
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
sizeBytes: 123456,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
for (final cupertino in <bool>[false, true]) {
|
||||
await tester.pumpWidget(
|
||||
artifactListHost(
|
||||
cupertino: cupertino,
|
||||
groups: [withLongName],
|
||||
textScale: 2,
|
||||
onSelected: (_, _) {},
|
||||
),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
final name = tester.renderObject<RenderBox>(find.text(longArtifactName));
|
||||
expect(
|
||||
name.size.height,
|
||||
greaterThan(120),
|
||||
reason: 'the recorded name must wrap over several lines, not one',
|
||||
);
|
||||
expect(
|
||||
find.text(
|
||||
'application/vnd.openxmlformats-officedocument.'
|
||||
'spreadsheetml.sheet · 120.6${nonBreakingSpace}KiB',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('a missing name and content type stay explicit', (tester) async {
|
||||
final group = visitGroup(
|
||||
artifacts: [
|
||||
unaddressedArtifact(),
|
||||
recordedArtifact(
|
||||
'notes.md',
|
||||
url: '/artifacts/7/1/notes.md',
|
||||
contentType: 'text/markdown',
|
||||
sizeBytes: 812,
|
||||
),
|
||||
],
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
artifactListHost(cupertino: false, groups: [group]),
|
||||
);
|
||||
|
||||
expect(find.text('(unnamed artifact)'), findsOneWidget);
|
||||
expect(
|
||||
find.text('type not recorded · 0${nonBreakingSpace}B'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('notes.md'), findsOneWidget);
|
||||
expect(
|
||||
find.text('text/markdown · 812${nonBreakingSpace}B'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byIcon(Icons.check), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('empty groups keep the honest empty wording', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
artifactListHost(cupertino: false, groups: const <ArtifactGroup>[]),
|
||||
);
|
||||
expect(find.text('No stage artifacts recorded.'), findsOneWidget);
|
||||
expect(find.byType(ListTile), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user