83 lines
2.4 KiB
Dart
83 lines
2.4 KiB
Dart
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('a saved endpoint wins over the build default on a phone', () async {
|
|
final store = _TestSettingsStore('wss://saved.example.test');
|
|
final saved = await resolveLaunchServer(
|
|
base: Uri.parse(nativeBase),
|
|
configured: 'ws://build.example.test',
|
|
web: false,
|
|
settingsStore: store,
|
|
);
|
|
expect(saved.uri, Uri.parse('wss://saved.example.test/connect'));
|
|
|
|
// Nothing saved yet: the build default stands (and pre-fills onboarding).
|
|
final fallback = await resolveLaunchServer(
|
|
base: Uri.parse(nativeBase),
|
|
configured: 'ws://build.example.test',
|
|
web: false,
|
|
settingsStore: _TestSettingsStore(''),
|
|
);
|
|
expect(fallback.uri, Uri.parse('ws://build.example.test/connect'));
|
|
});
|
|
|
|
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);
|
|
},
|
|
);
|
|
}
|