a1c4c1c402
Settings leaves the tab bar (Pipelines, Runs, Chat, Search) and opens as a page from a gear in the Pipelines bar, keeping /settings, its keys and a Back to Pipelines (also the system Back). Every floating tab bar shows icons only, named for assistive technology. On wide windows the shell's tab bar stays at the bottom right; a split detail learns its height plus a 12px gap, so its tabs or the chat composer float above it, and pages the detail opens (the stage page) stay in its pane through its own navigator.
375 lines
13 KiB
Dart
375 lines
13 KiB
Dart
import 'dart:convert';
|
|
|
|
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';
|
|
import 'package:pipelines_app/ui/adaptive/segmented_bar.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.byKey(const Key('pipelines-open-settings')));
|
|
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',
|
|
});
|
|
// It then loads the server's ntfy notification settings.
|
|
await reply(tester, channel, 'notification_settings', 1, {
|
|
'type': 'notification_settings',
|
|
'notification_settings': {
|
|
'run_finished': true,
|
|
'chat_needs_you': true,
|
|
'chat_reply_finished': false,
|
|
},
|
|
});
|
|
}
|
|
|
|
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,
|
|
},
|
|
],
|
|
});
|
|
await reply(tester, channel, 'validate', listRead, {
|
|
'type': 'graph',
|
|
'graph': {'stages': <dynamic>[]},
|
|
});
|
|
}
|
|
|
|
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(SegmentedBar), 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(SegmentedBar), findsOneWidget);
|
|
if (cupertino) {
|
|
expect(find.byType(Material), findsNothing);
|
|
}
|
|
expect(sockets, 1);
|
|
expect(requestsOf(channel, 'list_templates'), hasLength(1));
|
|
|
|
// Refresh sits in the bar's actions pill, not in the body.
|
|
Finder inBar(Key key) => find.descendant(
|
|
of: find.byType(SegmentedBar),
|
|
matching: find.byKey(key),
|
|
);
|
|
expect(inBar(templatesRefreshKey), findsOneWidget);
|
|
expect(find.byKey(templatesRefreshKey), findsOneWidget);
|
|
expect(inBar(templatesPageBackKey), findsOneWidget);
|
|
|
|
await tester.tap(find.byKey(templateRowKey('release')));
|
|
await tester.pump();
|
|
await tester.pump();
|
|
expect(find.text('Definition source'), findsOneWidget);
|
|
// One Back at a time, in the bar's round leading piece: the open
|
|
// template's Back replaces the page's.
|
|
expect(inBar(templateDetailBackKey), findsOneWidget);
|
|
expect(find.byKey(templateDetailBackKey), findsOneWidget);
|
|
expect(find.byKey(templatesPageBackKey), findsNothing);
|
|
|
|
// Detail Back returns to the gallery, then the page Back restores the
|
|
// same Settings state.
|
|
await tester.tap(find.byKey(templateDetailBackKey));
|
|
await tester.pump();
|
|
// The gallery hands the bar back to the page's Back on the next frame.
|
|
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', 2, {
|
|
'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();
|
|
// The gallery hands the bar back to the page's Back on the next frame.
|
|
await tester.pump();
|
|
await tester.tap(find.byKey(templatesPageBackKey));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.pipelines')));
|
|
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));
|
|
// One validation derives the gallery count; the other belongs to Create.
|
|
expect(requestsOf(channel, 'validate'), hasLength(2));
|
|
expect(requestsOf(channel, 'submit'), hasLength(1));
|
|
expect(sockets, 1);
|
|
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
});
|
|
}
|