@@ -23,6 +23,8 @@ import type workflowPageQueryParamsConfig from '@/views/workflow-page/config/wor
23
23
import { completedActivityTaskEvents } from '../__fixtures__/workflow-history-activity-events' ;
24
24
import { completedDecisionTaskEvents } from '../__fixtures__/workflow-history-decision-events' ;
25
25
import WorkflowHistory from '../workflow-history' ;
26
+ import { WorkflowHistoryContext } from '../workflow-history-context-provider/workflow-history-context-provider' ;
27
+ import { type WorkflowHistoryEventFilteringType } from '../workflow-history-filters-type/workflow-history-filters-type.types' ;
26
28
27
29
jest . mock ( '@/hooks/use-page-query-params/use-page-query-params' , ( ) =>
28
30
jest . fn ( ( ) => [ { historySelectedEventId : '1' } , jest . fn ( ) ] )
@@ -110,6 +112,10 @@ jest.mock(
110
112
) ;
111
113
112
114
describe ( 'WorkflowHistory' , ( ) => {
115
+ afterEach ( ( ) => {
116
+ jest . restoreAllMocks ( ) ;
117
+ } ) ;
118
+
113
119
it ( 'renders page correctly' , async ( ) => {
114
120
setup ( { } ) ;
115
121
expect ( await screen . findByText ( 'Workflow history' ) ) . toBeInTheDocument ( ) ;
@@ -271,6 +277,56 @@ describe('WorkflowHistory', () => {
271
277
272
278
expect ( screen . getByText ( 'Workflow Actions' ) ) . toBeInTheDocument ( ) ;
273
279
} ) ;
280
+
281
+ it ( 'should override ungrouped view preference when query param is set to true' , async ( ) => {
282
+ await setup ( {
283
+ pageQueryParamsValues : { ungroupedHistoryViewEnabled : true } ,
284
+ ungroupedViewPreference : false ,
285
+ } ) ;
286
+
287
+ // Should show ungrouped table even though preference is false
288
+ expect ( await screen . findByText ( 'Ungrouped Table' ) ) . toBeInTheDocument ( ) ;
289
+ expect ( screen . getByText ( 'Group' ) ) . toBeInTheDocument ( ) ;
290
+ } ) ;
291
+
292
+ it ( 'should use preference when query param is undefined for ungrouped view' , async ( ) => {
293
+ await setup ( {
294
+ pageQueryParamsValues : { ungroupedHistoryViewEnabled : undefined } ,
295
+ ungroupedViewPreference : true ,
296
+ } ) ;
297
+
298
+ // Should use preference (true) when query param is undefined
299
+ expect ( await screen . findByText ( 'Ungrouped Table' ) ) . toBeInTheDocument ( ) ;
300
+ expect ( screen . getByText ( 'Group' ) ) . toBeInTheDocument ( ) ;
301
+ } ) ;
302
+
303
+ it ( 'should override history event types preference when query param is set' , async ( ) => {
304
+ const {
305
+ mockSetUngroupedViewUserPreference,
306
+ mockSetHistoryEventTypesUserPreference,
307
+ } = await setup ( {
308
+ pageQueryParamsValues : {
309
+ historyEventTypes : [ 'TIMER' , 'SIGNAL' ] ,
310
+ ungroupedHistoryViewEnabled : false ,
311
+ } ,
312
+ historyEventTypesPreference : [ 'ACTIVITY' , 'DECISION' ] ,
313
+ } ) ;
314
+
315
+ expect ( mockSetUngroupedViewUserPreference ) . not . toHaveBeenCalled ( ) ;
316
+ expect ( mockSetHistoryEventTypesUserPreference ) . not . toHaveBeenCalled ( ) ;
317
+ } ) ;
318
+
319
+ it ( 'should use preference when history event types query param is undefined' , async ( ) => {
320
+ const { mockSetHistoryEventTypesUserPreference } = await setup ( {
321
+ pageQueryParamsValues : {
322
+ historyEventTypes : undefined ,
323
+ ungroupedHistoryViewEnabled : false ,
324
+ } ,
325
+ historyEventTypesPreference : [ 'TIMER' , 'SIGNAL' ] ,
326
+ } ) ;
327
+
328
+ expect ( mockSetHistoryEventTypesUserPreference ) . not . toHaveBeenCalled ( ) ;
329
+ } ) ;
274
330
} ) ;
275
331
276
332
async function setup ( {
@@ -281,6 +337,8 @@ async function setup({
281
337
hasNextPage,
282
338
emptyEvents,
283
339
withResetModal,
340
+ ungroupedViewPreference,
341
+ historyEventTypesPreference,
284
342
} : {
285
343
error ?: boolean ;
286
344
summaryError ?: boolean ;
@@ -291,6 +349,8 @@ async function setup({
291
349
hasNextPage ?: boolean ;
292
350
emptyEvents ?: boolean ;
293
351
withResetModal ?: boolean ;
352
+ ungroupedViewPreference ?: boolean ;
353
+ historyEventTypesPreference ?: Array < WorkflowHistoryEventFilteringType > ;
294
354
} ) {
295
355
const user = userEvent . setup ( ) ;
296
356
@@ -304,6 +364,10 @@ async function setup({
304
364
} ) ;
305
365
}
306
366
367
+ const mockSetUngroupedViewUserPreference = jest . fn ( ) ;
368
+ const mockSetHistoryEventTypesUserPreference = jest . fn ( ) ;
369
+ const mockClearHistoryEventTypesUserPreference = jest . fn ( ) ;
370
+
307
371
type ReqResolver = ( r : GetWorkflowHistoryResponse ) => void ;
308
372
let requestResolver : ReqResolver = ( ) => { } ;
309
373
let requestRejector = ( ) => { } ;
@@ -313,15 +377,27 @@ async function setup({
313
377
314
378
const renderResult = render (
315
379
< Suspense fallback = { 'Suspense placeholder' } >
316
- < WorkflowHistory
317
- params = { {
318
- domain : 'test-domain' ,
319
- cluster : 'test-cluster' ,
320
- runId : 'test-runid' ,
321
- workflowId : 'test-workflowId' ,
322
- workflowTab : 'history' ,
380
+ < WorkflowHistoryContext . Provider
381
+ value = { {
382
+ ungroupedViewUserPreference : ungroupedViewPreference ?? null ,
383
+ setUngroupedViewUserPreference : mockSetUngroupedViewUserPreference ,
384
+ historyEventTypesUserPreference : historyEventTypesPreference ?? null ,
385
+ setHistoryEventTypesUserPreference :
386
+ mockSetHistoryEventTypesUserPreference ,
387
+ clearHistoryEventTypesUserPreference :
388
+ mockClearHistoryEventTypesUserPreference ,
323
389
} }
324
- />
390
+ >
391
+ < WorkflowHistory
392
+ params = { {
393
+ domain : 'test-domain' ,
394
+ cluster : 'test-cluster' ,
395
+ runId : 'test-runid' ,
396
+ workflowId : 'test-workflowId' ,
397
+ workflowTab : 'history' ,
398
+ } }
399
+ />
400
+ </ WorkflowHistoryContext . Provider >
325
401
</ Suspense > ,
326
402
{
327
403
endpointsMocks : [
@@ -413,5 +489,8 @@ async function setup({
413
489
getRequestRejector,
414
490
...renderResult ,
415
491
mockSetQueryParams,
492
+ mockSetUngroupedViewUserPreference,
493
+ mockSetHistoryEventTypesUserPreference,
494
+ mockClearHistoryEventTypesUserPreference,
416
495
} ;
417
496
}
0 commit comments