@@ -27,19 +27,28 @@ describe('KvmComponent', () => {
27
27
const setup = ( ) : void => {
28
28
fixture = TestBed . createComponent ( KVMComponent )
29
29
component = fixture . componentInstance
30
- // Set initial inputs via setInput
30
+ // Set initial inputs via setInput to prevent effect from triggering during setup
31
+ fixture . componentRef . setInput ( 'deviceConnection' , false )
31
32
fixture . componentRef . setInput ( 'mpsServer' , '' )
32
- fixture . componentRef . setInput ( 'authToken' , '' )
33
+ fixture . componentRef . setInput ( 'authToken' , 'authToken ' )
33
34
fixture . componentRef . setInput ( 'deviceId' , '' )
34
35
fixture . detectChanges ( )
36
+
37
+ // Now enable connection to trigger init
38
+ fixture . componentRef . setInput ( 'deviceConnection' , true )
39
+ fixture . detectChanges ( )
35
40
}
36
41
37
42
const asyncSetup = fakeAsync ( ( ) => {
38
43
fixture = TestBed . createComponent ( KVMComponent )
39
44
component = fixture . componentInstance
45
+ fixture . componentRef . setInput ( 'deviceConnection' , false )
40
46
fixture . componentRef . setInput ( 'mpsServer' , 'wss://localhost' )
41
47
fixture . componentRef . setInput ( 'authToken' , 'authToken' )
42
- fixture . componentRef . setInput ( 'deviceId' , '' )
48
+ fixture . detectChanges ( )
49
+
50
+ fixture . componentRef . setInput ( 'deviceConnection' , true ) // Enable connection to trigger init
51
+ fixture . detectChanges ( )
43
52
tick ( 4500 )
44
53
fixture . detectChanges ( )
45
54
flush ( )
@@ -53,17 +62,17 @@ describe('KvmComponent', () => {
53
62
expect ( component . mouseHelper ) . toBeInstanceOf ( MouseHelper )
54
63
expect ( component . keyboardHelper ) . toBeInstanceOf ( KeyBoardHelper )
55
64
expect ( component . dataProcessor ) . toBeInstanceOf ( DataProcessor )
56
- expect ( component . selected ) . toEqual ( 1 )
65
+ expect ( component . selected ( ) ) . toEqual ( 1 )
57
66
expect ( component . encodings . length ) . toEqual ( 2 )
58
67
expect ( component . mpsServer ( ) ) . toBe ( '' )
59
68
expect ( component . deviceId ( ) ) . toBe ( '' )
60
- expect ( component . authToken ( ) ) . toBe ( '' )
69
+ expect ( component . authToken ( ) ) . toBe ( 'authToken ' )
61
70
} )
62
71
63
72
it ( 'should autoconnect on pageload' , ( ) => {
64
73
asyncSetup ( )
65
74
spyOn < any > ( component . redirector , 'start' )
66
- spyOn ( component . keyboardHelper , 'GrabKeyInput' )
75
+ spyOn ( component . keyboardHelper ! , 'GrabKeyInput' )
67
76
expect ( component . redirector ) . not . toBeNull ( )
68
77
expect ( component . mpsServer ( ) ) . toEqual ( 'wss://localhost' )
69
78
expect ( component . authToken ( ) ) . toEqual ( 'authToken' )
@@ -72,22 +81,30 @@ describe('KvmComponent', () => {
72
81
it ( 'should reset all the objects once kvm is stopped' , ( ) => {
73
82
setup ( )
74
83
spyOn < any > ( component . redirector , 'stop' )
75
- spyOn ( component . keyboardHelper , 'UnGrabKeyInput' )
84
+ spyOn ( component . keyboardHelper ! , 'UnGrabKeyInput' )
76
85
const resetSpy = spyOn ( component , 'reset' )
77
86
component . stopKvm ( )
78
87
expect ( component . redirector ?. stop ) . toHaveBeenCalled ( )
79
- expect ( component . keyboardHelper . UnGrabKeyInput ) . toHaveBeenCalled ( )
88
+ expect ( component . keyboardHelper ! . UnGrabKeyInput ) . toHaveBeenCalled ( )
80
89
expect ( resetSpy ) . toHaveBeenCalled ( )
81
90
} )
82
91
83
92
it ( 'should disconnect the active KVM session if there is an encoding change' , fakeAsync ( ( ) => {
84
93
setup ( )
85
94
const stopKvmSpy = spyOn ( component , 'stopKvm' )
86
95
const autoConnectSpy = spyOn ( component , 'autoConnect' )
87
- component . selectedEncoding ( ) . emit ( 1 )
88
- tick ( 1100 )
96
+
97
+ // First set deviceConnection to true and ensure component is connected
98
+ fixture . componentRef . setInput ( 'deviceConnection' , true )
89
99
fixture . detectChanges ( )
90
- expect ( component . selected ) . toEqual ( 1 )
100
+ tick ( )
101
+
102
+ // Then change the encoding
103
+ fixture . componentRef . setInput ( 'selectedEncoding' , 2 ) // Change from default 1 to 2
104
+ fixture . detectChanges ( )
105
+ tick ( 1100 ) // Wait for the timer in onEncodingChange
106
+
107
+ expect ( component . selected ( ) ) . toEqual ( 2 )
91
108
expect ( stopKvmSpy ) . toHaveBeenCalled ( )
92
109
expect ( autoConnectSpy ) . toHaveBeenCalled ( )
93
110
flush ( )
@@ -103,9 +120,9 @@ describe('KvmComponent', () => {
103
120
104
121
it ( 'should trigger the core components method on mouse interactions' , ( ) => {
105
122
setup ( )
106
- spyOn ( component . mouseHelper , 'mousedown' )
107
- spyOn ( component . mouseHelper , 'mouseup' )
108
- spyOn ( component . mouseHelper , 'mousemove' )
123
+ spyOn ( component . mouseHelper ! , 'mousedown' )
124
+ spyOn ( component . mouseHelper ! , 'mouseup' )
125
+ spyOn ( component . mouseHelper ! , 'mousemove' )
109
126
110
127
const event : any = {
111
128
button : 1 ,
@@ -114,14 +131,14 @@ describe('KvmComponent', () => {
114
131
}
115
132
component . onMousedown ( event as MouseEvent )
116
133
expect ( component . mouseHelper ) . not . toBeNull ( )
117
- expect ( component . mouseHelper . mousedown ) . toHaveBeenCalled ( )
134
+ expect ( component . mouseHelper ! . mousedown ) . toHaveBeenCalled ( )
118
135
119
136
component . onMouseup ( event as MouseEvent )
120
137
expect ( component . mouseHelper ) . not . toBeNull ( )
121
- expect ( component . mouseHelper . mouseup ) . toHaveBeenCalled ( )
138
+ expect ( component . mouseHelper ! . mouseup ) . toHaveBeenCalled ( )
122
139
123
140
component . onMousemove ( event as MouseEvent )
124
141
expect ( component . mouseHelper ) . not . toBeNull ( )
125
- expect ( component . mouseHelper . mousemove ) . toHaveBeenCalled ( )
142
+ expect ( component . mouseHelper ! . mousemove ) . toHaveBeenCalled ( )
126
143
} )
127
144
} )
0 commit comments