forked from eatvio/eatvio_app
feat(tests): increased tests coverage
This commit is contained in:
90
test/core/websockets/ws_manager_test.dart
Normal file
90
test/core/websockets/ws_manager_test.dart
Normal file
@@ -0,0 +1,90 @@
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/websockets/ws_manager.dart';
|
||||
import 'package:eatvio_app/core/websockets/ws_service.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
|
||||
import 'ws_manager_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<WsService>()])
|
||||
void main() {
|
||||
group('WsManager', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
test('initialize returns early when client is not null', () async {
|
||||
final wsService = MockWsService();
|
||||
final manager = WsManager(wsService: wsService);
|
||||
|
||||
|
||||
await manager.initialize();
|
||||
|
||||
expect(manager, isNotNull);
|
||||
});
|
||||
|
||||
test('newMessagesStream returns null when channel is null', () {
|
||||
final wsService = MockWsService();
|
||||
final manager = WsManager(wsService: wsService);
|
||||
|
||||
expect(manager.newMessagesStream, isNull);
|
||||
});
|
||||
|
||||
test('newNotificationsStream returns null when channel is null', () {
|
||||
final wsService = MockWsService();
|
||||
final manager = WsManager(wsService: wsService);
|
||||
|
||||
expect(manager.newNotificationsStream, isNull);
|
||||
});
|
||||
|
||||
test('directChatStream returns null when channel is null', () {
|
||||
final wsService = MockWsService();
|
||||
final manager = WsManager(wsService: wsService);
|
||||
|
||||
expect(manager.directChatStream, isNull);
|
||||
});
|
||||
|
||||
test('clientTypingStream returns null when channel is null', () {
|
||||
final wsService = MockWsService();
|
||||
final manager = WsManager(wsService: wsService);
|
||||
|
||||
expect(manager.clientTypingStream, isNull);
|
||||
});
|
||||
|
||||
test('subscribeDirectChatChannel does nothing when channel is null', () {
|
||||
final wsService = MockWsService();
|
||||
final manager = WsManager(wsService: wsService);
|
||||
|
||||
// Не должно быть исключений
|
||||
manager.subscribeDirectChatChannel();
|
||||
});
|
||||
|
||||
test('unsubscribeDirectChatChannel does nothing when channel is null', () {
|
||||
final wsService = MockWsService();
|
||||
final manager = WsManager(wsService: wsService);
|
||||
|
||||
// Не должно быть исключений
|
||||
manager.unsubscribeDirectChatChannel();
|
||||
});
|
||||
|
||||
test('clear sets client and userId to null', () async {
|
||||
final wsService = MockWsService();
|
||||
final manager = WsManager(wsService: wsService);
|
||||
|
||||
manager.userId = 1;
|
||||
|
||||
await manager.clear();
|
||||
|
||||
expect(manager.client, isNull);
|
||||
expect(manager.userId, isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user