abd696b0d9
Add the Settings destination under lib/features/settings with an editable websocket endpoint, truthful connection states, one ping per connect/mount, workspace validation and persistence under new feature-owned keys. Material and Cupertino controls, wrapping copy at large text, pending ping state, and isolated probe tools plus widget/unit coverage.
161 lines
5.2 KiB
Dart
161 lines
5.2 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/core/transport/pipelines_client.dart'
|
|
as transport;
|
|
import 'package:pipelines_app/features/settings/default_endpoint.dart';
|
|
import 'package:pipelines_app/features/settings/settings_copy.dart';
|
|
|
|
void main() {
|
|
group('workspace validation', () {
|
|
test('blank is untouched, relative is rejected, absolute is accepted', () {
|
|
expect(validateWorkspacePath(''), isNull);
|
|
expect(validateWorkspacePath(' '), isNull);
|
|
expect(validateWorkspacePath('repos/pipelines'), workspacePathError);
|
|
expect(validateWorkspacePath('/Users/you/repos/pipelines'), isNull);
|
|
expect(
|
|
validateWorkspacePath(' /srv/pipelines '),
|
|
isNull,
|
|
reason: 'trimmed before validating',
|
|
);
|
|
});
|
|
|
|
test('Save needs a trimmed absolute path, never a blank field', () {
|
|
expect(canSaveWorkspace(''), isFalse);
|
|
expect(canSaveWorkspace(' '), isFalse);
|
|
expect(canSaveWorkspace('relative/path'), isFalse);
|
|
expect(canSaveWorkspace('/srv/pipelines'), isTrue);
|
|
expect(canSaveWorkspace(' /srv/pipelines '), isTrue);
|
|
});
|
|
|
|
test('the saved line names an empty value instead of showing nothing', () {
|
|
expect(savedWorkspaceLine(''), 'Saved workspace: (none)');
|
|
expect(
|
|
savedWorkspaceLine(' /srv/pipelines '),
|
|
'Saved workspace: /srv/pipelines',
|
|
);
|
|
});
|
|
});
|
|
|
|
group('server build and connection card', () {
|
|
test('build label includes only the reported parts', () {
|
|
expect(serverBuildLabel(), '');
|
|
expect(serverBuildLabel(version: 'v1.2.3'), 'Server build v1.2.3');
|
|
expect(
|
|
serverBuildLabel(version: 'v1.2.3', commit: 'abc1234'),
|
|
'Server build v1.2.3 (abc1234)',
|
|
);
|
|
expect(serverBuildLabel(commit: 'abc1234'), 'Server build (abc1234)');
|
|
});
|
|
|
|
test('idle, connecting and disconnected states keep the app words', () {
|
|
expect(
|
|
connectionCardLines(
|
|
const transport.ConnectionState(transport.ConnectionKind.idle),
|
|
),
|
|
<String>['Not connected'],
|
|
);
|
|
expect(
|
|
connectionCardLines(
|
|
const transport.ConnectionState(
|
|
transport.ConnectionKind.connecting,
|
|
attempt: 3,
|
|
),
|
|
),
|
|
<String>['Connecting (attempt 3)\u2026'],
|
|
);
|
|
expect(
|
|
connectionCardLines(
|
|
const transport.ConnectionState(
|
|
transport.ConnectionKind.disconnected,
|
|
reason: 'Connection closed',
|
|
retrying: true,
|
|
),
|
|
),
|
|
<String>[
|
|
'Disconnected',
|
|
'Connection closed',
|
|
'Retrying with backoff\u2026',
|
|
],
|
|
);
|
|
expect(
|
|
connectionCardLines(
|
|
const transport.ConnectionState(
|
|
transport.ConnectionKind.disconnected,
|
|
),
|
|
),
|
|
<String>['Disconnected'],
|
|
);
|
|
});
|
|
|
|
test('connected names unavailable build/time instead of zero', () {
|
|
final lines = connectionCardLines(
|
|
const transport.ConnectionState(transport.ConnectionKind.connected),
|
|
);
|
|
expect(lines, <String>[
|
|
'Connected',
|
|
'Server build unavailable',
|
|
'Server time unavailable',
|
|
]);
|
|
});
|
|
|
|
test('connected reports the ping fields and an explicit ping error', () {
|
|
final lines = connectionCardLines(
|
|
const transport.ConnectionState(transport.ConnectionKind.connected),
|
|
buildVersion: 'v9',
|
|
buildCommit: 'deadbee',
|
|
serverTime: '2026-10-21T12:00:00Z',
|
|
pingError: 'Server details unavailable: timed out',
|
|
);
|
|
expect(lines, <String>[
|
|
'Connected',
|
|
'Server build v9 (deadbee)',
|
|
'Server time 2026-10-21T12:00:00Z',
|
|
'Server details unavailable: timed out',
|
|
]);
|
|
});
|
|
|
|
test(
|
|
'connected while the ping is pending says loading, not unavailable',
|
|
() {
|
|
final lines = connectionCardLines(
|
|
const transport.ConnectionState(transport.ConnectionKind.connected),
|
|
pingInFlight: true,
|
|
);
|
|
expect(lines, <String>['Connected', serverDetailsPending]);
|
|
expect(lines.any((line) => line.contains('unavailable')), isFalse);
|
|
},
|
|
);
|
|
|
|
test('a failed ping is one explicit line, not two unavailable values', () {
|
|
final lines = connectionCardLines(
|
|
const transport.ConnectionState(transport.ConnectionKind.connected),
|
|
pingError: 'Server details unavailable: timed out',
|
|
);
|
|
expect(lines, <String>[
|
|
'Connected',
|
|
'Server details unavailable: timed out',
|
|
]);
|
|
});
|
|
});
|
|
|
|
group('same-origin default endpoint', () {
|
|
test('native builds bake no endpoint', () {
|
|
expect(defaultServerUrl(web: false), '');
|
|
});
|
|
|
|
test('web uses the page origin, upgraded to ws/wss', () {
|
|
expect(
|
|
defaultServerUrl(web: true, base: Uri.parse('http://127.0.0.1:8123/')),
|
|
'ws://127.0.0.1:8123/connect',
|
|
);
|
|
expect(
|
|
defaultServerUrl(
|
|
web: true,
|
|
base: Uri.parse('https://pipelines.example.test/pipelines'),
|
|
),
|
|
'wss://pipelines.example.test/connect',
|
|
);
|
|
expect(defaultServerUrl(web: true, base: Uri.parse('about:blank')), '');
|
|
});
|
|
});
|
|
}
|