Merge: archive and unarchive pipelines
# Conflicts: # internal/cli/commands.go # internal/pipeline/store.go
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -9,14 +9,14 @@ void main() {
|
||||
testWidgets(
|
||||
'native scope remains usable at $width, Cupertino=$cupertino',
|
||||
(tester) async {
|
||||
var scheduled = false;
|
||||
var scope = PipelineScope.all;
|
||||
final control = StatefulBuilder(
|
||||
builder: (context, setState) => Center(
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: PipelineScopeControl(
|
||||
scheduled: scheduled,
|
||||
onSelected: (value) => setState(() => scheduled = value),
|
||||
scope: scope,
|
||||
onSelected: (value) => setState(() => scope = value),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -35,7 +35,7 @@ void main() {
|
||||
await tester.tap(find.text('Scheduled'));
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
expect(scheduled, isTrue);
|
||||
expect(scope, PipelineScope.scheduled);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
@@ -50,7 +50,10 @@ void main() {
|
||||
width: 500,
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: PipelineScopeControl(scheduled: false, onSelected: (_) {}),
|
||||
child: PipelineScopeControl(
|
||||
scope: PipelineScope.all,
|
||||
onSelected: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -31,7 +31,7 @@ void main() {
|
||||
'list_pipelines',
|
||||
'list_runs',
|
||||
]);
|
||||
expect(gateway.calls[0].fields, isEmpty);
|
||||
expect(gateway.calls[0].fields, {'include_archived': true});
|
||||
expect(gateway.calls[1].fields, isEmpty);
|
||||
expect(controller.pipelines.map((pipeline) => pipeline.id), [1, 2, 3]);
|
||||
expect(controller.pipelinesLoaded, isTrue);
|
||||
|
||||
@@ -127,24 +127,12 @@ void main() {
|
||||
expect(find.text('Alpha review'), findsOneWidget);
|
||||
expect(find.text('Gamma legacy'), findsOneWidget);
|
||||
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('pipeline-scope')),
|
||||
matching: find.text('Scheduled'),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await pickScope(tester, 'Scheduled');
|
||||
// Beta has no schedule in the fixture; Alpha has one.
|
||||
expect(find.text('Alpha review'), findsOneWidget);
|
||||
expect(find.text('Beta deploy'), findsNothing);
|
||||
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('pipeline-scope')),
|
||||
matching: find.text('All'),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await pickScope(tester, 'All');
|
||||
expect(find.text('Beta deploy'), findsOneWidget);
|
||||
});
|
||||
|
||||
|
||||
@@ -115,13 +115,16 @@ void main() {
|
||||
|
||||
expect(find.bySemanticsLabel('View runs of Alpha review'), findsOneWidget);
|
||||
// Run and Runs share the detail pane's actions pill at the top right,
|
||||
// Runs before the primary Run; nothing floats over the content.
|
||||
// Runs before the primary Run and the pipeline's overflow menu last;
|
||||
// nothing floats over the content.
|
||||
final runs = tester.getRect(find.byKey(const Key('pipeline-view-runs')));
|
||||
final run = tester.getRect(find.byKey(runPipelineActionKey));
|
||||
final menu = tester.getRect(find.byKey(const Key('pipeline-actions-menu')));
|
||||
final screen = tester.view.physicalSize / tester.view.devicePixelRatio;
|
||||
expect(runs.right, lessThanOrEqualTo(run.left));
|
||||
expect(run.right, lessThanOrEqualTo(menu.left));
|
||||
expect((runs.center.dy - run.center.dy).abs(), lessThan(1));
|
||||
expect(run.right, greaterThan(screen.width - 40));
|
||||
expect(menu.right, greaterThan(screen.width - 40));
|
||||
expect(run.bottom, lessThan(screen.height / 4));
|
||||
await tester.tap(find.byKey(const Key('pipeline-view-runs')));
|
||||
expect(opened, [1]);
|
||||
|
||||
@@ -44,3 +44,20 @@ Future<void> pumpWide(WidgetTester tester, FakeGateway gateway) async {
|
||||
Finder selectableText(String text) => find.byWidgetPredicate(
|
||||
(widget) => widget is SelectableText && widget.data == text,
|
||||
);
|
||||
|
||||
/// Picks a scope from the segments, or from the menu a pane too narrow for
|
||||
/// the segments shows instead.
|
||||
Future<void> pickScope(WidgetTester tester, String label) async {
|
||||
final segment = find.descendant(
|
||||
of: find.byKey(const Key('pipeline-scope')),
|
||||
matching: find.text(label),
|
||||
);
|
||||
if (segment.evaluate().isEmpty) {
|
||||
await tester.tap(find.byKey(const Key('pipeline-scope')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(label).last);
|
||||
} else {
|
||||
await tester.tap(segment);
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user