-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb6cba1
commit 7ce3fca
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:elastic_dashboard/services/robot_notifications_listener.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
|
||
import '../test_util.dart'; | ||
import '../test_util.mocks.dart'; | ||
|
||
// Create a mock class for the onNotification callback | ||
class MockNotificationCallback extends Mock { | ||
void call(String? title, String? description, Icon? icon); | ||
} | ||
|
||
void main() { | ||
test("Robot Notifications (No Connection) ", () { | ||
MockNTConnection mockConnection = createMockOfflineNT4(); | ||
MockNT4Subscription mockSub = MockNT4Subscription(); | ||
|
||
when(mockConnection.subscribeAll(any, any)).thenReturn(mockSub); | ||
|
||
// Create a mock for the onNotification callback | ||
MockNotificationCallback mockOnNotification = MockNotificationCallback(); | ||
|
||
RobotNotificationsListener notifications = RobotNotificationsListener( | ||
ntConnection: mockConnection, | ||
onNotification: mockOnNotification.call, | ||
); | ||
|
||
notifications.listen(); | ||
|
||
// Verify that subscribeAll was called with the specific parameters | ||
verify(mockConnection.subscribeAll('/Elastic/robotnotifications', 0.2)) | ||
.called(1); | ||
verify(mockConnection.addDisconnectedListener(any)).called(1); | ||
|
||
// Verify that no other interactions have been made with the mockConnection | ||
verifyNoMoreInteractions(mockConnection); | ||
|
||
// Verify that the onNotification callback was never called | ||
verifyNever(mockOnNotification.call(any, any, any)); | ||
}); | ||
} |