38 lines
1 KiB
Dart
38 lines
1 KiB
Dart
|
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
|
import 'package:halkyon_learn_flutter/src/feature/jellyfin/data/jellyfin_suggestion.dart';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
test('asks the instance once, as it is first needed', () async {
|
||
|
|
var asked = 0;
|
||
|
|
final suggestion = JellyfinSuggestion(() async {
|
||
|
|
asked++;
|
||
|
|
return 'https://jellyfin.halkyon.eu/';
|
||
|
|
});
|
||
|
|
expect(suggestion.server.value, isNull);
|
||
|
|
|
||
|
|
await suggestion.look();
|
||
|
|
await suggestion.look();
|
||
|
|
|
||
|
|
expect(asked, 1);
|
||
|
|
expect(suggestion.server.value, Uri.parse('https://jellyfin.halkyon.eu/'));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('asks again only after asking failed; none named is none', () async {
|
||
|
|
var asked = 0;
|
||
|
|
final suggestion = JellyfinSuggestion(() async {
|
||
|
|
asked++;
|
||
|
|
if (asked == 1) {
|
||
|
|
throw Exception('offline');
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
});
|
||
|
|
|
||
|
|
await suggestion.look();
|
||
|
|
expect(suggestion.server.value, isNull);
|
||
|
|
await suggestion.look();
|
||
|
|
await suggestion.look();
|
||
|
|
|
||
|
|
expect(asked, 2);
|
||
|
|
expect(suggestion.server.value, isNull);
|
||
|
|
});
|
||
|
|
}
|