1
1
import React from 'react' ;
2
2
3
+ import { HttpResponse } from 'msw' ;
3
4
import { type FieldErrors , useForm } from 'react-hook-form' ;
4
5
5
6
import { render , screen , userEvent } from '@/test-utils/rtl' ;
6
7
8
+ import { type ResetPoints } from '@/__generated__/proto-ts/uber/cadence/api/v1/ResetPoints' ;
9
+ import { mockDescribeWorkflowResponse } from '@/views/workflow-page/__fixtures__/describe-workflow-response' ;
10
+
7
11
import WorkflowActionResetForm from '../workflow-action-reset-form' ;
8
12
import { type ResetWorkflowFormData } from '../workflow-action-reset-form.types' ;
9
13
14
+ const resetPoints = {
15
+ points : [
16
+ {
17
+ binaryChecksum : 'test-binary-checksum' ,
18
+ runId : 'test-run-id' ,
19
+ firstDecisionCompletedId : '4' ,
20
+ resettable : false ,
21
+ createdTime : null ,
22
+ expiringTime : null ,
23
+ } ,
24
+ {
25
+ binaryChecksum : 'test-binary-checksum-2' ,
26
+ runId : 'test-run-id' ,
27
+ firstDecisionCompletedId : '7' ,
28
+ resettable : true ,
29
+ createdTime : null ,
30
+ expiringTime : null ,
31
+ } ,
32
+ {
33
+ binaryChecksum : 'test-binary-checksum-3' ,
34
+ runId : 'test-run-id' ,
35
+ firstDecisionCompletedId : '10' ,
36
+ resettable : true ,
37
+ createdTime : null ,
38
+ expiringTime : null ,
39
+ } ,
40
+ ] ,
41
+ } ;
10
42
describe ( 'WorkflowActionResetForm' , ( ) => {
11
43
it ( 'renders all form fields correctly' , async ( ) => {
12
44
await setup ( { } ) ;
@@ -68,6 +100,84 @@ describe('WorkflowActionResetForm', () => {
68
100
} ) ;
69
101
expect ( skipSignalCheckbox ) . not . toBeChecked ( ) ;
70
102
} ) ;
103
+
104
+ it ( 'switches between Event ID and Binary Checksum reset types' , async ( ) => {
105
+ const { user } = await setup ( { } ) ;
106
+
107
+ const binaryChecksumRadio = screen . getByRole ( 'radio' , {
108
+ name : 'Binary Checksum' ,
109
+ } ) ;
110
+ await user . click ( binaryChecksumRadio ) ;
111
+
112
+ expect (
113
+ screen . queryByPlaceholderText ( 'Find Event ID' )
114
+ ) . not . toBeInTheDocument ( ) ;
115
+ expect ( screen . getByText ( 'Select binary checksum' ) ) . toBeInTheDocument ( ) ;
116
+
117
+ const eventIdRadio = screen . getByRole ( 'radio' , {
118
+ name : 'Event ID' ,
119
+ } ) ;
120
+ await user . click ( eventIdRadio ) ;
121
+
122
+ expect ( screen . getByPlaceholderText ( 'Find Event ID' ) ) . toBeInTheDocument ( ) ;
123
+ expect (
124
+ screen . queryByText ( 'Select binary checksum' )
125
+ ) . not . toBeInTheDocument ( ) ;
126
+ } ) ;
127
+
128
+ it ( 'lists only resettable points' , async ( ) => {
129
+ const { user } = await setup ( { resetPoints } ) ;
130
+
131
+ const binaryChecksumRadio = screen . getByRole ( 'radio' , {
132
+ name : 'Binary Checksum' ,
133
+ } ) ;
134
+ await user . click ( binaryChecksumRadio ) ;
135
+
136
+ const binaryChecksumSelect = screen . getByRole ( 'combobox' , {
137
+ name : 'Select binary checksum' ,
138
+ } ) ;
139
+ await user . click ( binaryChecksumSelect ) ;
140
+
141
+ expect ( ( await screen . findAllByRole ( 'option' ) ) . length ) . toBe ( 2 ) ;
142
+ expect ( screen . getByText ( 'test-binary-checksum-2' ) ) . toBeInTheDocument ( ) ;
143
+ expect ( screen . getByText ( 'test-binary-checksum-3' ) ) . toBeInTheDocument ( ) ;
144
+ } ) ;
145
+
146
+ it ( 'handles error state for bad binary fetch' , async ( ) => {
147
+ const { user } = await setup ( { isError : true } ) ;
148
+
149
+ const binaryChecksumRadio = screen . getByRole ( 'radio' , {
150
+ name : 'Binary Checksum' ,
151
+ } ) ;
152
+ await user . click ( binaryChecksumRadio ) ;
153
+
154
+ const binaryChecksumSelect = screen . getByRole ( 'combobox' , {
155
+ name : 'Select binary checksum' ,
156
+ } ) ;
157
+
158
+ await user . click ( binaryChecksumSelect ) ;
159
+
160
+ expect (
161
+ await screen . findByText ( 'Failed to load binary checksums' )
162
+ ) . toBeInTheDocument ( ) ;
163
+ } ) ;
164
+
165
+ it ( 'handles empty state' , async ( ) => {
166
+ const { user } = await setup ( { resetPoints : { points : [ ] } } ) ;
167
+
168
+ const binaryChecksumRadio = screen . getByRole ( 'radio' , {
169
+ name : 'Binary Checksum' ,
170
+ } ) ;
171
+ await user . click ( binaryChecksumRadio ) ;
172
+
173
+ const binaryChecksumSelect = screen . getByRole ( 'combobox' , {
174
+ name : 'Select binary checksum' ,
175
+ } ) ;
176
+
177
+ await user . click ( binaryChecksumSelect ) ;
178
+
179
+ expect ( await screen . findByText ( 'No results found' ) ) . toBeInTheDocument ( ) ;
180
+ } ) ;
71
181
} ) ;
72
182
73
183
type TestProps = {
@@ -83,6 +193,7 @@ function TestWrapper({ formErrors, formData }: TestProps) {
83
193
return (
84
194
< WorkflowActionResetForm
85
195
control = { methods . control }
196
+ clearErrors = { methods . clearErrors }
86
197
fieldErrors = { formErrors }
87
198
formData = { formData }
88
199
cluster = "test-cluster"
@@ -99,11 +210,41 @@ async function setup({
99
210
decisionFinishEventId : '' ,
100
211
reason : '' ,
101
212
skipSignalReapply : false ,
213
+ resetType : 'EventId' ,
102
214
} ,
103
- } : Partial < TestProps > ) {
215
+ resetPoints = mockDescribeWorkflowResponse . workflowExecutionInfo
216
+ . autoResetPoints ,
217
+ isError = false ,
218
+ } : Partial < TestProps > & { resetPoints ?: ResetPoints ; isError ?: boolean } ) {
104
219
const user = userEvent . setup ( ) ;
105
220
106
- render ( < TestWrapper formErrors = { formErrors } formData = { formData } /> ) ;
221
+ const describeWorkflowResponse = {
222
+ ...mockDescribeWorkflowResponse ,
223
+ workflowExecutionInfo : {
224
+ ...mockDescribeWorkflowResponse . workflowExecutionInfo ,
225
+ autoResetPoints : resetPoints ,
226
+ } ,
227
+ } ;
228
+ render ( < TestWrapper formErrors = { formErrors } formData = { formData } /> , {
229
+ endpointsMocks : [
230
+ {
231
+ path : '/api/domains/:domain/:cluster/workflows/:workflowId/:runId' ,
232
+ httpMethod : 'GET' ,
233
+ httpResolver : ( ) => {
234
+ if ( isError ) {
235
+ return HttpResponse . json (
236
+ { message : 'Failed to fetch workflow summary' } ,
237
+ { status : 500 }
238
+ ) ;
239
+ } else {
240
+ return HttpResponse . json ( describeWorkflowResponse , {
241
+ status : 200 ,
242
+ } ) ;
243
+ }
244
+ } ,
245
+ } ,
246
+ ] ,
247
+ } ) ;
107
248
108
249
return { user } ;
109
250
}
0 commit comments