feat(app): load saved endpoint during native startup
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/bootstrap.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_store.dart';
|
||||
|
||||
class _TestSettingsStore implements SettingsStore {
|
||||
_TestSettingsStore(this.value, {this.fail = false});
|
||||
|
||||
final String value;
|
||||
final bool fail;
|
||||
int loads = 0;
|
||||
|
||||
@override
|
||||
Future<SettingsValues> load() async {
|
||||
loads++;
|
||||
if (fail) throw StateError('unavailable');
|
||||
return SettingsValues(serverUrl: value);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> saveServerUrl(String value) async => true;
|
||||
|
||||
@override
|
||||
Future<bool> saveWorkspace(String value) async => true;
|
||||
}
|
||||
|
||||
void main() {
|
||||
const nativeBase = 'http://127.0.0.1:8096/';
|
||||
|
||||
test(
|
||||
'uses saved endpoint natively only when build configuration is blank',
|
||||
() async {
|
||||
final store = _TestSettingsStore('wss://saved.example.test');
|
||||
final saved = await resolveLaunchServer(
|
||||
base: Uri.parse(nativeBase),
|
||||
configured: '',
|
||||
web: false,
|
||||
settingsStore: store,
|
||||
);
|
||||
expect(saved.uri, Uri.parse('wss://saved.example.test/connect'));
|
||||
expect(store.loads, 1);
|
||||
|
||||
final configured = await resolveLaunchServer(
|
||||
base: Uri.parse(nativeBase),
|
||||
configured: 'ws://build.example.test',
|
||||
web: false,
|
||||
settingsStore: store,
|
||||
);
|
||||
expect(configured.uri, Uri.parse('ws://build.example.test/connect'));
|
||||
expect(store.loads, 1);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'blank or failed settings load leaves native configuration required',
|
||||
() async {
|
||||
for (final store in [
|
||||
_TestSettingsStore(''),
|
||||
_TestSettingsStore('', fail: true),
|
||||
]) {
|
||||
final server = await resolveLaunchServer(
|
||||
base: Uri.parse(nativeBase),
|
||||
configured: '',
|
||||
web: false,
|
||||
settingsStore: store,
|
||||
);
|
||||
expect(server.requiresConfiguration, isTrue);
|
||||
expect(server.uri, isNull);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'web infers same-origin endpoint without loading native settings',
|
||||
() async {
|
||||
final store = _TestSettingsStore('wss://saved.example.test');
|
||||
final server = await resolveLaunchServer(
|
||||
base: Uri.parse('https://web.example.test/runs'),
|
||||
configured: '',
|
||||
web: true,
|
||||
settingsStore: store,
|
||||
);
|
||||
expect(server.uri, Uri.parse('wss://web.example.test/connect'));
|
||||
expect(store.loads, 0);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user