merge(app): land Templates entry from Settings after retained-run recovery
This commit is contained in:
@@ -13,11 +13,13 @@ void main() {
|
||||
);
|
||||
expect(AppRoute.parse('/search'), AppRoute.search);
|
||||
expect(AppRoute.parse('/settings'), AppRoute.settings);
|
||||
expect(AppRoute.parse('/templates'), AppRoute.templates);
|
||||
});
|
||||
|
||||
test('normalises slashes and accepts a full URL, query and fragment', () {
|
||||
expect(AppRoute.parse('/runs/'), AppRoute.runs);
|
||||
expect(AppRoute.parse('/pipelines///'), AppRoute.pipelines);
|
||||
expect(AppRoute.parse('/templates/'), AppRoute.templates);
|
||||
expect(
|
||||
AppRoute.parse('http://127.0.0.1:8096/runs/7?action=decide#top'),
|
||||
AppRoute.run(7),
|
||||
@@ -43,6 +45,7 @@ void main() {
|
||||
'/runs/1/extra',
|
||||
'/pipelines/2',
|
||||
'/search/1',
|
||||
'/templates/release',
|
||||
'/chat/a/b',
|
||||
'/chat/%2F',
|
||||
'/chat/${'x' * 201}',
|
||||
@@ -62,11 +65,13 @@ void main() {
|
||||
AppRoute.chatSession('probe_open-1'),
|
||||
AppRoute.search,
|
||||
AppRoute.settings,
|
||||
AppRoute.templates,
|
||||
]) {
|
||||
expect(AppRoute.parse(route.path), route);
|
||||
}
|
||||
expect(AppRoute.run(3).path, '/runs/3');
|
||||
expect(AppRoute.chatSession('probe_open-1').path, '/chat/probe_open-1');
|
||||
expect(AppRoute.chatSession('bad id').path, '/chat');
|
||||
expect(AppRoute.templates.path, '/templates');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,4 +28,25 @@ void main() {
|
||||
|
||||
expect(await router.popRoute(), isFalse);
|
||||
});
|
||||
|
||||
test('Templates opens above Settings and Back restores the route', () async {
|
||||
final router = delegate(AppRoute.settings);
|
||||
addTearDown(router.dispose);
|
||||
|
||||
router.openTemplates();
|
||||
expect(router.route, AppRoute.templates);
|
||||
expect(router.templatesOpen, isTrue);
|
||||
|
||||
expect(await router.popRoute(), isTrue);
|
||||
expect(router.route, AppRoute.settings);
|
||||
expect(router.templatesOpen, isFalse);
|
||||
});
|
||||
|
||||
test('a /templates boot link still closes back to Settings', () async {
|
||||
final router = delegate(AppRoute.templates);
|
||||
addTearDown(router.dispose);
|
||||
|
||||
router.closeTemplates();
|
||||
expect(router.route, AppRoute.settings);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,344 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/pipelines_app.dart';
|
||||
import 'package:pipelines_app/application/templates_destination.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_keys.dart';
|
||||
import 'package:pipelines_app/features/templates/screen.dart';
|
||||
import 'package:pipelines_app/features/templates/ui/template_create_wording.dart';
|
||||
import 'package:pipelines_app/features/templates/ui/template_detail.dart'
|
||||
show templateDetailBackKey;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import '../features/pipelines/fixtures.dart';
|
||||
import '../features/templates/ui/template_gallery_test_support.dart'
|
||||
show GalleryGateway, galleryTemplates, pumpGallery, templatesReply;
|
||||
import 'pipelines_app_test.dart' show webServer;
|
||||
import 'pipelines_replies.dart';
|
||||
|
||||
List<Map<String, dynamic>> requestsOf(FakeChannel channel, String type) =>
|
||||
channel.outgoing
|
||||
.map((frame) => jsonDecode(frame as String) as Map<String, dynamic>)
|
||||
.where((frame) => frame['type'] == type)
|
||||
.toList();
|
||||
|
||||
Future<List<Map<String, dynamic>>> waitForCount(
|
||||
WidgetTester tester,
|
||||
FakeChannel channel,
|
||||
String type,
|
||||
int count,
|
||||
) async {
|
||||
for (
|
||||
var attempt = 0;
|
||||
attempt < 100 && requestsOf(channel, type).length < count;
|
||||
attempt++
|
||||
) {
|
||||
await tester.pump(const Duration(milliseconds: 10));
|
||||
}
|
||||
final requests = requestsOf(channel, type);
|
||||
expect(
|
||||
requests.length,
|
||||
greaterThanOrEqualTo(count),
|
||||
reason: 'Timed out waiting for $type #$count',
|
||||
);
|
||||
return requests;
|
||||
}
|
||||
|
||||
Future<void> reply(
|
||||
WidgetTester tester,
|
||||
FakeChannel channel,
|
||||
String type,
|
||||
int count,
|
||||
Map<String, dynamic> body,
|
||||
) async {
|
||||
final requests = await waitForCount(tester, channel, type, count);
|
||||
channel.incoming.add(jsonEncode({'id': requests[count - 1]['id'], ...body}));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> pumpApp(
|
||||
WidgetTester tester, {
|
||||
required FakeChannel channel,
|
||||
required PipelinesClient client,
|
||||
required PlatformRouteInformationProvider provider,
|
||||
required bool cupertino,
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(1100, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
if (cupertino) {
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
|
||||
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
|
||||
}
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
await tester.pumpWidget(
|
||||
PipelinesApp(
|
||||
server: webServer(),
|
||||
client: client,
|
||||
cupertino: cupertino,
|
||||
routeInformationProvider: provider,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> openSettings(
|
||||
WidgetTester tester,
|
||||
FakeChannel channel,
|
||||
PlatformRouteInformationProvider provider,
|
||||
) async {
|
||||
await tester.tap(find.text('Settings').last);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/settings');
|
||||
// Settings pings the shared socket; answer it so later reads are not queued.
|
||||
await reply(tester, channel, 'ping', 1, {
|
||||
'type': 'pong',
|
||||
'build': {'version': 'probe'},
|
||||
'time': 'fixture',
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> openTemplates(
|
||||
WidgetTester tester,
|
||||
FakeChannel channel,
|
||||
PlatformRouteInformationProvider provider, {
|
||||
int listRead = 1,
|
||||
}) async {
|
||||
await tester.ensureVisible(find.byKey(SettingsKeys.templates));
|
||||
await tester.tap(find.byKey(SettingsKeys.templates));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 600));
|
||||
expect(provider.value.uri.path, '/templates');
|
||||
await reply(tester, channel, 'list_templates', listRead, {
|
||||
'type': 'templates',
|
||||
'templates': [
|
||||
{
|
||||
'key': 'release',
|
||||
'name': 'Release workflow',
|
||||
'description': 'Ship a version',
|
||||
'source': 'name: "release"\n',
|
||||
'scheduled': true,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('non-embedded TemplatesScreen keeps its own native bar', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = GalleryGateway(
|
||||
(type, fields) async => templatesReply(galleryTemplates),
|
||||
);
|
||||
await pumpGallery(tester, gateway);
|
||||
|
||||
expect(find.byType(AppBar), findsOneWidget);
|
||||
await tester.tap(find.byKey(templateRowKey('release')));
|
||||
await tester.pump();
|
||||
expect(find.text('Definition source'), findsOneWidget);
|
||||
expect(find.byKey(templatesBackKey), findsOneWidget);
|
||||
expect(gateway.callsOf('list_templates'), hasLength(1));
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'Settings opens the embedded Templates page and Back restores it '
|
||||
'($cupertino)',
|
||||
(tester) async {
|
||||
final fixture = PipelineFixture();
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
var sockets = 0;
|
||||
final client = PipelinesClient(
|
||||
channelFactory: (_) {
|
||||
sockets++;
|
||||
return channel;
|
||||
},
|
||||
);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(
|
||||
uri: Uri.parse('/pipelines'),
|
||||
),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
|
||||
await pumpApp(
|
||||
tester,
|
||||
channel: channel,
|
||||
client: client,
|
||||
provider: provider,
|
||||
cupertino: cupertino,
|
||||
);
|
||||
await replyPipelines(tester, channel, fixture);
|
||||
|
||||
await openSettings(tester, channel, provider);
|
||||
// An edit that only Settings owns must survive the Templates detour.
|
||||
await tester.enterText(find.byType(EditableText).first, 'edited url');
|
||||
await tester.pump();
|
||||
expect(find.text('edited url'), findsOneWidget);
|
||||
|
||||
await openTemplates(tester, channel, provider);
|
||||
final screen = tester.widget<TemplatesScreen>(
|
||||
find.byType(TemplatesScreen),
|
||||
);
|
||||
expect(screen.embedded, isTrue);
|
||||
expect(find.text('Release workflow'), findsOneWidget);
|
||||
// One visible navigation bar: the Templates page owns it, the shell is
|
||||
// preserved underneath.
|
||||
expect(
|
||||
find.byType(cupertino ? CupertinoNavigationBar : AppBar),
|
||||
findsOneWidget,
|
||||
);
|
||||
if (cupertino) {
|
||||
expect(find.byType(Material), findsNothing);
|
||||
}
|
||||
expect(sockets, 1);
|
||||
expect(requestsOf(channel, 'list_templates'), hasLength(1));
|
||||
|
||||
await tester.tap(find.byKey(templateRowKey('release')));
|
||||
await tester.pump();
|
||||
expect(find.text('Definition source'), findsOneWidget);
|
||||
|
||||
// Detail Back returns to the gallery, then the page Back restores the
|
||||
// same Settings state.
|
||||
await tester.tap(find.byKey(templateDetailBackKey));
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(templatesPageBackKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(provider.value.uri.path, '/settings');
|
||||
expect(find.byType(TemplatesScreen), findsNothing);
|
||||
expect(find.text('edited url'), findsOneWidget);
|
||||
expect(find.text('Server URL'), findsOneWidget);
|
||||
expect(sockets, 1);
|
||||
expect(requestsOf(channel, 'ping'), hasLength(1));
|
||||
|
||||
// Browser Back from /templates follows the same close path.
|
||||
await openTemplates(tester, channel, provider, listRead: 2);
|
||||
expect(find.byType(TemplatesScreen), findsOneWidget);
|
||||
await provider.didPushRouteInformation(
|
||||
RouteInformation(uri: Uri.parse('/settings')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/settings');
|
||||
expect(find.byType(TemplatesScreen), findsNothing);
|
||||
expect(find.text('edited url'), findsOneWidget);
|
||||
expect(requestsOf(channel, 'list_templates'), hasLength(2));
|
||||
expect(sockets, 1);
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pump();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('an accepted create re-reads Pipelines exactly once', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = PipelineFixture();
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
var sockets = 0;
|
||||
final client = PipelinesClient(
|
||||
channelFactory: (_) {
|
||||
sockets++;
|
||||
return channel;
|
||||
},
|
||||
);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
|
||||
await pumpApp(
|
||||
tester,
|
||||
channel: channel,
|
||||
client: client,
|
||||
provider: provider,
|
||||
cupertino: false,
|
||||
);
|
||||
await replyPipelines(tester, channel, fixture);
|
||||
expect(
|
||||
find.byKey(const Key('pipeline-row-41'), skipOffstage: false),
|
||||
findsNothing,
|
||||
);
|
||||
|
||||
await openSettings(tester, channel, provider);
|
||||
await openTemplates(tester, channel, provider);
|
||||
await tester.tap(find.byKey(templateRowKey('release')));
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(templateCreateActionKey));
|
||||
await tester.pump();
|
||||
await tester.enterText(find.byKey(templateCreateNameKey), 'Probe release');
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(templateCreateConfirmKey));
|
||||
await tester.pump();
|
||||
|
||||
await reply(tester, channel, 'validate', 1, {
|
||||
'type': 'graph',
|
||||
'graph': {'stages': <dynamic>[]},
|
||||
});
|
||||
await reply(tester, channel, 'submit', 1, {
|
||||
'type': 'pipeline',
|
||||
'detail': {'id': 41, 'name': 'Probe release'},
|
||||
});
|
||||
expect(
|
||||
find.text('Created "Probe release". It is in the Pipelines list.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// The detail itself never adds a row: the hidden list is still the old one
|
||||
// until the fresh server reply arrives.
|
||||
final refreshes = await waitForCount(tester, channel, 'list_pipelines', 2);
|
||||
expect(
|
||||
find.byKey(const Key('pipeline-row-41'), skipOffstage: false),
|
||||
findsNothing,
|
||||
);
|
||||
channel.incoming.add(
|
||||
jsonEncode({
|
||||
'id': refreshes[1]['id'],
|
||||
'type': 'pipelines',
|
||||
'pipelines': [
|
||||
...fixture.summaries,
|
||||
pipelineSummary(id: 41, name: 'Probe release'),
|
||||
],
|
||||
}),
|
||||
);
|
||||
await tester.pump();
|
||||
await reply(tester, channel, 'list_runs', 2, {
|
||||
'type': 'runs',
|
||||
'runs': fixture.runs,
|
||||
});
|
||||
expect(
|
||||
find.byKey(const Key('pipeline-row-41'), skipOffstage: false),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(templateCreateCancelKey));
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(templateDetailBackKey));
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(templatesPageBackKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Pipelines').last);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(provider.value.uri.path, '/pipelines');
|
||||
expect(find.text('Probe release'), findsOneWidget);
|
||||
// Only the accepted detail's invalidation re-read the list; showing it
|
||||
// again adds no request.
|
||||
expect(requestsOf(channel, 'list_pipelines'), hasLength(2));
|
||||
expect(requestsOf(channel, 'list_runs'), hasLength(2));
|
||||
expect(requestsOf(channel, 'validate'), hasLength(1));
|
||||
expect(requestsOf(channel, 'submit'), hasLength(1));
|
||||
expect(sockets, 1);
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pump();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user