5a9284ccf7
The pipeline's bar gets a Pipeline actions menu with Archive (confirm dialog: history is kept) or Unarchive; an archived detail says so and offers no Run. The list hides archived pipelines and the scope control gains an Archived view. Server refusals (enabled schedule, newer version) are shown verbatim. The capture fixture answers archive requests.
185 lines
6.5 KiB
Dart
185 lines
6.5 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/cupertino.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/ui/run_pipeline_action.dart';
|
|
|
|
import 'fixtures.dart';
|
|
import 'test_helpers.dart';
|
|
|
|
/// A fixture server that remembers archive state, like the real one: the list
|
|
/// carries `archived_at` and archive replies return the updated detail.
|
|
FakeGateway archiveGateway(PipelineFixture fixture, {String? refusal}) {
|
|
final archived = <int, String>{};
|
|
Map<String, dynamic> mark(Map<String, dynamic> row) => {
|
|
...row,
|
|
if (archived[row['id']] != null) 'archived_at': archived[row['id']],
|
|
};
|
|
return FakeGateway((type, fields) {
|
|
switch (type) {
|
|
case 'list_pipelines':
|
|
return pipelineListReply([
|
|
for (final row in fixture.summaries) mark(row),
|
|
]);
|
|
case 'list_runs':
|
|
return runListReply(fixture.runs);
|
|
case 'get_pipeline':
|
|
return pipelineDetailReply(
|
|
mark(
|
|
fixture.detailFor(
|
|
fields['pipeline_id'] as int,
|
|
fields['version'] as int,
|
|
)!,
|
|
),
|
|
);
|
|
case 'archive_pipeline' || 'unarchive_pipeline':
|
|
if (refusal != null) return errorReply(refusal);
|
|
final id = fields['pipeline_id'] as int;
|
|
if (type == 'archive_pipeline') {
|
|
archived[id] = '2026-11-04T12:00:00Z';
|
|
} else {
|
|
archived.remove(id);
|
|
}
|
|
return {
|
|
'type': type == 'archive_pipeline'
|
|
? 'pipeline_archived'
|
|
: 'pipeline_unarchived',
|
|
'detail': mark(fixture.detailFor(id, 0)!),
|
|
};
|
|
}
|
|
return errorReply('unexpected $type');
|
|
});
|
|
}
|
|
|
|
Future<void> pump(
|
|
WidgetTester tester,
|
|
FakeGateway gateway, {
|
|
bool cupertino = false,
|
|
}) async {
|
|
tester.view.physicalSize = const Size(1100, 900);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
final screen = PipelinesScreen(gateway: gateway);
|
|
await tester.pumpWidget(
|
|
cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
Finder rowNamed(String name) => find.descendant(
|
|
of: find.byKey(const Key('pipeline-list')),
|
|
matching: find.text(name),
|
|
);
|
|
|
|
Future<void> openMenuItem(WidgetTester tester, String key) async {
|
|
await tester.tap(find.byKey(const Key('pipeline-actions-menu')));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(Key(key)));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('Archive from the pipeline menu hides it after confirmation', (
|
|
tester,
|
|
) async {
|
|
final gateway = archiveGateway(PipelineFixture());
|
|
await pump(tester, gateway);
|
|
expect(gateway.callsOf('list_pipelines').first.fields, {
|
|
'include_archived': true,
|
|
});
|
|
await tester.tap(rowNamed('Beta deploy'));
|
|
await tester.pumpAndSettle();
|
|
|
|
await openMenuItem(tester, 'pipeline-archive');
|
|
expect(find.text('Archive Beta deploy?'), findsOneWidget);
|
|
expect(
|
|
find.textContaining('runs, artifacts and search history are kept'),
|
|
findsOneWidget,
|
|
);
|
|
await tester.tap(find.text('Cancel'));
|
|
await tester.pumpAndSettle();
|
|
expect(gateway.callsOf('archive_pipeline'), isEmpty);
|
|
|
|
await openMenuItem(tester, 'pipeline-archive');
|
|
await tester.tap(find.byKey(const Key('pipeline-archive-confirm')));
|
|
await tester.pumpAndSettle();
|
|
expect(gateway.callsOf('archive_pipeline').single.fields, {
|
|
'pipeline_id': 2,
|
|
'expected_version': 1,
|
|
});
|
|
expect(rowNamed('Beta deploy'), findsNothing);
|
|
expect(rowNamed('Alpha review'), findsOneWidget);
|
|
// The open detail stays, says it is archived and offers no Run.
|
|
expect(find.byKey(const Key('pipeline-archived-notice')), findsOneWidget);
|
|
expect(find.byType(RunPipelineAction), findsNothing);
|
|
});
|
|
|
|
testWidgets('the Archived scope lists archived pipelines and unarchives', (
|
|
tester,
|
|
) async {
|
|
final gateway = archiveGateway(PipelineFixture());
|
|
await pump(tester, gateway);
|
|
await tester.tap(rowNamed('Gamma legacy'));
|
|
await tester.pumpAndSettle();
|
|
await openMenuItem(tester, 'pipeline-archive');
|
|
await tester.tap(find.byKey(const Key('pipeline-archive-confirm')));
|
|
await tester.pumpAndSettle();
|
|
|
|
await pickScope(tester, 'Archived');
|
|
expect(rowNamed('Gamma legacy'), findsOneWidget);
|
|
expect(rowNamed('Alpha review'), findsNothing);
|
|
expect(rowNamed('Beta deploy'), findsNothing);
|
|
|
|
await openMenuItem(tester, 'pipeline-unarchive');
|
|
expect(gateway.callsOf('unarchive_pipeline').single.fields, {
|
|
'pipeline_id': 3,
|
|
'expected_version': 1,
|
|
});
|
|
expect(find.text('No archived pipelines.'), findsOneWidget);
|
|
expect(find.byKey(const Key('pipeline-archived-notice')), findsNothing);
|
|
|
|
await pickScope(tester, 'All');
|
|
expect(rowNamed('Gamma legacy'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('a refused archive shows the server reason', (tester) async {
|
|
const reason =
|
|
'pipeline "Alpha review" has enabled schedule(s) "nightly" (#4); '
|
|
'pause or repoint them before archiving';
|
|
final gateway = archiveGateway(PipelineFixture(), refusal: reason);
|
|
await pump(tester, gateway);
|
|
await tester.tap(rowNamed('Alpha review'));
|
|
await tester.pumpAndSettle();
|
|
await openMenuItem(tester, 'pipeline-archive');
|
|
await tester.tap(find.byKey(const Key('pipeline-archive-confirm')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Could not archive'), findsOneWidget);
|
|
expect(find.text(reason), findsOneWidget);
|
|
await tester.tap(find.text('OK'));
|
|
await tester.pumpAndSettle();
|
|
expect(rowNamed('Alpha review'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('Cupertino archives through the action sheet and alert', (
|
|
tester,
|
|
) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
try {
|
|
final gateway = archiveGateway(PipelineFixture());
|
|
await pump(tester, gateway, cupertino: true);
|
|
await tester.tap(rowNamed('Beta deploy'));
|
|
await tester.pumpAndSettle();
|
|
await openMenuItem(tester, 'pipeline-archive');
|
|
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
|
|
await tester.tap(find.byKey(const Key('pipeline-archive-confirm')));
|
|
await tester.pumpAndSettle();
|
|
expect(gateway.callsOf('archive_pipeline'), hasLength(1));
|
|
expect(rowNamed('Beta deploy'), findsNothing);
|
|
} finally {
|
|
debugDefaultTargetPlatformOverride = null;
|
|
}
|
|
});
|
|
}
|