@@ -12,10 +12,13 @@ import {
12
12
waitForElementToBeRemoved ,
13
13
} from '@/test-utils/rtl' ;
14
14
15
+ import { type HistoryEvent } from '@/__generated__/proto-ts/uber/cadence/api/v1/HistoryEvent' ;
15
16
import * as usePageFiltersModule from '@/components/page-filters/hooks/use-page-filters' ;
16
17
import { type Props as PageFiltersToggleProps } from '@/components/page-filters/page-filters-toggle/page-filters-toggle.types' ;
18
+ import { type PageQueryParamValues } from '@/hooks/use-page-query-params/use-page-query-params.types' ;
17
19
import { type GetWorkflowHistoryResponse } from '@/route-handlers/get-workflow-history/get-workflow-history.types' ;
18
20
import { mockDescribeWorkflowResponse } from '@/views/workflow-page/__fixtures__/describe-workflow-response' ;
21
+ import type workflowPageQueryParamsConfig from '@/views/workflow-page/config/workflow-page-query-params.config' ;
19
22
20
23
import { completedActivityTaskEvents } from '../__fixtures__/workflow-history-activity-events' ;
21
24
import { completedDecisionTaskEvents } from '../__fixtures__/workflow-history-decision-events' ;
@@ -32,7 +35,13 @@ jest.mock(
32
35
33
36
jest . mock (
34
37
'../workflow-history-timeline-group/workflow-history-timeline-group' ,
35
- ( ) => jest . fn ( ( ) => < div > Timeline group card</ div > )
38
+ ( ) =>
39
+ jest . fn ( ( { onReset, resetToDecisionEventId } ) => (
40
+ < div >
41
+ Timeline group card
42
+ { resetToDecisionEventId && < button onClick = { onReset } > Reset</ button > }
43
+ </ div >
44
+ ) )
36
45
) ;
37
46
38
47
jest . mock (
@@ -69,6 +78,37 @@ jest.mock(
69
78
( ) => jest . fn ( ( ) => < div > keep loading events</ div > )
70
79
) ;
71
80
81
+ jest . mock (
82
+ '../workflow-history-expand-all-events-button/workflow-history-expand-all-events-button' ,
83
+ ( ) =>
84
+ jest . fn ( ( { isExpandAllEvents, toggleIsExpandAllEvents } ) => (
85
+ < button onClick = { toggleIsExpandAllEvents } >
86
+ { isExpandAllEvents ? 'Collapse All' : 'Expand All' }
87
+ </ button >
88
+ ) )
89
+ ) ;
90
+
91
+ jest . mock (
92
+ '../workflow-history-export-json-button/workflow-history-export-json-button' ,
93
+ ( ) => jest . fn ( ( ) => < button > Export JSON</ button > )
94
+ ) ;
95
+
96
+ jest . mock (
97
+ '../workflow-history-ungrouped-table/workflow-history-ungrouped-table' ,
98
+ ( ) => jest . fn ( ( ) => < div > Ungrouped Table</ div > )
99
+ ) ;
100
+
101
+ jest . mock (
102
+ '@/views/workflow-actions/workflow-actions-modal/workflow-actions-modal' ,
103
+ ( ) =>
104
+ jest . fn ( ( { onClose } ) => (
105
+ < div >
106
+ < div > Workflow Actions</ div >
107
+ < button onClick = { onClose } > Close</ button >
108
+ </ div >
109
+ ) )
110
+ ) ;
111
+
72
112
describe ( 'WorkflowHistory' , ( ) => {
73
113
it ( 'renders page correctly' , async ( ) => {
74
114
setup ( { } ) ;
@@ -180,6 +220,57 @@ describe('WorkflowHistory', () => {
180
220
expect ( screen . queryByText ( 'keep loading events' ) ) . not . toBeInTheDocument ( ) ;
181
221
} ) ;
182
222
} ) ;
223
+
224
+ it ( 'should show no results when filtered events are empty' , async ( ) => {
225
+ setup ( { emptyEvents : true } ) ;
226
+ expect ( await screen . findByText ( 'No Results' ) ) . toBeInTheDocument ( ) ;
227
+ } ) ;
228
+
229
+ it ( 'should render expand all events button' , async ( ) => {
230
+ setup ( { } ) ;
231
+ expect ( await screen . findByText ( 'Expand All' ) ) . toBeInTheDocument ( ) ;
232
+ } ) ;
233
+
234
+ it ( 'should render export JSON button' , async ( ) => {
235
+ setup ( { } ) ;
236
+ expect ( await screen . findByText ( 'Export JSON' ) ) . toBeInTheDocument ( ) ;
237
+ } ) ;
238
+
239
+ it ( 'should show "Ungroup" button in grouped view and call setQueryParams when clicked' , async ( ) => {
240
+ const { user, mockSetQueryParams } = await setup ( {
241
+ pageQueryParamsValues : { ungroupedHistoryViewEnabled : false } ,
242
+ } ) ;
243
+
244
+ const ungroupButton = await screen . findByText ( 'Ungroup' ) ;
245
+ expect ( ungroupButton ) . toBeInTheDocument ( ) ;
246
+
247
+ await user . click ( ungroupButton ) ;
248
+ expect ( mockSetQueryParams ) . toHaveBeenCalledWith ( {
249
+ ungroupedHistoryViewEnabled : 'true' ,
250
+ } ) ;
251
+ } ) ;
252
+
253
+ it ( 'should show "Group" button when in ungrouped view' , async ( ) => {
254
+ await setup ( {
255
+ pageQueryParamsValues : { ungroupedHistoryViewEnabled : true } ,
256
+ } ) ;
257
+
258
+ expect ( await screen . findByText ( 'Group' ) ) . toBeInTheDocument ( ) ;
259
+ } ) ;
260
+
261
+ it ( 'should show ungrouped table when ungrouped view is enabled' , async ( ) => {
262
+ setup ( { pageQueryParamsValues : { ungroupedHistoryViewEnabled : true } } ) ;
263
+ expect ( await screen . findByText ( 'Ungrouped Table' ) ) . toBeInTheDocument ( ) ;
264
+ } ) ;
265
+
266
+ it ( 'should show workflow actions modal when resetToDecisionEventId is set' , async ( ) => {
267
+ const { user } = await setup ( { withResetModal : true } ) ;
268
+
269
+ const resetButton = await screen . findByText ( 'Reset' ) ;
270
+ await user . click ( resetButton ) ;
271
+
272
+ expect ( screen . getByText ( 'Workflow Actions' ) ) . toBeInTheDocument ( ) ;
273
+ } ) ;
183
274
} ) ;
184
275
185
276
async function setup ( {
@@ -188,19 +279,26 @@ async function setup({
188
279
resolveLoadMoreManually,
189
280
pageQueryParamsValues = { } ,
190
281
hasNextPage,
282
+ emptyEvents,
283
+ withResetModal,
191
284
} : {
192
285
error ?: boolean ;
193
286
summaryError ?: boolean ;
194
287
resolveLoadMoreManually ?: boolean ;
195
- pageQueryParamsValues ?: Record < string , string > ;
288
+ pageQueryParamsValues ?: Partial <
289
+ PageQueryParamValues < typeof workflowPageQueryParamsConfig >
290
+ > ;
196
291
hasNextPage ?: boolean ;
292
+ emptyEvents ?: boolean ;
293
+ withResetModal ?: boolean ;
197
294
} ) {
198
295
const user = userEvent . setup ( ) ;
199
296
297
+ const mockSetQueryParams = jest . fn ( ) ;
200
298
if ( pageQueryParamsValues ) {
201
299
jest . spyOn ( usePageFiltersModule , 'default' ) . mockReturnValue ( {
202
300
queryParams : pageQueryParamsValues ,
203
- setQueryParams : jest . fn ( ) ,
301
+ setQueryParams : mockSetQueryParams ,
204
302
activeFiltersCount : 0 ,
205
303
resetAllFilters : jest . fn ( ) ,
206
304
} ) ;
@@ -255,10 +353,17 @@ async function setup({
255
353
) ;
256
354
}
257
355
356
+ let events : Array < HistoryEvent > = completedActivityTaskEvents ;
357
+ if ( emptyEvents ) {
358
+ events = [ ] ;
359
+ } else if ( withResetModal ) {
360
+ events = completedDecisionTaskEvents ;
361
+ }
362
+
258
363
return HttpResponse . json (
259
364
{
260
365
history : {
261
- events : completedActivityTaskEvents ,
366
+ events,
262
367
} ,
263
368
archived : false ,
264
369
nextPageToken : hasNextPage ? 'mock-next-page-token' : '' ,
@@ -302,5 +407,11 @@ async function setup({
302
407
screen . queryAllByText ( 'Suspense placeholder' )
303
408
) ;
304
409
305
- return { user, getRequestResolver, getRequestRejector, ...renderResult } ;
410
+ return {
411
+ user,
412
+ getRequestResolver,
413
+ getRequestRejector,
414
+ ...renderResult ,
415
+ mockSetQueryParams,
416
+ } ;
306
417
}
0 commit comments