@@ -23,6 +23,8 @@ import type workflowPageQueryParamsConfig from '@/views/workflow-page/config/wor
2323import { completedActivityTaskEvents } from '../__fixtures__/workflow-history-activity-events' ;
2424import { completedDecisionTaskEvents } from '../__fixtures__/workflow-history-decision-events' ;
2525import 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' ;
2628
2729jest . mock ( '@/hooks/use-page-query-params/use-page-query-params' , ( ) =>
2830 jest . fn ( ( ) => [ { historySelectedEventId : '1' } , jest . fn ( ) ] )
@@ -110,6 +112,10 @@ jest.mock(
110112) ;
111113
112114describe ( 'WorkflowHistory' , ( ) => {
115+ afterEach ( ( ) => {
116+ jest . restoreAllMocks ( ) ;
117+ } ) ;
118+
113119 it ( 'renders page correctly' , async ( ) => {
114120 setup ( { } ) ;
115121 expect ( await screen . findByText ( 'Workflow history' ) ) . toBeInTheDocument ( ) ;
@@ -271,6 +277,56 @@ describe('WorkflowHistory', () => {
271277
272278 expect ( screen . getByText ( 'Workflow Actions' ) ) . toBeInTheDocument ( ) ;
273279 } ) ;
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+ } ) ;
274330} ) ;
275331
276332async function setup ( {
@@ -281,6 +337,8 @@ async function setup({
281337 hasNextPage,
282338 emptyEvents,
283339 withResetModal,
340+ ungroupedViewPreference,
341+ historyEventTypesPreference,
284342} : {
285343 error ?: boolean ;
286344 summaryError ?: boolean ;
@@ -291,6 +349,8 @@ async function setup({
291349 hasNextPage ?: boolean ;
292350 emptyEvents ?: boolean ;
293351 withResetModal ?: boolean ;
352+ ungroupedViewPreference ?: boolean ;
353+ historyEventTypesPreference ?: Array < WorkflowHistoryEventFilteringType > ;
294354} ) {
295355 const user = userEvent . setup ( ) ;
296356
@@ -304,6 +364,10 @@ async function setup({
304364 } ) ;
305365 }
306366
367+ const mockSetUngroupedViewUserPreference = jest . fn ( ) ;
368+ const mockSetHistoryEventTypesUserPreference = jest . fn ( ) ;
369+ const mockClearHistoryEventTypesUserPreference = jest . fn ( ) ;
370+
307371 type ReqResolver = ( r : GetWorkflowHistoryResponse ) => void ;
308372 let requestResolver : ReqResolver = ( ) => { } ;
309373 let requestRejector = ( ) => { } ;
@@ -313,15 +377,27 @@ async function setup({
313377
314378 const renderResult = render (
315379 < 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 ,
323389 } }
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 >
325401 </ Suspense > ,
326402 {
327403 endpointsMocks : [
@@ -413,5 +489,8 @@ async function setup({
413489 getRequestRejector,
414490 ...renderResult ,
415491 mockSetQueryParams,
492+ mockSetUngroupedViewUserPreference,
493+ mockSetHistoryEventTypesUserPreference,
494+ mockClearHistoryEventTypesUserPreference,
416495 } ;
417496}
0 commit comments