Skip to content

Commit

Permalink
Fixed shuffleboard api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Dec 11, 2023
1 parent 50bba59 commit f4cd4b1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
1 change: 0 additions & 1 deletion lib/services/nt4_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter/foundation.dart';
import 'package:elastic_dashboard/services/ds_interop.dart';
import 'package:elastic_dashboard/services/log.dart';
import 'package:elastic_dashboard/services/nt4.dart';
import 'package:elastic_dashboard/services/settings.dart';

NT4Connection get nt4Connection => NT4Connection.instance;

Expand Down
5 changes: 5 additions & 0 deletions test/pages/dashboard_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ void main() {
final mockNT4Client = MockNT4Client();
final mockSubscription = MockNT4Subscription();

when(mockNT4Connection.isNT4Connected).thenReturn(true);
when(mockNT4Connection.connectionStatus())
.thenAnswer((_) => Stream.value(true));
when(mockNT4Connection.latencyStream()).thenAnswer((_) => Stream.value(0));

when(mockSubscription.periodicStream())
.thenAnswer((_) => Stream.value(null));

Expand Down
48 changes: 42 additions & 6 deletions test/services/shuffleboard_nt_listener_test.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';

import 'package:elastic_dashboard/services/nt4.dart';
import 'package:elastic_dashboard/services/nt4_connection.dart';
import 'package:elastic_dashboard/services/settings.dart';
import 'package:elastic_dashboard/services/shuffleboard_nt_listener.dart';
import '../test_util.mocks.dart';

void main() {
test('Shuffleboard NT listener', () async {
nt4Connection.nt4Connect('0.0.0.0');
List<Function(NT4Topic topic)> topicAnnounceListeners = [];
Map<String, dynamic> lastAnnouncedValues = {
'/Shuffleboard/.metadata/Test-Tab/Test Number/Position': [1.0, 1.0],
'/Shuffleboard/.metadata/Test-Tab/Test Number/Size': [2.0, 2.0],
};

final mockNT4Connection = MockNT4Connection();
final mockNT4Client = MockNT4Client();
final mockSubscription = MockNT4Subscription();

when(mockNT4Client.lastAnnouncedValues).thenReturn(lastAnnouncedValues);
when(mockNT4Client.topicAnnounceListeners)
.thenReturn(topicAnnounceListeners);
when(mockNT4Client.addTopicAnnounceListener(any)).thenAnswer(
(realInvocation) =>
topicAnnounceListeners.add(realInvocation.positionalArguments[0]));

when(mockSubscription.periodicStream())
.thenAnswer((_) => Stream.value(null));

when(mockNT4Connection.nt4Client).thenReturn(mockNT4Client);

when(mockNT4Connection.isNT4Connected).thenReturn(true);

when(mockNT4Connection.latencyStream()).thenAnswer((_) => Stream.value(0));

when(mockNT4Connection.getLastAnnouncedValue(any)).thenAnswer(
(realInvocation) =>
lastAnnouncedValues[realInvocation.positionalArguments[0]],
);

when(mockNT4Connection.subscribeAndRetrieveData<List<Object?>>(any))
.thenAnswer((realInvocation) => Future.value(
lastAnnouncedValues[realInvocation.positionalArguments[0]]));

when(mockNT4Connection.subscribe(any, any)).thenReturn(mockSubscription);

when(mockNT4Connection.subscribe(any)).thenReturn(mockSubscription);

NT4Connection.instance = mockNT4Connection;

Map<String, dynamic> announcedWidgetData = {};

Expand All @@ -22,11 +63,6 @@ void main() {

expect(nt4Connection.nt4Client.topicAnnounceListeners.isNotEmpty, true);

nt4Connection.nt4Client.lastAnnouncedValues.addAll({
'/Shuffleboard/.metadata/Test-Tab/Test Number/Position': [1.0, 1.0],
'/Shuffleboard/.metadata/Test-Tab/Test Number/Size': [2.0, 2.0],
});

for (final callback in nt4Connection.nt4Client.topicAnnounceListeners) {
callback.call(NT4Topic(
name: '/Shuffleboard/.metadata/Test-Tab/Test Number/Position',
Expand Down

0 comments on commit f4cd4b1

Please sign in to comment.