feat(app): register native Settings on the shared live session
This commit is contained in:
@@ -22,6 +22,32 @@ List<String> types(FakeChannel channel) => [
|
||||
];
|
||||
|
||||
void main() {
|
||||
test('Retry preserves an endpoint changed through shared Settings', () async {
|
||||
final endpoints = <Uri>[];
|
||||
final client = PipelinesClient(
|
||||
channelFactory: (uri) {
|
||||
endpoints.add(uri);
|
||||
return FakeChannel()..readyCompleter.complete();
|
||||
},
|
||||
);
|
||||
final session = AppSession(
|
||||
endpoint: Uri.parse('ws://original.test/connect'),
|
||||
client: client,
|
||||
);
|
||||
addTearDown(session.dispose);
|
||||
await session.start();
|
||||
final changed = Uri.parse('ws://selected.test/connect');
|
||||
await session.client.connect(changed);
|
||||
await session.stop();
|
||||
await session.retry();
|
||||
expect(endpoints, [
|
||||
Uri.parse('ws://original.test/connect'),
|
||||
changed,
|
||||
changed,
|
||||
]);
|
||||
expect(session.endpoint, changed);
|
||||
});
|
||||
|
||||
test(
|
||||
'start subscribes once, stop unsubscribes, and the app owns the socket',
|
||||
() async {
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
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/core/transport/pipelines_client.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import 'pipelines_app_test.dart' show webServer, requestOf;
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('Settings shares socket and one native bar ($cupertino)', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
if (cupertino) {
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
|
||||
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
|
||||
}
|
||||
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 tester.pumpWidget(
|
||||
PipelinesApp(
|
||||
server: webServer(),
|
||||
client: client,
|
||||
cupertino: cupertino,
|
||||
routeInformationProvider: provider,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(
|
||||
requestOf(channel, 'ping'),
|
||||
isNull,
|
||||
reason: 'Unvisited settings must not issue hidden requests',
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Settings').last);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/settings');
|
||||
expect(find.text('Server URL'), findsOneWidget);
|
||||
if (cupertino) {
|
||||
final title = tester.widget<Text>(find.text('Connection'));
|
||||
expect(
|
||||
title.style!.color!.computeLuminance(),
|
||||
greaterThan(0.5),
|
||||
reason: 'Cupertino dark host must not inherit light Material text',
|
||||
);
|
||||
}
|
||||
expect(find.text('Settings — Not implemented'), findsNothing);
|
||||
expect(sockets, 1);
|
||||
expect(
|
||||
cupertino ? find.byType(CupertinoNavigationBar) : find.byType(AppBar),
|
||||
findsOneWidget,
|
||||
);
|
||||
final ping = requestOf(channel, 'ping')!;
|
||||
channel.incoming.add(
|
||||
jsonEncode({
|
||||
'id': ping['id'],
|
||||
'type': 'pong',
|
||||
'build': {'version': 'settings-fixture'},
|
||||
'time': 'fixture time',
|
||||
}),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.textContaining('settings-fixture'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pump();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user