3136e5bb7e
Replace the tabbed Settings flow with a single grouped page that searches and lazily loads server-backed sections. Preserve existing settings behavior while adding inline loading and retry states and updating coverage for the new navigation model.
66 lines
1.6 KiB
Dart
66 lines
1.6 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/settings/settings_server_load.dart';
|
|
|
|
void main() {
|
|
test('concurrent loads share one request', () async {
|
|
var calls = 0;
|
|
final reply = Completer<int>();
|
|
final load = ServerLoad<int>(() {
|
|
calls++;
|
|
return reply.future;
|
|
});
|
|
addTearDown(load.dispose);
|
|
|
|
final first = load.load();
|
|
final second = load.refresh();
|
|
expect(calls, 1);
|
|
expect(load.loading, isTrue);
|
|
|
|
reply.complete(7);
|
|
await first;
|
|
await second;
|
|
expect(load.value, 7);
|
|
expect(load.hasValue, isTrue);
|
|
expect(load.loading, isFalse);
|
|
expect(load.error, isNull);
|
|
});
|
|
|
|
test(
|
|
'a failed refresh keeps the last value; a retry clears the error',
|
|
() async {
|
|
var calls = 0;
|
|
final load = ServerLoad<String>(() async {
|
|
calls++;
|
|
if (calls == 2) throw StateError('server unreachable');
|
|
return 'value $calls';
|
|
});
|
|
addTearDown(load.dispose);
|
|
|
|
await load.load();
|
|
expect(load.value, 'value 1');
|
|
|
|
await load.refresh();
|
|
expect(load.value, 'value 1', reason: 'the cached value survives');
|
|
expect(load.error, isA<StateError>());
|
|
|
|
await load.refresh();
|
|
expect(load.error, isNull);
|
|
expect(load.value, 'value 3');
|
|
expect(calls, 3);
|
|
},
|
|
);
|
|
|
|
test('a reply that lands after dispose is dropped quietly', () async {
|
|
final reply = Completer<int>();
|
|
final load = ServerLoad<int>(() => reply.future);
|
|
final pending = load.load();
|
|
load.dispose();
|
|
|
|
reply.complete(1);
|
|
await pending;
|
|
expect(load.hasValue, isFalse);
|
|
});
|
|
}
|