90 lines
3.2 KiB
Dart
90 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:pipelines_app/application/pipelines_root.dart';
|
|
import 'package:pipelines_app/application/pipelines_app.dart';
|
|
import 'package:pipelines_app/application/server_endpoint.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_scope.dart';
|
|
import 'package:pipelines_app/core/session/server_session.dart';
|
|
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
|
|
|
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
|
|
|
void main() {
|
|
testWidgets(
|
|
'native root tries same-server backup without changing logical identity',
|
|
(tester) async {
|
|
SharedPreferences.setMockInitialValues({
|
|
'pipelines.session.v2.home.cookie': 'pipelines_session=home',
|
|
});
|
|
await ServerSession.load();
|
|
final home = SavedServer.validated(
|
|
id: 'home',
|
|
name: 'Home',
|
|
endpoints: ['wss://tail.test/connect', 'ws://192.168.1.2:8083/connect'],
|
|
);
|
|
final other = SavedServer.validated(
|
|
id: 'other',
|
|
name: 'Other',
|
|
endpoints: ['wss://other.test/connect'],
|
|
);
|
|
final store = MemoryServerCatalogStore(
|
|
catalog: ServerCatalog(servers: [home, other], selectedId: home.id),
|
|
);
|
|
final attempts = <Uri>[];
|
|
final client = PipelinesClient(
|
|
backoffBase: const Duration(milliseconds: 10),
|
|
channelFactory: (uri) {
|
|
attempts.add(uri);
|
|
final channel = FakeChannel();
|
|
if (uri.host == 'tail.test') {
|
|
channel.readyCompleter.completeError(
|
|
StateError('Tailscale unreachable'),
|
|
);
|
|
} else {
|
|
channel.readyCompleter.complete();
|
|
}
|
|
return channel;
|
|
},
|
|
);
|
|
await tester.pumpWidget(
|
|
PipelinesRoot(
|
|
federatedChats: false,
|
|
nativeUpdatesSupported: false,
|
|
server: ServerEndpoint.resolve(
|
|
base: Uri.parse('file:///'),
|
|
web: false,
|
|
configured: home.endpoints.first,
|
|
),
|
|
catalogStore: store,
|
|
check: (_) async => SessionState.signedIn,
|
|
clientFactory: () => client,
|
|
),
|
|
);
|
|
for (var frame = 0; frame < 16; frame++) {
|
|
await tester.pump(const Duration(milliseconds: 20));
|
|
}
|
|
expect(attempts.map((uri) => uri.toString()), home.endpoints);
|
|
expect(client.endpoint.toString(), home.endpoints.last);
|
|
expect(client.state.kind, ConnectionKind.connected);
|
|
expect(serverIdentity(client), home.id);
|
|
expect(store.catalog?.selectedId, home.id);
|
|
expect(
|
|
tester.widget<PipelinesApp>(find.byType(PipelinesApp)).serverId,
|
|
home.id,
|
|
);
|
|
expect(ServerSession.headersFor(Uri.parse(home.endpoints.last)), {
|
|
'Cookie': 'pipelines_session=home',
|
|
});
|
|
expect(
|
|
ServerSession.headersFor(Uri.parse(other.endpoints.first)),
|
|
isEmpty,
|
|
);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
},
|
|
);
|
|
}
|