Nikolas Rimikis
1 year ago
committed by
GitHub
5 changed files with 204 additions and 5 deletions
@ -0,0 +1,12 @@
|
||||
import 'package:neon/src/platform/platform.dart'; |
||||
import 'package:test/test.dart'; |
||||
|
||||
void main() { |
||||
test('NeonPlatform', () async { |
||||
expect(() => NeonPlatform.instance, throwsA(isA<StateError>())); |
||||
|
||||
await NeonPlatform.setup(); |
||||
|
||||
expect(NeonPlatform.instance, isA<NeonPlatform>()); |
||||
}); |
||||
} |
@ -0,0 +1,73 @@
|
||||
// ignore_for_file: unreachable_from_main |
||||
|
||||
import 'dart:async'; |
||||
|
||||
import 'package:mocktail/mocktail.dart'; |
||||
import 'package:neon/src/utils/stream_listenable.dart'; |
||||
import 'package:rxdart/rxdart.dart'; |
||||
import 'package:test/test.dart'; |
||||
|
||||
class MockCallbackFunction extends Mock { |
||||
FutureOr<void> call(); |
||||
} |
||||
|
||||
void main() { |
||||
group('StreamListenable', () { |
||||
test('stream', () async { |
||||
final stream = BehaviorSubject<bool>(); |
||||
final callback = MockCallbackFunction(); |
||||
|
||||
StreamListenable(stream).addListener(callback.call); |
||||
|
||||
verifyNever(callback.call); |
||||
|
||||
stream.value = true; |
||||
await Future.delayed(const Duration(milliseconds: 100)); |
||||
verify(callback.call).called(1); |
||||
|
||||
stream.value = true; |
||||
await Future.delayed(const Duration(milliseconds: 100)); |
||||
verify(callback.call).called(1); |
||||
|
||||
unawaited(stream.close()); |
||||
}); |
||||
|
||||
test('multiStream', () async { |
||||
final stream = BehaviorSubject<bool>(); |
||||
final stream2 = BehaviorSubject<int>(); |
||||
final callback = MockCallbackFunction(); |
||||
|
||||
StreamListenable.multiListenable({ |
||||
stream, |
||||
stream2, |
||||
}).addListener(callback.call); |
||||
|
||||
verifyNever(callback.call); |
||||
|
||||
stream.value = true; |
||||
await Future.delayed(const Duration(milliseconds: 100)); |
||||
verify(callback.call).called(1); |
||||
|
||||
stream2.value = 3; |
||||
await Future.delayed(const Duration(milliseconds: 100)); |
||||
verify(callback.call).called(1); |
||||
|
||||
unawaited(stream.close()); |
||||
unawaited(stream2.close()); |
||||
}); |
||||
|
||||
test('dispose', () { |
||||
final controller = StreamController(); |
||||
|
||||
final listenable = StreamListenable(controller.stream); |
||||
|
||||
expect(controller.hasListener, true); |
||||
|
||||
// ignore: cascade_invocations |
||||
listenable.dispose(); |
||||
|
||||
expect(controller.isClosed, false); |
||||
unawaited(controller.close()); |
||||
}); |
||||
}); |
||||
} |
@ -0,0 +1,17 @@
|
||||
import 'package:neon/src/utils/user_agent.dart'; |
||||
import 'package:package_info_plus/package_info_plus.dart'; |
||||
import 'package:test/test.dart'; |
||||
|
||||
void main() { |
||||
test('UserAgent', () { |
||||
final packageInfo = PackageInfo( |
||||
appName: 'appName', |
||||
packageName: 'packageName', |
||||
version: 'version', |
||||
buildNumber: 'buildNumber', |
||||
); |
||||
buildUserAgent(packageInfo); |
||||
|
||||
expect(neonUserAgent, 'Neon version+buildNumber'); |
||||
}); |
||||
} |
Loading…
Reference in new issue