c264f865ff
A saved server still named by the app ('My server', 'This server',
'Original legacy server' or its address host/IP) takes the hostname the
machine reports in get_status the first time the app connects; typed
names are kept. New servers (legacy migration, Settings with a blank
name, onboarding) start with the address host. A browser on its page
origin with no saved profile shows the reported hostname too. No server
change: get_status already reports the hostname.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
169 lines
5.9 KiB
Dart
169 lines
5.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/core/servers/server_catalog.dart';
|
|
import 'package:pipelines_app/core/servers/server_catalog_store.dart';
|
|
import 'package:pipelines_app/core/servers/server_context.dart';
|
|
import 'package:pipelines_app/features/settings/saved_servers_section.dart';
|
|
import 'package:pipelines_app/features/settings/server_connections.dart';
|
|
|
|
import 'saved_servers_test.dart' show revealSave;
|
|
|
|
SavedServer machine(String id, String name, String url) =>
|
|
SavedServer.validated(id: id, name: name, endpoints: [url]);
|
|
|
|
Future<ServerConnections> connectionsFor(MemoryServerCatalogStore store) async {
|
|
final connections = ServerConnections(store: store, onSelected: (_) async {});
|
|
await connections.load();
|
|
return connections;
|
|
}
|
|
|
|
void main() {
|
|
test('a placeholder name becomes the hostname and is saved', () async {
|
|
final store = MemoryServerCatalogStore(
|
|
catalog: ServerCatalog(
|
|
servers: [
|
|
machine('legacy-server', 'My server', 'ws://192.168.1.20:8083/ws'),
|
|
machine('b', '100.64.0.2', 'ws://100.64.0.2:8083/ws'),
|
|
machine('c', 'Laptop', 'ws://laptop.test/ws'),
|
|
],
|
|
selectedId: 'b',
|
|
),
|
|
);
|
|
final connections = await connectionsFor(store);
|
|
addTearDown(connections.dispose);
|
|
expect(await connections.learnHostname('legacy-server', 'tank'), isTrue);
|
|
expect(await connections.learnHostname('b', 'linux-box'), isTrue);
|
|
expect(await connections.learnHostname('c', 'mac-mini'), isFalse);
|
|
expect(await connections.learnHostname('b', ''), isFalse);
|
|
final names = store.catalog!.servers.map((s) => s.name).toList();
|
|
expect(names, ['tank', 'linux-box', 'Laptop']);
|
|
expect(store.catalog!.selectedId, 'b');
|
|
expect(connections.catalog.toJson(), store.catalog!.toJson());
|
|
// Once named, a later hostname does not rename it again.
|
|
expect(await connections.learnHostname('legacy-server', 'other'), isFalse);
|
|
});
|
|
|
|
test('a rename learned during another change is applied after it', () async {
|
|
final store = MemoryServerCatalogStore(
|
|
catalog: ServerCatalog(
|
|
servers: [machine('a', 'This server', 'ws://a.test/ws')],
|
|
selectedId: 'a',
|
|
),
|
|
);
|
|
final connections = await connectionsFor(store);
|
|
addTearDown(connections.dispose);
|
|
final persisting = connections.persist();
|
|
expect(connections.busy, isTrue);
|
|
expect(await connections.learnHostname('a', 'tank'), isFalse);
|
|
await persisting;
|
|
await pumpEventQueue();
|
|
expect(store.catalog!.active!.name, 'tank');
|
|
});
|
|
|
|
test('a failed rename save keeps the old name', () async {
|
|
final store = MemoryServerCatalogStore(
|
|
catalog: ServerCatalog(
|
|
servers: [machine('a', 'a.test', 'ws://a.test/ws')],
|
|
selectedId: 'a',
|
|
),
|
|
);
|
|
final connections = await connectionsFor(store);
|
|
addTearDown(connections.dispose);
|
|
store.failSaves = true;
|
|
expect(await connections.learnHostname('a', 'tank'), isFalse);
|
|
expect(connections.catalog.active!.name, 'a.test');
|
|
});
|
|
|
|
testWidgets('the unsaved page origin is named by its hostname', (
|
|
tester,
|
|
) async {
|
|
final connections = await connectionsFor(MemoryServerCatalogStore());
|
|
addTearDown(connections.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: ServerContext(
|
|
connections: connections,
|
|
serverId: null,
|
|
child: Builder(
|
|
builder: (context) =>
|
|
Text(ServerContext.metadata(context, '7 stages')),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
expect(find.text('7 stages'), findsOneWidget);
|
|
expect(await connections.learnHostname(null, 'tank'), isTrue);
|
|
await tester.pump();
|
|
expect(find.text('tank · 7 stages'), findsOneWidget);
|
|
expect(connections.catalog.servers, isEmpty);
|
|
});
|
|
|
|
testWidgets('a saved server row and its metadata follow the rename', (
|
|
tester,
|
|
) async {
|
|
final connections = await connectionsFor(
|
|
MemoryServerCatalogStore(
|
|
catalog: ServerCatalog(
|
|
servers: [machine('a', 'My server', 'ws://a.test/ws')],
|
|
selectedId: 'a',
|
|
),
|
|
),
|
|
);
|
|
addTearDown(connections.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: ServerContext(
|
|
connections: connections,
|
|
serverId: 'a',
|
|
child: Builder(
|
|
builder: (context) => ListView(
|
|
children: [
|
|
Text(ServerContext.metadata(context, '7 stages')),
|
|
SavedServersSection(connections: connections),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
expect(find.text('My server · 7 stages'), findsOneWidget);
|
|
await tester.runAsync(() => connections.learnHostname('a', 'tank'));
|
|
await tester.pump();
|
|
expect(find.text('tank · 7 stages'), findsOneWidget);
|
|
expect(find.text('tank'), findsWidgets);
|
|
expect(find.text('My server'), findsNothing);
|
|
});
|
|
|
|
testWidgets('Add server with no name uses the address host for now', (
|
|
tester,
|
|
) async {
|
|
final connections = await connectionsFor(MemoryServerCatalogStore());
|
|
addTearDown(connections.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: SingleChildScrollView(
|
|
child: SavedServersSection(connections: connections),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.tap(find.text('Add server'));
|
|
await tester.pumpAndSettle();
|
|
await tester.enterText(
|
|
find.byKey(const Key('server-profile-addresses')),
|
|
'ws://192.168.1.20:8083/ws',
|
|
);
|
|
await revealSave(tester);
|
|
await tester.tap(find.text('Save server'));
|
|
await tester.pumpAndSettle();
|
|
expect(connections.catalog.active?.name, '192.168.1.20');
|
|
await tester.runAsync(
|
|
() => connections.learnHostname(connections.catalog.active!.id, 'tank'),
|
|
);
|
|
expect(connections.catalog.active?.name, 'tank');
|
|
});
|
|
}
|