feat(app): add native pipelines list and detail screen
Read-only Pipelines screen for the Flutter client: - list_pipelines and list_runs with a last-run join, plus get_pipeline with an explicit version (0 = latest); no mutation requests. - Name, run-presence, last-run-status and schedule filters; six sort orders; clear filters; truthful loading, empty and error states. - Detail Summary, selectable Source and version history with selection and return to latest. - Sequenced list/detail requests so stale replies cannot replace a newer selection or open a cleared one; refresh keeps the selected pipeline and version. - Material controls on Android/desktop and Cupertino on iOS; a per-label segmented tab row at narrow widths and scaled text, with the native control kept wherever an equal share fits. - Fixture probe entry and Chrome scripts for the rendered evidence; widget tests cover filters, sorting, formatting, sequencing, layout and the tab row. Graph rendering remains P2: the Graph tab states that it is pending and exposes a host hook. PipelinesScreen is not yet registered in the shell. Evidence and limits: app/notes/P1.md.
This commit is contained in:
@@ -0,0 +1,219 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
/// One recorded gateway call, so tests can assert exact request shapes.
|
||||
class GatewayCall {
|
||||
GatewayCall(this.type, this.fields);
|
||||
|
||||
final String type;
|
||||
final JsonMap fields;
|
||||
|
||||
@override
|
||||
String toString() => '$type $fields';
|
||||
}
|
||||
|
||||
/// A hand-written gateway. Tests decide every reply; nothing here touches a
|
||||
/// server, socket or shared state.
|
||||
class FakeGateway implements ApiGateway {
|
||||
FakeGateway(this.handler);
|
||||
|
||||
final FutureOr<JsonMap> Function(String type, JsonMap fields) handler;
|
||||
final List<GatewayCall> calls = <GatewayCall>[];
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
calls.add(GatewayCall(type, Map<String, dynamic>.from(fields)));
|
||||
return handler(type, fields);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
|
||||
|
||||
List<GatewayCall> callsOf(String type) =>
|
||||
calls.where((call) => call.type == type).toList(growable: false);
|
||||
}
|
||||
|
||||
Map<String, dynamic> pipelineSummary({
|
||||
required int id,
|
||||
required String name,
|
||||
int version = 1,
|
||||
int stages = 1,
|
||||
String updatedAt = '2026-10-17T21:26:00',
|
||||
int? scheduleCount = 0,
|
||||
bool? scheduled = false,
|
||||
}) => {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'version': version,
|
||||
'stages': stages,
|
||||
'created_at': '2026-10-01T09:00:00',
|
||||
'updated_at': updatedAt,
|
||||
'scheduled': scheduled,
|
||||
'schedule_count': scheduleCount,
|
||||
'enabled_schedule_count': scheduleCount,
|
||||
};
|
||||
|
||||
Map<String, dynamic> pipelineDetail({
|
||||
required int id,
|
||||
required String name,
|
||||
required int version,
|
||||
required int latestVersion,
|
||||
String source = 'name: alpha',
|
||||
int stages = 1,
|
||||
String contentHash = 'abc123',
|
||||
int? scheduleCount = 0,
|
||||
bool? scheduled = false,
|
||||
List<Map<String, dynamic>> versions = const [],
|
||||
}) => {
|
||||
...pipelineSummary(
|
||||
id: id,
|
||||
name: name,
|
||||
version: version,
|
||||
stages: stages,
|
||||
scheduleCount: scheduleCount,
|
||||
scheduled: scheduled,
|
||||
),
|
||||
'latest_version': latestVersion,
|
||||
'version_created_at': '2026-10-17T21:24:00',
|
||||
'content_hash': contentHash,
|
||||
'source': source,
|
||||
'versions': versions,
|
||||
};
|
||||
|
||||
Map<String, dynamic> versionSummary(
|
||||
int version, {
|
||||
int stages = 1,
|
||||
String createdAt = '2026-10-17T21:24:00',
|
||||
}) => {'version': version, 'stages': stages, 'created_at': createdAt};
|
||||
|
||||
Map<String, dynamic> pipelineRun({
|
||||
required int id,
|
||||
required int pipelineId,
|
||||
String status = 'succeeded',
|
||||
String createdAt = '2026-10-17T19:00:00',
|
||||
String finishedAt = '2026-10-17T19:01:05',
|
||||
bool executing = false,
|
||||
}) => {
|
||||
'id': id,
|
||||
'pipeline_id': pipelineId,
|
||||
'status': status,
|
||||
'created_at': createdAt,
|
||||
'finished_at': finishedAt,
|
||||
'executing': executing,
|
||||
};
|
||||
|
||||
JsonMap pipelineListReply(List<Map<String, dynamic>> pipelines) => {
|
||||
'type': 'pipelines',
|
||||
'pipelines': pipelines,
|
||||
};
|
||||
|
||||
JsonMap pipelineDetailReply(Map<String, dynamic> detail) => {
|
||||
'type': 'pipeline',
|
||||
'detail': detail,
|
||||
};
|
||||
|
||||
JsonMap runListReply(List<Map<String, dynamic>> runs) => {
|
||||
'type': 'runs',
|
||||
'runs': runs,
|
||||
};
|
||||
|
||||
JsonMap errorReply(String message) => {'type': 'error', 'error': message};
|
||||
|
||||
/// A small complete fixture used by widget/browser-facing tests.
|
||||
class PipelineFixture {
|
||||
PipelineFixture({this.now});
|
||||
final DateTime? now;
|
||||
|
||||
late final List<Map<String, dynamic>> summaries = [
|
||||
pipelineSummary(
|
||||
id: 1,
|
||||
name: 'Alpha review',
|
||||
version: 2,
|
||||
stages: 2,
|
||||
scheduleCount: 1,
|
||||
scheduled: true,
|
||||
),
|
||||
pipelineSummary(
|
||||
id: 2,
|
||||
name: 'Beta deploy',
|
||||
version: 1,
|
||||
stages: 1,
|
||||
updatedAt: '2026-10-16T08:05:00',
|
||||
scheduleCount: 0,
|
||||
scheduled: false,
|
||||
),
|
||||
pipelineSummary(
|
||||
id: 3,
|
||||
name: 'Gamma legacy',
|
||||
version: 1,
|
||||
stages: 3,
|
||||
updatedAt: '2026-10-15T12:00:00',
|
||||
scheduleCount: null,
|
||||
scheduled: null,
|
||||
),
|
||||
];
|
||||
|
||||
late final List<Map<String, dynamic>> details = [
|
||||
pipelineDetail(
|
||||
id: 1,
|
||||
name: 'Alpha review',
|
||||
version: 2,
|
||||
latestVersion: 2,
|
||||
stages: 2,
|
||||
contentHash: 'hash-alpha',
|
||||
scheduleCount: 1,
|
||||
scheduled: true,
|
||||
source: 'name: Alpha review\nstages:\n review:\n type: model',
|
||||
versions: [versionSummary(1, stages: 1), versionSummary(2, stages: 2)],
|
||||
),
|
||||
pipelineDetail(
|
||||
id: 2,
|
||||
name: 'Beta deploy',
|
||||
version: 1,
|
||||
latestVersion: 1,
|
||||
contentHash: 'hash-beta',
|
||||
source: 'name: Beta deploy\nstages:\n deploy:\n type: human',
|
||||
versions: [versionSummary(1)],
|
||||
),
|
||||
pipelineDetail(
|
||||
id: 3,
|
||||
name: 'Gamma legacy',
|
||||
version: 1,
|
||||
latestVersion: 1,
|
||||
stages: 3,
|
||||
contentHash: 'hash-gamma',
|
||||
scheduleCount: null,
|
||||
scheduled: null,
|
||||
source: 'name: Gamma legacy',
|
||||
versions: [versionSummary(1, stages: 3)],
|
||||
),
|
||||
];
|
||||
|
||||
late final List<Map<String, dynamic>> runs = [
|
||||
pipelineRun(id: 42, pipelineId: 1),
|
||||
pipelineRun(
|
||||
id: 41,
|
||||
pipelineId: 2,
|
||||
status: 'failed',
|
||||
createdAt: '2026-10-16T08:10:00',
|
||||
finishedAt: '2026-10-16T08:11:00',
|
||||
),
|
||||
];
|
||||
|
||||
Map<String, dynamic>? detailFor(int id, int version) {
|
||||
final match = details.where((detail) => detail['id'] == id);
|
||||
if (match.isEmpty) return null;
|
||||
final detail = Map<String, dynamic>.from(match.first);
|
||||
if (version > 0) {
|
||||
detail['version'] = version;
|
||||
for (final row in detail['versions'] as List<Map<String, dynamic>>) {
|
||||
if (row['version'] == version) detail['stages'] = row['stages'];
|
||||
}
|
||||
if (version < (detail['latest_version'] as int)) {
|
||||
detail['source'] = '${detail['source']}\n# selected version $version';
|
||||
}
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_models.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_query.dart';
|
||||
|
||||
import 'fixtures.dart';
|
||||
|
||||
void main() {
|
||||
final alpha = PipelineSummary.fromJson(
|
||||
pipelineSummary(
|
||||
id: 1,
|
||||
name: 'Alpha review',
|
||||
stages: 2,
|
||||
scheduleCount: 1,
|
||||
scheduled: true,
|
||||
),
|
||||
);
|
||||
final beta = PipelineSummary.fromJson(
|
||||
pipelineSummary(
|
||||
id: 2,
|
||||
name: 'Beta deploy',
|
||||
scheduleCount: 0,
|
||||
scheduled: false,
|
||||
),
|
||||
);
|
||||
final gamma = PipelineSummary.fromJson(
|
||||
pipelineSummary(
|
||||
id: 3,
|
||||
name: 'Gamma legacy',
|
||||
scheduleCount: null,
|
||||
scheduled: null,
|
||||
),
|
||||
);
|
||||
final all = [alpha, beta, gamma];
|
||||
final latestRuns = latestRunByPipeline([
|
||||
PipelineRun.fromJson(pipelineRun(id: 5, pipelineId: 1)),
|
||||
PipelineRun.fromJson(pipelineRun(id: 6, pipelineId: 2, status: 'failed')),
|
||||
]);
|
||||
|
||||
test('name and schedule narrow independently', () {
|
||||
expect(
|
||||
filterPipelines(
|
||||
all,
|
||||
const PipelineFilters(name: 'ALPHA'),
|
||||
latestRuns,
|
||||
true,
|
||||
).map((pipeline) => pipeline.id),
|
||||
[1],
|
||||
);
|
||||
expect(
|
||||
filterPipelines(
|
||||
all,
|
||||
const PipelineFilters(schedule: ScheduleFilter.scheduled),
|
||||
latestRuns,
|
||||
true,
|
||||
).map((pipeline) => pipeline.id),
|
||||
[1],
|
||||
);
|
||||
expect(
|
||||
filterPipelines(
|
||||
all,
|
||||
const PipelineFilters(schedule: ScheduleFilter.unscheduled),
|
||||
latestRuns,
|
||||
true,
|
||||
).map((pipeline) => pipeline.id),
|
||||
[2],
|
||||
);
|
||||
});
|
||||
|
||||
test('run facets are skipped until the run history is known', () {
|
||||
const filters = PipelineFilters(presence: RunPresence.noRuns);
|
||||
expect(
|
||||
filterPipelines(
|
||||
all,
|
||||
filters,
|
||||
latestRuns,
|
||||
false,
|
||||
).map((pipeline) => pipeline.id),
|
||||
[1, 2, 3],
|
||||
);
|
||||
expect(
|
||||
filterPipelines(
|
||||
all,
|
||||
filters,
|
||||
latestRuns,
|
||||
true,
|
||||
).map((pipeline) => pipeline.id),
|
||||
[3],
|
||||
);
|
||||
});
|
||||
|
||||
test('last run status needs a matching run', () {
|
||||
expect(
|
||||
filterPipelines(
|
||||
all,
|
||||
const PipelineFilters(lastRunStatuses: {'failed'}),
|
||||
latestRuns,
|
||||
true,
|
||||
).map((pipeline) => pipeline.id),
|
||||
[2],
|
||||
);
|
||||
expect(
|
||||
filterPipelines(
|
||||
all,
|
||||
const PipelineFilters(lastRunStatuses: {'waiting'}),
|
||||
latestRuns,
|
||||
true,
|
||||
),
|
||||
isEmpty,
|
||||
);
|
||||
});
|
||||
|
||||
test('facet counting and empty-state wording', () {
|
||||
const filters = PipelineFilters(
|
||||
name: 'nope',
|
||||
presence: RunPresence.hasRuns,
|
||||
schedule: ScheduleFilter.scheduled,
|
||||
);
|
||||
expect(filters.active, isTrue);
|
||||
expect(filters.count, 3);
|
||||
final empty = pipelineListEmptyState(all, const [], filters);
|
||||
expect(empty?.message, 'No pipelines match the current filters.');
|
||||
expect(empty?.clearAction, 'Clear filters');
|
||||
final onlyName = pipelineListEmptyState(
|
||||
all,
|
||||
const [],
|
||||
const PipelineFilters(name: 'nope'),
|
||||
);
|
||||
expect(onlyName?.message, 'No pipelines match "nope".');
|
||||
expect(
|
||||
pipelineListEmptyState(
|
||||
const [],
|
||||
const [],
|
||||
const PipelineFilters(),
|
||||
)?.message,
|
||||
'No pipelines are defined on this server.',
|
||||
);
|
||||
expect(pipelineListEmptyState(all, all, const PipelineFilters()), isNull);
|
||||
});
|
||||
|
||||
test('run badge omits unusable fragments but keeps the run id', () {
|
||||
final run = PipelineRun.fromJson(
|
||||
pipelineRun(id: 9, pipelineId: 1, createdAt: '', finishedAt: ''),
|
||||
);
|
||||
expect(runBadge(run, DateTime(2026, 10, 17)).metaLine, 'run 9');
|
||||
final executing = PipelineRun.fromJson(
|
||||
pipelineRun(
|
||||
id: 10,
|
||||
pipelineId: 1,
|
||||
status: 'running',
|
||||
createdAt: '2026-10-17T21:00:00',
|
||||
finishedAt: '',
|
||||
executing: true,
|
||||
),
|
||||
);
|
||||
expect(
|
||||
runBadge(executing, DateTime(2026, 10, 17, 21, 2)).metaLine,
|
||||
contains('2m 0s'),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_format.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_models.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_query.dart';
|
||||
|
||||
import 'fixtures.dart';
|
||||
|
||||
void main() {
|
||||
group('formatting', () {
|
||||
test('renders local timestamps, durations and ages', () {
|
||||
expect(formatLocalTimestamp('2026-10-17T21:26:00'), '17 Oct 21:26');
|
||||
expect(formatLocalTimestamp(''), isNull);
|
||||
expect(formatLocalTimestamp('not a time'), isNull);
|
||||
expect(formatDuration(0), '0s');
|
||||
expect(formatDuration(45), '45s');
|
||||
expect(formatDuration(125), '2m 5s');
|
||||
expect(formatDuration(3720), '1h 2m');
|
||||
expect(formatDuration(-4), '0s');
|
||||
expect(stageCountText(1), '1 stage');
|
||||
expect(stageCountText(2), '2 stages');
|
||||
final now = DateTime(2026, 10, 17, 21, 30);
|
||||
expect(formatRanAgo('2026-10-17T21:29:40', now), 'just now');
|
||||
expect(formatRanAgo('2026-10-17T21:25:00', now), '5m ago');
|
||||
expect(formatRanAgo('2026-10-17T19:30:00', now), '2h ago');
|
||||
expect(formatRanAgo('2026-10-14T21:30:00', now), '3d ago');
|
||||
expect(formatRanAgo('2026-10-17T22:00:00', now), 'just now');
|
||||
});
|
||||
|
||||
test('maps the server status vocabulary and unknown values', () {
|
||||
expect(runStateOf('success'), 'succeeded');
|
||||
expect(runStateOf('CANCELLED'), 'canceled');
|
||||
expect(runStateOf('error'), 'failed');
|
||||
expect(runStateOf('mystery'), 'unknown');
|
||||
expect(runStateOf(null), 'unknown');
|
||||
expect(runStateLabel('running'), 'Running');
|
||||
});
|
||||
});
|
||||
|
||||
group('pipeline detail', () {
|
||||
test('parses the get_pipeline detail and resolves latest', () {
|
||||
final detail = PipelineDetail.fromJson(
|
||||
pipelineDetail(
|
||||
id: 7,
|
||||
name: 'Seven',
|
||||
version: 0,
|
||||
latestVersion: 3,
|
||||
source: 'name: seven',
|
||||
versions: [versionSummary(1), versionSummary(2), versionSummary(3)],
|
||||
),
|
||||
);
|
||||
expect(detail.id, 7);
|
||||
expect(detail.latestVersion, 3);
|
||||
expect(detail.resolvedVersion, 3);
|
||||
expect(detail.source, 'name: seven');
|
||||
expect(detail.versions.map((version) => version.version), [1, 2, 3]);
|
||||
expect(pipelineSubtitle(detail), 'id 7 · v0 · 1 stage');
|
||||
expect(pipelineSummaryFields(detail).first.key, 'Content hash');
|
||||
expect(
|
||||
pipelineSummaryFields(
|
||||
detail,
|
||||
).firstWhere((field) => field.key == 'Latest version').value,
|
||||
'v3',
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'schedule state distinguishes configured, absent and unknown peers',
|
||||
() {
|
||||
expect(
|
||||
PipelineSummary.fromJson(
|
||||
pipelineSummary(id: 1, name: 'a', scheduleCount: 2),
|
||||
).scheduleState,
|
||||
PipelineScheduleState.scheduled,
|
||||
);
|
||||
expect(
|
||||
PipelineSummary.fromJson(
|
||||
pipelineSummary(
|
||||
id: 1,
|
||||
name: 'a',
|
||||
scheduleCount: null,
|
||||
scheduled: null,
|
||||
),
|
||||
).scheduleState,
|
||||
PipelineScheduleState.unclassified,
|
||||
);
|
||||
expect(
|
||||
PipelineSummary.fromJson(
|
||||
pipelineSummary(id: 1, name: 'a'),
|
||||
).scheduleLabel,
|
||||
'',
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_models.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_query.dart';
|
||||
|
||||
import 'fixtures.dart';
|
||||
|
||||
void main() {
|
||||
final alpha = PipelineSummary.fromJson(
|
||||
pipelineSummary(id: 3, name: 'alpha', version: 1, stages: 2),
|
||||
);
|
||||
final beta = PipelineSummary.fromJson(
|
||||
pipelineSummary(id: 2, name: 'Beta', version: 1, stages: 1),
|
||||
);
|
||||
final gamma = PipelineSummary.fromJson(
|
||||
pipelineSummary(id: 1, name: 'gamma', version: 1, stages: 3),
|
||||
);
|
||||
final original = [alpha, beta, gamma];
|
||||
|
||||
test('server order is untouched', () {
|
||||
expect(
|
||||
sortPipelines(original, PipelineSort.serverOrder, {}),
|
||||
equals(original),
|
||||
);
|
||||
});
|
||||
|
||||
test('name order is case-insensitive with a stable tie-break', () {
|
||||
expect(
|
||||
sortPipelines(
|
||||
original,
|
||||
PipelineSort.nameAsc,
|
||||
{},
|
||||
).map((pipeline) => pipeline.name),
|
||||
['alpha', 'Beta', 'gamma'],
|
||||
);
|
||||
expect(
|
||||
sortPipelines(
|
||||
original,
|
||||
PipelineSort.nameDesc,
|
||||
{},
|
||||
).map((pipeline) => pipeline.name),
|
||||
['gamma', 'Beta', 'alpha'],
|
||||
);
|
||||
});
|
||||
|
||||
test('stage order uses the name then id tie-break', () {
|
||||
expect(
|
||||
sortPipelines(
|
||||
original,
|
||||
PipelineSort.fewestStages,
|
||||
{},
|
||||
).map((pipeline) => pipeline.id),
|
||||
[2, 3, 1],
|
||||
);
|
||||
expect(
|
||||
sortPipelines(
|
||||
original,
|
||||
PipelineSort.mostStages,
|
||||
{},
|
||||
).map((pipeline) => pipeline.id),
|
||||
[1, 3, 2],
|
||||
);
|
||||
});
|
||||
|
||||
test('most recent run puts pipelines without runs last', () {
|
||||
final runs = latestRunByPipeline([
|
||||
PipelineRun.fromJson(pipelineRun(id: 10, pipelineId: 3)),
|
||||
PipelineRun.fromJson(
|
||||
pipelineRun(id: 12, pipelineId: 3, createdAt: '2026-10-18T18:00:00'),
|
||||
),
|
||||
PipelineRun.fromJson(pipelineRun(id: 11, pipelineId: 2)),
|
||||
]);
|
||||
expect(runs[3]?.id, 12);
|
||||
expect(
|
||||
sortPipelines(
|
||||
original,
|
||||
PipelineSort.recentRun,
|
||||
runs,
|
||||
).map((pipeline) => pipeline.id),
|
||||
[3, 2, 1],
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' show PointerDeviceKind;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/pipelines/widgets/pipeline_tabs.dart';
|
||||
|
||||
const double _paneInset = 16;
|
||||
|
||||
/// A label that wrapped inside its word renders narrower than the width the
|
||||
/// paragraph needs on one line.
|
||||
void expectWholeLabel(WidgetTester tester, String label) {
|
||||
final paragraph = tester.renderObject<RenderParagraph>(find.text(label));
|
||||
expect(
|
||||
paragraph.size.width,
|
||||
greaterThanOrEqualTo(
|
||||
paragraph.getMaxIntrinsicWidth(double.infinity) - 0.01,
|
||||
),
|
||||
reason: '"$label" must not wrap inside the word',
|
||||
);
|
||||
}
|
||||
|
||||
double labelWidth(WidgetTester tester, String label) =>
|
||||
tester.getSize(find.text(label)).width;
|
||||
|
||||
Rect tabRect(WidgetTester tester, PipelineDetailTab tab) =>
|
||||
tester.getRect(find.byKey(ValueKey('pipeline-tab-${tab.name}')));
|
||||
|
||||
Future<void> pumpTabs(
|
||||
WidgetTester tester, {
|
||||
required double width,
|
||||
required double textScale,
|
||||
bool cupertino = false,
|
||||
ValueChanged<PipelineDetailTab>? onSelected,
|
||||
}) async {
|
||||
tester.view.physicalSize = Size(width, 640);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final tabs = StatefulBuilder(
|
||||
builder: (context, setState) => PipelineDetailTabs(
|
||||
selected: PipelineDetailTab.summary,
|
||||
onSelected: (tab) {
|
||||
onSelected?.call(tab);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
);
|
||||
final content = Align(alignment: Alignment.topLeft, child: tabs);
|
||||
Widget scaled(BuildContext context, Widget? child) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: child!,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
builder: scaled,
|
||||
home: CupertinoPageScaffold(child: content),
|
||||
)
|
||||
: MaterialApp(
|
||||
builder: scaled,
|
||||
home: Scaffold(body: content),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final (width, scale) in [
|
||||
(320.0, 1.5),
|
||||
(320.0, 2.0),
|
||||
(390.0, 2.0),
|
||||
(720.0, 2.0),
|
||||
]) {
|
||||
testWidgets(
|
||||
'Material tab labels stay whole at ${width.toInt()}px and ${scale}x text',
|
||||
(tester) async {
|
||||
await pumpTabs(tester, width: width, textScale: scale);
|
||||
expect(tester.takeException(), isNull);
|
||||
for (final tab in PipelineDetailTab.values) {
|
||||
expect(find.text(tab.label), findsOneWidget);
|
||||
expectWholeLabel(tester, tab.label);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('per-label segments size to their own labels', (tester) async {
|
||||
await pumpTabs(tester, width: 320, textScale: 2);
|
||||
final widths = {
|
||||
for (final tab in PipelineDetailTab.values)
|
||||
tab: tabRect(tester, tab).width,
|
||||
};
|
||||
expect(
|
||||
widths[PipelineDetailTab.summary],
|
||||
isNot(widths[PipelineDetailTab.graph]),
|
||||
);
|
||||
expect(
|
||||
widths[PipelineDetailTab.graph],
|
||||
isNot(widths[PipelineDetailTab.source]),
|
||||
);
|
||||
for (final tab in PipelineDetailTab.values) {
|
||||
expect(
|
||||
widths[tab],
|
||||
closeTo(labelWidth(tester, tab.label) + 2 * 8, 0.5),
|
||||
reason: '"${tab.label}" must not get the widest-label share',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('a fitting tab row shows every label inside the pane', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpTabs(tester, width: 320, textScale: 2);
|
||||
final contentWidth =
|
||||
tabRect(tester, PipelineDetailTab.source).right -
|
||||
tabRect(tester, PipelineDetailTab.summary).left;
|
||||
final width = contentWidth + 2 * _paneInset + 2;
|
||||
await pumpTabs(tester, width: width, textScale: 2);
|
||||
expect(tester.takeException(), isNull);
|
||||
for (final tab in PipelineDetailTab.values) {
|
||||
expectWholeLabel(tester, tab.label);
|
||||
final rect = tester.getRect(find.text(tab.label));
|
||||
expect(rect.left, greaterThanOrEqualTo(_paneInset - 0.5));
|
||||
expect(rect.right, lessThanOrEqualTo(width - _paneInset + 0.5));
|
||||
}
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('pipeline-detail-tabs'))).width,
|
||||
closeTo(width - 2 * _paneInset, 0.5),
|
||||
reason: 'a row whose labels fit still fills the pane',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a tab row that overflows only scrolls by the labels\' need', (
|
||||
tester,
|
||||
) async {
|
||||
PipelineDetailTab? selected;
|
||||
await pumpTabs(tester, width: 320, textScale: 2);
|
||||
final contentWidth =
|
||||
tabRect(tester, PipelineDetailTab.source).right -
|
||||
tabRect(tester, PipelineDetailTab.summary).left;
|
||||
final width = contentWidth + 2 * _paneInset - 20;
|
||||
await pumpTabs(
|
||||
tester,
|
||||
width: width,
|
||||
textScale: 2,
|
||||
onSelected: (tab) => selected = tab,
|
||||
);
|
||||
final paneRight = width - _paneInset;
|
||||
final source = tester.getRect(find.text('Source'));
|
||||
expect(
|
||||
tabRect(tester, PipelineDetailTab.source).left,
|
||||
lessThan(paneRight),
|
||||
reason: 'the third tab must not be an empty cell',
|
||||
);
|
||||
expect(
|
||||
math.min(source.right, paneRight) - math.max(source.left, _paneInset),
|
||||
greaterThan(20),
|
||||
reason: 'a readable share of the last label stays in the pane',
|
||||
);
|
||||
expect(source.right, greaterThan(paneRight));
|
||||
|
||||
final row = find.byType(SingleChildScrollView);
|
||||
await tester.drag(
|
||||
row,
|
||||
const Offset(-400, 0),
|
||||
kind: PointerDeviceKind.mouse,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getRect(find.text('Source')).right,
|
||||
lessThanOrEqualTo(paneRight + 0.01),
|
||||
reason: 'the last tab is fully visible after dragging',
|
||||
);
|
||||
await tester.tap(find.text('Source'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(selected, PipelineDetailTab.source);
|
||||
});
|
||||
|
||||
testWidgets('720px at 2x text shows all three labels at rest', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpTabs(tester, width: 720, textScale: 2);
|
||||
for (final tab in PipelineDetailTab.values) {
|
||||
final rect = tester.getRect(find.text(tab.label));
|
||||
expect(rect.left, greaterThanOrEqualTo(_paneInset - 0.5));
|
||||
expect(rect.right, lessThanOrEqualTo(720 - _paneInset + 0.5));
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('a fitting tab row still fills the pane at 1x', (tester) async {
|
||||
await pumpTabs(tester, width: 400, textScale: 1);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('pipeline-detail-tabs'))).width,
|
||||
closeTo(368, 0.5),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('the wide row keeps the platform Material control', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpTabs(tester, width: 1200, textScale: 1);
|
||||
expect(find.byType(SegmentedButton<PipelineDetailTab>), findsOneWidget);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('pipeline-detail-tabs'))).width,
|
||||
closeTo(1168, 0.5),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino tab labels stay whole at 320px and 2x text', (
|
||||
tester,
|
||||
) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
||||
try {
|
||||
await pumpTabs(tester, width: 320, textScale: 2, cupertino: true);
|
||||
expect(tester.takeException(), isNull);
|
||||
// The labels do not fit an equal-share control here, so the per-label
|
||||
// row of standard Cupertino buttons is used.
|
||||
expect(
|
||||
find.byType(CupertinoButton),
|
||||
findsNWidgets(PipelineDetailTab.values.length),
|
||||
);
|
||||
for (final tab in PipelineDetailTab.values) {
|
||||
expectWholeLabel(tester, tab.label);
|
||||
}
|
||||
} finally {
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('Cupertino keeps its native segmented control where it fits', (
|
||||
tester,
|
||||
) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
||||
try {
|
||||
await pumpTabs(tester, width: 1200, textScale: 1, cupertino: true);
|
||||
expect(
|
||||
find.byType(CupertinoSegmentedControl<PipelineDetailTab>),
|
||||
findsOneWidget,
|
||||
);
|
||||
for (final tab in PipelineDetailTab.values) {
|
||||
expectWholeLabel(tester, tab.label);
|
||||
}
|
||||
} finally {
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/pipelines/screen.dart';
|
||||
import 'package:pipelines_app/features/pipelines/widgets/pipeline_tabs.dart';
|
||||
|
||||
import 'fixtures.dart';
|
||||
import 'test_helpers.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('narrow layout is list then detail with a native back', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final fixture = PipelineFixture();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: PipelinesScreen(gateway: gatewayFor(fixture))),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('pipeline-list')), findsOneWidget);
|
||||
expect(find.byKey(const Key('pipeline-detail')), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('pipeline-row-1')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('pipeline-list')), findsNothing);
|
||||
expect(find.byKey(const Key('pipeline-detail')), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byTooltip('Back to pipelines'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('pipeline-list')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'2x text at 390px keeps list and detail scrollable without overflow',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final fixture = PipelineFixture();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: const TextScaler.linear(2)),
|
||||
child: child!,
|
||||
),
|
||||
home: PipelinesScreen(gateway: gatewayFor(fixture)),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text('Alpha review'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipeline-row-1')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.ensureVisible(find.text('Source'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Source'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(
|
||||
selectableText(
|
||||
'name: Alpha review\nstages:\n review:\n type: model',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('wide layout at 2x text renders both panes', (tester) async {
|
||||
tester.view.physicalSize = const Size(1100, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final fixture = PipelineFixture();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: const TextScaler.linear(2)),
|
||||
child: child!,
|
||||
),
|
||||
home: PipelinesScreen(gateway: gatewayFor(fixture)),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('pipeline-row-1')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byKey(const Key('pipeline-list')), findsOneWidget);
|
||||
expect(find.byKey(const Key('pipeline-detail')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('iOS uses Cupertino scaffolds, list tiles and segmented tabs', (
|
||||
tester,
|
||||
) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
||||
tester.view.physicalSize = const Size(1100, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final fixture = PipelineFixture();
|
||||
try {
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(home: PipelinesScreen(gateway: gatewayFor(fixture))),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(CupertinoPageScaffold), findsOneWidget);
|
||||
expect(find.byType(CupertinoListTile), findsWidgets);
|
||||
expect(find.byType(CupertinoActionSheet), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('pipeline-row-1')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.byType(CupertinoSegmentedControl<PipelineDetailTab>),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byType(CupertinoListTile), findsWidgets);
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipeline-version-1')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Viewing v1 (latest v2).'), findsOneWidget);
|
||||
await tester.tap(find.text('Source'));
|
||||
await tester.pump();
|
||||
expect(
|
||||
selectableText(
|
||||
'name: Alpha review\nstages:\n review:\n type: model\n'
|
||||
'# selected version 1',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
} finally {
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('hosted graph hook receives the selected pipeline and stage', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = PipelineFixture();
|
||||
PipelineStageRef? selected;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: PipelinesScreen(
|
||||
gateway: gatewayFor(fixture),
|
||||
graphBuilder: (context, detail, onStageSelected) => Column(
|
||||
children: [
|
||||
Text('HOSTED GRAPH ${detail.id} v${detail.resolvedVersion}'),
|
||||
TextButton(
|
||||
onPressed: () => onStageSelected('review'),
|
||||
child: const Text('Stage review'),
|
||||
),
|
||||
],
|
||||
),
|
||||
onStageSelected: (ref) => selected = ref,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('pipeline-row-1')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Graph'));
|
||||
await tester.pump();
|
||||
expect(find.text('HOSTED GRAPH 1 v2'), findsOneWidget);
|
||||
await tester.tap(find.text('Stage review'));
|
||||
expect(selected?.pipelineId, 1);
|
||||
expect(selected?.version, 2);
|
||||
expect(selected?.stageKey, 'review');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_repository.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipelines_controller.dart';
|
||||
|
||||
import 'fixtures.dart';
|
||||
|
||||
PipelinesController controllerFor(FakeGateway gateway) =>
|
||||
PipelinesController(PipelinesRepository(gateway));
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'opening a pipeline requests the row version and parses detail',
|
||||
() async {
|
||||
final fixture = PipelineFixture();
|
||||
final gateway = FakeGateway(
|
||||
(type, fields) => switch (type) {
|
||||
'list_pipelines' => pipelineListReply(fixture.summaries),
|
||||
'list_runs' => runListReply(fixture.runs),
|
||||
'get_pipeline' => pipelineDetailReply(
|
||||
fixture.detailFor(
|
||||
fields['pipeline_id'] as int,
|
||||
fields['version'] as int,
|
||||
)!,
|
||||
),
|
||||
_ => errorReply('unexpected $type'),
|
||||
},
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
await controller.load();
|
||||
await controller.openPipeline(1, version: 2);
|
||||
|
||||
expect(gateway.callsOf('get_pipeline').single.fields, {
|
||||
'pipeline_id': 1,
|
||||
'version': 2,
|
||||
});
|
||||
expect(controller.detail?.id, 1);
|
||||
expect(controller.detail?.resolvedVersion, 2);
|
||||
expect(controller.selectedVersion, 2);
|
||||
},
|
||||
);
|
||||
|
||||
test('a stale detail reply cannot replace the newer selection', () async {
|
||||
final fixture = PipelineFixture();
|
||||
final first = Completer<Map<String, dynamic>>();
|
||||
final second = Completer<Map<String, dynamic>>();
|
||||
final gateway = FakeGateway(
|
||||
(type, fields) => switch (type) {
|
||||
'list_pipelines' => pipelineListReply(fixture.summaries),
|
||||
'list_runs' => runListReply(fixture.runs),
|
||||
'get_pipeline' =>
|
||||
fields['pipeline_id'] == 1 ? first.future : second.future,
|
||||
_ => errorReply('unexpected $type'),
|
||||
},
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
await controller.load();
|
||||
|
||||
final firstRequest = controller.openPipeline(1, version: 2);
|
||||
final secondRequest = controller.openPipeline(2, version: 1);
|
||||
expect(controller.selectedId, 2);
|
||||
first.complete(pipelineDetailReply(fixture.details[0]));
|
||||
await firstRequest;
|
||||
expect(
|
||||
controller.detail,
|
||||
isNull,
|
||||
reason: 'the late reply belongs to the discarded selection',
|
||||
);
|
||||
expect(controller.detailLoading, isTrue);
|
||||
|
||||
second.complete(pipelineDetailReply(fixture.details[1]));
|
||||
await secondRequest;
|
||||
expect(controller.detail?.id, 2);
|
||||
expect(controller.detail?.name, 'Beta deploy');
|
||||
});
|
||||
|
||||
test('a late reply after Back cannot reopen the cleared detail', () async {
|
||||
final fixture = PipelineFixture();
|
||||
final reply = Completer<Map<String, dynamic>>();
|
||||
final gateway = FakeGateway(
|
||||
(type, fields) => switch (type) {
|
||||
'list_pipelines' => pipelineListReply(fixture.summaries),
|
||||
'list_runs' => runListReply(fixture.runs),
|
||||
'get_pipeline' => reply.future,
|
||||
_ => errorReply('unexpected $type'),
|
||||
},
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
await controller.load();
|
||||
final request = controller.openPipeline(1, version: 2);
|
||||
controller.clearSelection();
|
||||
reply.complete(pipelineDetailReply(fixture.details[0]));
|
||||
await request;
|
||||
expect(controller.detail, isNull);
|
||||
expect(controller.selectedId, isNull);
|
||||
});
|
||||
|
||||
test(
|
||||
'version selection requests that exact version and latest again',
|
||||
() async {
|
||||
final fixture = PipelineFixture();
|
||||
final gateway = FakeGateway(
|
||||
(type, fields) => switch (type) {
|
||||
'list_pipelines' => pipelineListReply(fixture.summaries),
|
||||
'list_runs' => runListReply(fixture.runs),
|
||||
'get_pipeline' => pipelineDetailReply(
|
||||
fixture.detailFor(
|
||||
fields['pipeline_id'] as int,
|
||||
fields['version'] as int,
|
||||
)!,
|
||||
),
|
||||
_ => errorReply('unexpected $type'),
|
||||
},
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
await controller.load();
|
||||
await controller.openPipeline(1, version: 2);
|
||||
await controller.selectVersion(1);
|
||||
|
||||
expect(controller.selectedVersion, 1);
|
||||
expect(controller.detail?.source, contains('# selected version 1'));
|
||||
expect(gateway.callsOf('get_pipeline').last.fields, {
|
||||
'pipeline_id': 1,
|
||||
'version': 1,
|
||||
});
|
||||
|
||||
await controller.selectVersion(0);
|
||||
expect(controller.selectedVersion, 0);
|
||||
expect(gateway.callsOf('get_pipeline').last.fields, {
|
||||
'pipeline_id': 1,
|
||||
'version': 0,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
test('a detail refusal keeps the selection and names the reason', () async {
|
||||
final fixture = PipelineFixture();
|
||||
final gateway = FakeGateway(
|
||||
(type, fields) => switch (type) {
|
||||
'list_pipelines' => pipelineListReply(fixture.summaries),
|
||||
'list_runs' => runListReply(fixture.runs),
|
||||
'get_pipeline' => errorReply('pipeline 9 was not found'),
|
||||
_ => errorReply('unexpected $type'),
|
||||
},
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
await controller.load();
|
||||
await controller.openPipeline(9);
|
||||
expect(controller.detailError, 'pipeline 9 was not found');
|
||||
expect(controller.selectedId, 9);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_query.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_repository.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipelines_controller.dart';
|
||||
|
||||
import 'fixtures.dart';
|
||||
|
||||
PipelinesController controllerFor(FakeGateway gateway) =>
|
||||
PipelinesController(PipelinesRepository(gateway));
|
||||
|
||||
Future<void> settle() => Future<void>.delayed(Duration.zero);
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'load sends exact list and runs requests and parses the envelopes',
|
||||
() async {
|
||||
final fixture = PipelineFixture();
|
||||
final gateway = FakeGateway(
|
||||
(type, fields) => switch (type) {
|
||||
'list_pipelines' => pipelineListReply(fixture.summaries),
|
||||
'list_runs' => runListReply(fixture.runs),
|
||||
_ => errorReply('unexpected $type'),
|
||||
},
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
await controller.load();
|
||||
|
||||
expect(gateway.calls.map((call) => call.type).toList(), [
|
||||
'list_pipelines',
|
||||
'list_runs',
|
||||
]);
|
||||
expect(gateway.calls[0].fields, isEmpty);
|
||||
expect(gateway.calls[1].fields, isEmpty);
|
||||
expect(controller.pipelines.map((pipeline) => pipeline.id), [1, 2, 3]);
|
||||
expect(controller.pipelinesLoaded, isTrue);
|
||||
expect(controller.runsLoaded, isTrue);
|
||||
expect(controller.latestRuns[1]?.id, 42);
|
||||
expect(controller.listError, isNull);
|
||||
expect(controller.runsError, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
test('refresh keeps the selected pipeline and requested version', () async {
|
||||
final fixture = PipelineFixture();
|
||||
final summaries = List<Map<String, dynamic>>.of(fixture.summaries);
|
||||
final gateway = FakeGateway(
|
||||
(type, fields) => switch (type) {
|
||||
'list_pipelines' => pipelineListReply(summaries),
|
||||
'list_runs' => runListReply(fixture.runs),
|
||||
'get_pipeline' => pipelineDetailReply(
|
||||
fixture.detailFor(
|
||||
fields['pipeline_id'] as int,
|
||||
fields['version'] as int,
|
||||
)!,
|
||||
),
|
||||
_ => errorReply('unexpected $type'),
|
||||
},
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
await controller.load();
|
||||
await controller.openPipeline(2, version: 1);
|
||||
summaries[1] = pipelineSummary(id: 2, name: 'Beta deploy renamed');
|
||||
|
||||
await controller.load();
|
||||
|
||||
expect(controller.selectedId, 2);
|
||||
expect(controller.selectedVersion, 1);
|
||||
expect(controller.detail?.id, 2);
|
||||
expect(controller.pipelines[1].name, 'Beta deploy renamed');
|
||||
expect(gateway.callsOf('get_pipeline').last.fields, {
|
||||
'pipeline_id': 2,
|
||||
'version': 1,
|
||||
});
|
||||
});
|
||||
|
||||
test(
|
||||
'server refusals are shown verbatim and a list failure is retryable',
|
||||
() async {
|
||||
final gateway = FakeGateway(
|
||||
(type, fields) => errorReply('server offline'),
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
await controller.load();
|
||||
expect(controller.listError, 'server offline');
|
||||
expect(controller.pipelinesLoaded, isFalse);
|
||||
expect(controller.runsError, 'server offline');
|
||||
},
|
||||
);
|
||||
|
||||
test('a runs failure is truthful without discarding pipelines', () async {
|
||||
final fixture = PipelineFixture();
|
||||
final gateway = FakeGateway(
|
||||
(type, fields) => switch (type) {
|
||||
'list_pipelines' => pipelineListReply(fixture.summaries),
|
||||
'list_runs' => errorReply('runs unavailable'),
|
||||
_ => errorReply('unexpected $type'),
|
||||
},
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
await controller.load();
|
||||
expect(controller.pipelinesLoaded, isTrue);
|
||||
expect(controller.pipelines, isNotEmpty);
|
||||
expect(controller.runsLoaded, isFalse);
|
||||
expect(controller.runsError, 'runs unavailable');
|
||||
});
|
||||
|
||||
test('run facets wait for a known run history', () async {
|
||||
final fixture = PipelineFixture();
|
||||
final runsReply = Completer<Map<String, dynamic>>();
|
||||
final gateway = FakeGateway(
|
||||
(type, fields) => switch (type) {
|
||||
'list_pipelines' => pipelineListReply(fixture.summaries),
|
||||
'list_runs' => runsReply.future,
|
||||
_ => errorReply('unexpected $type'),
|
||||
},
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
controller.setFilters(const PipelineFilters(presence: RunPresence.noRuns));
|
||||
final loading = controller.load();
|
||||
await settle();
|
||||
expect(controller.pipelinesLoaded, isTrue);
|
||||
expect(controller.runsLoaded, isFalse);
|
||||
expect(controller.visiblePipelines.length, 3);
|
||||
|
||||
runsReply.complete(runListReply(fixture.runs));
|
||||
await loading;
|
||||
expect(controller.runsLoaded, isTrue);
|
||||
expect(controller.visiblePipelines.map((pipeline) => pipeline.id), [3]);
|
||||
});
|
||||
|
||||
test('a stale list refresh cannot overwrite newer rows', () async {
|
||||
final first = Completer<Map<String, dynamic>>();
|
||||
final second = Completer<Map<String, dynamic>>();
|
||||
var listCalls = 0;
|
||||
final gateway = FakeGateway((type, fields) {
|
||||
if (type == 'list_runs') return runListReply(const []);
|
||||
if (type == 'list_pipelines') {
|
||||
listCalls++;
|
||||
return listCalls == 1 ? first.future : second.future;
|
||||
}
|
||||
return errorReply('unexpected $type');
|
||||
});
|
||||
final controller = controllerFor(gateway);
|
||||
final firstLoad = controller.load();
|
||||
final secondLoad = controller.load();
|
||||
second.complete(pipelineListReply([pipelineSummary(id: 2, name: 'Newer')]));
|
||||
await secondLoad;
|
||||
first.complete(pipelineListReply([pipelineSummary(id: 1, name: 'Older')]));
|
||||
await firstLoad;
|
||||
expect(controller.pipelines.single.name, 'Newer');
|
||||
expect(controller.listLoading, isFalse);
|
||||
});
|
||||
|
||||
test('pipeline errors keep a readable message', () {
|
||||
expect(
|
||||
pipelineErrorMessage(const PipelineRequestException('exact refusal')),
|
||||
'exact refusal',
|
||||
);
|
||||
expect(pipelineErrorMessage(Exception('broken')), 'broken');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/pipelines/screen.dart';
|
||||
|
||||
import 'fixtures.dart';
|
||||
import 'test_helpers.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('filter page narrows by name, schedule and last run status', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = PipelineFixture();
|
||||
await pumpWide(tester, gatewayFor(fixture));
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipeline-filter')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Filter pipelines'), findsOneWidget);
|
||||
await tester.enterText(find.byType(TextField), 'beta');
|
||||
await tester.tap(find.text('Done'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Filter (1)'), findsOneWidget);
|
||||
expect(find.text('Beta deploy'), findsOneWidget);
|
||||
expect(find.text('Alpha review'), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipeline-clear-filters')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Alpha review'), findsOneWidget);
|
||||
expect(find.text('Gamma legacy'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipeline-filter')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.ensureVisible(find.text('No schedules'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('No schedules'));
|
||||
await tester.pump();
|
||||
await tester.tap(find.text('Done'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Beta deploy'), findsOneWidget);
|
||||
expect(find.text('Alpha review'), findsNothing);
|
||||
expect(find.text('Gamma legacy'), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipeline-clear-filters')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('pipeline-filter')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.ensureVisible(find.text('failed'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('failed'));
|
||||
await tester.pump();
|
||||
await tester.tap(find.text('Done'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Beta deploy'), findsOneWidget);
|
||||
expect(find.text('Alpha review'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('sort menu changes visible order', (tester) async {
|
||||
final fixture = PipelineFixture();
|
||||
await pumpWide(tester, gatewayFor(fixture));
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipeline-sort')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Name Z\u2013A'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Sort: Name Z\u2013A'), findsOneWidget);
|
||||
final gamma = tester.getTopLeft(find.text('Gamma legacy')).dy;
|
||||
final beta = tester.getTopLeft(find.text('Beta deploy')).dy;
|
||||
final alpha = tester.getTopLeft(find.text('Alpha review')).dy;
|
||||
expect(gamma, lessThan(beta));
|
||||
expect(beta, lessThan(alpha));
|
||||
});
|
||||
|
||||
testWidgets('empty and error states are truthful and retryable', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = PipelineFixture();
|
||||
var fails = true;
|
||||
final gateway = FakeGateway((type, fields) {
|
||||
if (type == 'list_runs') return runListReply(fixture.runs);
|
||||
if (type == 'list_pipelines') {
|
||||
return fails
|
||||
? errorReply('server offline')
|
||||
: pipelineListReply(fixture.summaries);
|
||||
}
|
||||
return errorReply('unexpected $type');
|
||||
});
|
||||
await pumpWide(tester, gateway);
|
||||
|
||||
expect(find.text('server offline'), findsOneWidget);
|
||||
expect(find.text('Loading pipelines…'), findsNothing);
|
||||
fails = false;
|
||||
await tester.tap(find.text('Retry'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Alpha review'), findsOneWidget);
|
||||
|
||||
final emptyGateway = gatewayFor(fixture, summaries: const []);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: PipelinesScreen(gateway: emptyGateway)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text('No pipelines are defined on this server.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a detail refusal keeps the selection and offers retry', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = PipelineFixture();
|
||||
final gateway = gatewayFor(fixture, detailFails: true);
|
||||
await pumpWide(tester, gateway);
|
||||
await tester.tap(find.byKey(const Key('pipeline-row-2')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('pipeline 2 was not found'), findsOneWidget);
|
||||
expect(find.text('Retry'), findsOneWidget);
|
||||
expect(find.text('Select a pipeline.'), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
import 'dart:async';
|
||||
|
||||
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/pipelines/screen.dart';
|
||||
|
||||
import 'fixtures.dart';
|
||||
import 'test_helpers.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('list renders web wording, filters, opens detail and source', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = PipelineFixture();
|
||||
final gateway = gatewayFor(fixture);
|
||||
await pumpWide(tester, gateway);
|
||||
|
||||
expect(find.text('Pipelines'), findsOneWidget);
|
||||
expect(find.text('Alpha review'), findsOneWidget);
|
||||
expect(find.text('id 1 · v2 · 2 stages'), findsOneWidget);
|
||||
expect(find.text('updated 17 Oct 21:26'), findsOneWidget);
|
||||
expect(find.text('1 schedule'), findsOneWidget);
|
||||
expect(find.textContaining('run 42'), findsOneWidget);
|
||||
expect(find.text('no runs recorded'), findsOneWidget);
|
||||
expect(find.text('Select a pipeline.'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipeline-row-1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('pipeline-detail')), findsOneWidget);
|
||||
expect(find.text('hash-alpha'), findsOneWidget);
|
||||
expect(find.text('id 1 · v2 · 2 stages'), findsNWidgets(2));
|
||||
expect(gateway.callsOf('get_pipeline').single.fields, {
|
||||
'pipeline_id': 1,
|
||||
'version': 2,
|
||||
});
|
||||
|
||||
await tester.tap(find.text('Source'));
|
||||
await tester.pump();
|
||||
expect(
|
||||
selectableText('name: Alpha review\nstages:\n review:\n type: model'),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('version rows select an exact version and return to latest', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = PipelineFixture();
|
||||
final gateway = gatewayFor(fixture);
|
||||
await pumpWide(tester, gateway);
|
||||
await tester.tap(find.byKey(const Key('pipeline-row-1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('v1'), findsOneWidget);
|
||||
expect(find.text('v2'), findsNWidgets(2));
|
||||
await tester.tap(find.byKey(const Key('pipeline-version-1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.callsOf('get_pipeline').last.fields, {
|
||||
'pipeline_id': 1,
|
||||
'version': 1,
|
||||
});
|
||||
expect(find.text('Viewing v1 (latest v2).'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Source'));
|
||||
await tester.pump();
|
||||
expect(
|
||||
selectableText(
|
||||
'name: Alpha review\nstages:\n review:\n type: model\n'
|
||||
'# selected version 1',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Summary'));
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('pipeline-latest-version')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.callsOf('get_pipeline').last.fields, {
|
||||
'pipeline_id': 1,
|
||||
'version': 0,
|
||||
});
|
||||
expect(find.text('Viewing v1 (latest v2).'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('refresh keeps the selected row and its detail', (tester) async {
|
||||
final fixture = PipelineFixture();
|
||||
final gateway = gatewayFor(fixture);
|
||||
await pumpWide(tester, gateway);
|
||||
await tester.tap(find.byKey(const Key('pipeline-row-1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byTooltip('Refresh'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final row = tester.widget<ListTile>(
|
||||
find.byKey(const Key('pipeline-row-1')),
|
||||
);
|
||||
expect(row.selected, isTrue);
|
||||
expect(find.byKey(const Key('pipeline-detail')), findsOneWidget);
|
||||
expect(gateway.callsOf('get_pipeline').length, greaterThanOrEqualTo(2));
|
||||
});
|
||||
|
||||
testWidgets('initial loading is shown until both list reads settle', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = PipelineFixture();
|
||||
final list = Completer<JsonMap>();
|
||||
final runs = Completer<JsonMap>();
|
||||
final gateway = FakeGateway(
|
||||
(type, fields) => switch (type) {
|
||||
'list_pipelines' => list.future,
|
||||
'list_runs' => runs.future,
|
||||
_ => errorReply('unexpected $type'),
|
||||
},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: PipelinesScreen(gateway: gateway)),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text('Loading pipelines…'), findsOneWidget);
|
||||
|
||||
list.complete(pipelineListReply(fixture.summaries));
|
||||
runs.complete(runListReply(fixture.runs));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Alpha review'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('graph tab states it is pending without a hook', (tester) async {
|
||||
final fixture = PipelineFixture();
|
||||
await pumpWide(tester, gatewayFor(fixture));
|
||||
await tester.tap(find.byKey(const Key('pipeline-row-1')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Graph'));
|
||||
await tester.pump();
|
||||
expect(find.text('Graph rendering is pending (P2).'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/pipelines/screen.dart';
|
||||
|
||||
import 'fixtures.dart';
|
||||
|
||||
FakeGateway gatewayFor(
|
||||
PipelineFixture fixture, {
|
||||
bool listFails = false,
|
||||
bool runsFail = false,
|
||||
bool detailFails = false,
|
||||
List<Map<String, dynamic>>? summaries,
|
||||
}) => FakeGateway(
|
||||
(type, fields) => switch (type) {
|
||||
'list_pipelines' =>
|
||||
listFails
|
||||
? errorReply('server offline')
|
||||
: pipelineListReply(summaries ?? fixture.summaries),
|
||||
'list_runs' =>
|
||||
runsFail ? errorReply('runs down') : runListReply(fixture.runs),
|
||||
'get_pipeline' =>
|
||||
detailFails
|
||||
? errorReply('pipeline ${fields['pipeline_id']} was not found')
|
||||
: pipelineDetailReply(
|
||||
fixture.detailFor(
|
||||
fields['pipeline_id'] as int,
|
||||
fields['version'] as int,
|
||||
)!,
|
||||
),
|
||||
_ => errorReply('unexpected $type'),
|
||||
},
|
||||
);
|
||||
|
||||
Future<void> pumpWide(WidgetTester tester, FakeGateway gateway) async {
|
||||
tester.view.physicalSize = const Size(1100, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(MaterialApp(home: PipelinesScreen(gateway: gateway)));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Finder selectableText(String text) => find.byWidgetPredicate(
|
||||
(widget) => widget is SelectableText && widget.data == text,
|
||||
);
|
||||
Reference in New Issue
Block a user