@@ -12,13 +12,14 @@ import {
12
12
getPipeline ,
13
13
rdiPipelineSelector ,
14
14
setChangedFile ,
15
- setPipeline ,
16
15
} from 'uiSrc/slices/rdi/pipeline'
17
- import { setPipelineDialogState } from 'uiSrc/slices/app/context'
16
+ import {
17
+ appContextPipelineManagement ,
18
+ setPipelineDialogState ,
19
+ } from 'uiSrc/slices/app/context'
18
20
import { sendEventTelemetry , TelemetryEvent } from 'uiSrc/telemetry'
19
21
import { FileChangeType } from 'uiSrc/slices/interfaces'
20
22
import SourcePipelineDialog , {
21
- EMPTY_PIPELINE ,
22
23
PipelineSourceOptions ,
23
24
} from './SourcePipelineModal'
24
25
@@ -42,117 +43,155 @@ jest.mock('uiSrc/slices/rdi/pipeline', () => ({
42
43
rdiPipelineSelector : jest . fn ( ) ,
43
44
} ) )
44
45
46
+ jest . mock ( 'uiSrc/slices/app/context' , ( ) => ( {
47
+ ...jest . requireActual ( 'uiSrc/slices/app/context' ) ,
48
+ appContextPipelineManagement : jest . fn ( ) ,
49
+ } ) )
50
+
45
51
let store : typeof mockedStore
46
52
beforeEach ( ( ) => {
47
53
cleanup ( )
48
54
store = cloneDeep ( mockedStore )
49
55
store . clearActions ( )
50
56
; ( rdiPipelineSelector as jest . Mock ) . mockReturnValue ( {
51
57
...initialStateDefault . rdi . pipeline ,
52
- loading : false ,
53
- config : '' ,
58
+ } )
59
+ ; ( appContextPipelineManagement as jest . Mock ) . mockReturnValue ( {
60
+ ...initialStateDefault . app . context . pipelineManagement ,
54
61
} )
55
62
} )
56
63
57
64
describe ( 'SourcePipelineDialog' , ( ) => {
58
- it ( 'should render' , ( ) => {
59
- expect ( render ( < SourcePipelineDialog /> ) ) . toBeTruthy ( )
60
- } )
61
-
62
- it ( 'should call proper actions after select fetch from server option' , ( ) => {
63
- const sendEventTelemetryMock = jest . fn ( )
64
- ; ( sendEventTelemetry as jest . Mock ) . mockImplementation (
65
- ( ) => sendEventTelemetryMock ,
66
- )
67
-
65
+ it ( 'should not show dialog by default and not set isOpenDialog to true' , ( ) => {
68
66
render ( < SourcePipelineDialog /> )
69
67
70
- fireEvent . click ( screen . getByTestId ( 'server-source-pipeline-dialog' ) )
71
-
72
- const expectedActions = [ getPipeline ( ) , setPipelineDialogState ( false ) ]
68
+ expect (
69
+ screen . queryByTestId ( 'file-source-pipeline-dialog' ) ,
70
+ ) . not . toBeInTheDocument ( )
73
71
74
- expect ( store . getActions ( ) ) . toEqual ( expectedActions )
75
- expect ( sendEventTelemetry ) . toBeCalledWith ( {
76
- event : TelemetryEvent . RDI_START_OPTION_SELECTED ,
77
- eventData : {
78
- id : 'rdiInstanceId' ,
79
- option : PipelineSourceOptions . SERVER ,
80
- } ,
81
- } )
72
+ expect ( store . getActions ( ) ) . toEqual ( [ ] )
82
73
} )
83
74
84
- it ( 'should call proper actions after select empty pipeline option' , ( ) => {
85
- const sendEventTelemetryMock = jest . fn ( )
86
- ; ( sendEventTelemetry as jest . Mock ) . mockImplementation (
87
- ( ) => sendEventTelemetryMock ,
88
- )
89
- render ( < SourcePipelineDialog /> )
90
-
91
- fireEvent . click ( screen . getByTestId ( 'empty-source-pipeline-dialog' ) )
92
-
93
- const expectedActions = [
94
- setPipeline ( EMPTY_PIPELINE ) ,
95
- setChangedFile ( { name : 'config' , status : FileChangeType . Added } ) ,
96
- setPipelineDialogState ( false ) ,
97
- ]
98
-
99
- expect ( store . getActions ( ) ) . toEqual ( expectedActions )
100
- expect ( sendEventTelemetry ) . toBeCalledWith ( {
101
- event : TelemetryEvent . RDI_START_OPTION_SELECTED ,
102
- eventData : {
103
- id : 'rdiInstanceId' ,
104
- option : PipelineSourceOptions . NEW ,
105
- } ,
75
+ it ( 'should show dialog when isOpenDialog flag is true' , ( ) => {
76
+ ; ( appContextPipelineManagement as jest . Mock ) . mockReturnValue ( {
77
+ ...initialStateDefault . app . context . pipelineManagement ,
78
+ isOpenDialog : true ,
106
79
} )
107
- } )
108
80
109
- it ( 'should call proper telemetry event after select empty pipeline option' , ( ) => {
110
- const sendEventTelemetryMock = jest . fn ( )
111
- ; ( sendEventTelemetry as jest . Mock ) . mockImplementation (
112
- ( ) => sendEventTelemetryMock ,
113
- )
114
81
render ( < SourcePipelineDialog /> )
115
82
116
- fireEvent . click ( screen . getByTestId ( 'file-source-pipeline-dialog' ) )
117
-
118
- expect ( sendEventTelemetry ) . toBeCalledWith ( {
119
- event : TelemetryEvent . RDI_START_OPTION_SELECTED ,
120
- eventData : {
121
- id : 'rdiInstanceId' ,
122
- option : PipelineSourceOptions . FILE ,
123
- } ,
124
- } )
83
+ expect (
84
+ screen . queryByTestId ( 'file-source-pipeline-dialog' ) ,
85
+ ) . toBeInTheDocument ( )
125
86
} )
126
87
127
88
it ( 'should not show dialog when there is deployed pipeline on a server' , ( ) => {
128
- const sendEventTelemetryMock = jest . fn ( )
129
- ; ( sendEventTelemetry as jest . Mock ) . mockImplementation (
130
- ( ) => sendEventTelemetryMock ,
131
- )
132
89
; ( rdiPipelineSelector as jest . Mock ) . mockReturnValue ( {
133
90
...initialStateDefault . rdi . pipeline ,
134
91
loading : false ,
135
- config : 'deployed config' ,
92
+ data : { config : 'some config' } ,
136
93
} )
137
94
138
95
render ( < SourcePipelineDialog /> )
139
96
140
- expect ( screen . queryByTestId ( 'file-source-pipeline-dialog' ) ) . not . toBeInTheDocument ( )
97
+ expect ( store . getActions ( ) ) . toEqual ( [ ] )
141
98
} )
142
99
143
100
it ( 'should not show dialog when config is fetching' , ( ) => {
144
- const sendEventTelemetryMock = jest . fn ( )
145
- ; ( sendEventTelemetry as jest . Mock ) . mockImplementation (
146
- ( ) => sendEventTelemetryMock ,
147
- )
148
101
; ( rdiPipelineSelector as jest . Mock ) . mockReturnValue ( {
149
102
...initialStateDefault . rdi . pipeline ,
150
103
loading : true ,
151
- config : '' ,
104
+ data : null ,
105
+ } )
106
+
107
+ render ( < SourcePipelineDialog /> )
108
+
109
+ expect ( store . getActions ( ) ) . toEqual ( [ ] )
110
+ } )
111
+
112
+ it ( 'should show dialog when there is no pipeline on a server' , ( ) => {
113
+ ; ( rdiPipelineSelector as jest . Mock ) . mockReturnValue ( {
114
+ ...initialStateDefault . rdi . pipeline ,
115
+ loading : false ,
116
+ data : { config : '' } ,
152
117
} )
153
118
154
119
render ( < SourcePipelineDialog /> )
155
120
156
- expect ( screen . queryByTestId ( 'file-source-pipeline-dialog' ) ) . not . toBeInTheDocument ( )
121
+ expect ( store . getActions ( ) ) . toEqual ( [ setPipelineDialogState ( true ) ] )
122
+ } )
123
+
124
+ describe ( 'Telemetry events' , ( ) => {
125
+ const sendEventTelemetryMock = jest . fn ( )
126
+
127
+ beforeEach ( ( ) => {
128
+ ; ( sendEventTelemetry as jest . Mock ) . mockImplementation (
129
+ ( ) => sendEventTelemetryMock ,
130
+ )
131
+ ; ( appContextPipelineManagement as jest . Mock ) . mockReturnValue ( {
132
+ ...initialStateDefault . app . context . pipelineManagement ,
133
+ isOpenDialog : true ,
134
+ } )
135
+ } )
136
+
137
+ it ( 'should call proper actions after select fetch from server option' , ( ) => {
138
+ render ( < SourcePipelineDialog /> )
139
+
140
+ fireEvent . click ( screen . getByTestId ( 'server-source-pipeline-dialog' ) )
141
+
142
+ const expectedActions = [ getPipeline ( ) , setPipelineDialogState ( false ) ]
143
+
144
+ expect ( store . getActions ( ) ) . toEqual ( expectedActions )
145
+ expect ( sendEventTelemetry ) . toBeCalledWith ( {
146
+ event : TelemetryEvent . RDI_START_OPTION_SELECTED ,
147
+ eventData : {
148
+ id : 'rdiInstanceId' ,
149
+ option : PipelineSourceOptions . SERVER ,
150
+ } ,
151
+ } )
152
+ } )
153
+
154
+ it ( 'should call proper actions after select empty pipeline option' , ( ) => {
155
+ render ( < SourcePipelineDialog /> )
156
+
157
+ fireEvent . click ( screen . getByTestId ( 'empty-source-pipeline-dialog' ) )
158
+
159
+ const expectedActions = [
160
+ setChangedFile ( { name : 'config' , status : FileChangeType . Added } ) ,
161
+ setPipelineDialogState ( false ) ,
162
+ ]
163
+
164
+ expect ( store . getActions ( ) ) . toEqual ( expectedActions )
165
+ expect ( sendEventTelemetry ) . toBeCalledWith ( {
166
+ event : TelemetryEvent . RDI_START_OPTION_SELECTED ,
167
+ eventData : {
168
+ id : 'rdiInstanceId' ,
169
+ option : PipelineSourceOptions . NEW ,
170
+ } ,
171
+ } )
172
+ } )
173
+
174
+ it ( 'should call proper telemetry event after select empty pipeline option' , ( ) => {
175
+ const sendEventTelemetryMock = jest . fn ( )
176
+ ; ( sendEventTelemetry as jest . Mock ) . mockImplementation (
177
+ ( ) => sendEventTelemetryMock ,
178
+ )
179
+ ; ( appContextPipelineManagement as jest . Mock ) . mockReturnValue ( {
180
+ ...initialStateDefault . app . context . pipelineManagement ,
181
+ isOpenDialog : true ,
182
+ } )
183
+
184
+ render ( < SourcePipelineDialog /> )
185
+
186
+ fireEvent . click ( screen . getByTestId ( 'file-source-pipeline-dialog' ) )
187
+
188
+ expect ( sendEventTelemetry ) . toBeCalledWith ( {
189
+ event : TelemetryEvent . RDI_START_OPTION_SELECTED ,
190
+ eventData : {
191
+ id : 'rdiInstanceId' ,
192
+ option : PipelineSourceOptions . FILE ,
193
+ } ,
194
+ } )
195
+ } )
157
196
} )
158
197
} )
0 commit comments