@@ -12,13 +12,14 @@ import {
1212 getPipeline ,
1313 rdiPipelineSelector ,
1414 setChangedFile ,
15- setPipeline ,
1615} 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'
1820import { sendEventTelemetry , TelemetryEvent } from 'uiSrc/telemetry'
1921import { FileChangeType } from 'uiSrc/slices/interfaces'
2022import SourcePipelineDialog , {
21- EMPTY_PIPELINE ,
2223 PipelineSourceOptions ,
2324} from './SourcePipelineModal'
2425
@@ -42,117 +43,155 @@ jest.mock('uiSrc/slices/rdi/pipeline', () => ({
4243 rdiPipelineSelector : jest . fn ( ) ,
4344} ) )
4445
46+ jest . mock ( 'uiSrc/slices/app/context' , ( ) => ( {
47+ ...jest . requireActual ( 'uiSrc/slices/app/context' ) ,
48+ appContextPipelineManagement : jest . fn ( ) ,
49+ } ) )
50+
4551let store : typeof mockedStore
4652beforeEach ( ( ) => {
4753 cleanup ( )
4854 store = cloneDeep ( mockedStore )
4955 store . clearActions ( )
5056 ; ( rdiPipelineSelector as jest . Mock ) . mockReturnValue ( {
5157 ...initialStateDefault . rdi . pipeline ,
52- loading : false ,
53- config : '' ,
58+ } )
59+ ; ( appContextPipelineManagement as jest . Mock ) . mockReturnValue ( {
60+ ...initialStateDefault . app . context . pipelineManagement ,
5461 } )
5562} )
5663
5764describe ( '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' , ( ) => {
6866 render ( < SourcePipelineDialog /> )
6967
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 ( )
7371
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 ( [ ] )
8273 } )
8374
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 ,
10679 } )
107- } )
10880
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- )
11481 render ( < SourcePipelineDialog /> )
11582
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 ( )
12586 } )
12687
12788 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- )
13289 ; ( rdiPipelineSelector as jest . Mock ) . mockReturnValue ( {
13390 ...initialStateDefault . rdi . pipeline ,
13491 loading : false ,
135- config : 'deployed config' ,
92+ data : { config : 'some config' } ,
13693 } )
13794
13895 render ( < SourcePipelineDialog /> )
13996
140- expect ( screen . queryByTestId ( 'file-source-pipeline-dialog' ) ) . not . toBeInTheDocument ( )
97+ expect ( store . getActions ( ) ) . toEqual ( [ ] )
14198 } )
14299
143100 it ( 'should not show dialog when config is fetching' , ( ) => {
144- const sendEventTelemetryMock = jest . fn ( )
145- ; ( sendEventTelemetry as jest . Mock ) . mockImplementation (
146- ( ) => sendEventTelemetryMock ,
147- )
148101 ; ( rdiPipelineSelector as jest . Mock ) . mockReturnValue ( {
149102 ...initialStateDefault . rdi . pipeline ,
150103 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 : '' } ,
152117 } )
153118
154119 render ( < SourcePipelineDialog /> )
155120
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+ } )
157196 } )
158197} )
0 commit comments