d1b05217c9
Keep the pipeline feature on its existing Material path because the app runs under MaterialApp and never selects Cupertino hosts. Preserve public cupertino parameters and required Cupertino icon values for later cleanup and shared controls.
157 lines
5.6 KiB
Dart
157 lines
5.6 KiB
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) 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(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);
|
|
});
|
|
}
|