Skip to content

Commit 3f186b3

Browse files
RI-7730: keep progress when user navigated out of RDI management page (#5187)
1 parent e51cbb7 commit 3f186b3

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

redisinsight/ui/src/pages/rdi/pipeline-management/PipelineManagementPage.spec.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
cleanup,
99
mockedStore,
1010
createMockedStore,
11+
expectActionsToContain,
12+
expectActionsToNotContain,
1113
} from 'uiSrc/utils/test-utils'
1214
import {
1315
appContextPipelineManagement,
@@ -30,6 +32,9 @@ jest.mock('uiSrc/slices/app/context', () => ({
3032

3133
jest.mock('formik')
3234

35+
const MOCK_RDI_ID = 'id1'
36+
const MOCK_RDI_ID2 = 'id2'
37+
3338
let store: typeof mockedStore
3439
beforeEach(() => {
3540
cleanup()
@@ -103,4 +108,45 @@ describe('PipelineManagementPage', () => {
103108
expectedActions,
104109
)
105110
})
111+
112+
describe('pipeline state', () => {
113+
it('should fetch pipeline when context is empty', () => {
114+
;(appContextPipelineManagement as jest.Mock).mockReturnValueOnce({
115+
lastViewedPage: '',
116+
})
117+
reactRouterDom.useParams = jest.fn().mockReturnValue({
118+
rdiInstanceId: MOCK_RDI_ID,
119+
})
120+
121+
renderPipelineManagement(instance(mockedProps))
122+
123+
expectActionsToContain(store.getActions(), [getPipeline()])
124+
})
125+
126+
it('should fetch pipeline when context stores different visited RDI instance', () => {
127+
;(appContextPipelineManagement as jest.Mock).mockReturnValueOnce({
128+
lastViewedPage: '',
129+
})
130+
reactRouterDom.useParams = jest.fn().mockReturnValue({
131+
rdiInstanceId: MOCK_RDI_ID2,
132+
})
133+
134+
renderPipelineManagement(instance(mockedProps))
135+
136+
expectActionsToContain(store.getActions(), [getPipeline()])
137+
})
138+
139+
it('should not fetch pipeline when context stores the same visited RDI instance', () => {
140+
;(appContextPipelineManagement as jest.Mock).mockReturnValueOnce({
141+
lastViewedPage: Pages.rdiPipelineConfig(MOCK_RDI_ID),
142+
})
143+
reactRouterDom.useParams = jest.fn().mockReturnValue({
144+
rdiInstanceId: MOCK_RDI_ID,
145+
})
146+
147+
renderPipelineManagement(instance(mockedProps))
148+
149+
expectActionsToNotContain(store.getActions(), [getPipeline()])
150+
})
151+
})
106152
})

redisinsight/ui/src/pages/rdi/pipeline-management/PipelineManagementPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ const PipelineManagementPage = ({ routes = [] }: Props) => {
4444
setTitle(`${rdiInstanceName} - Pipeline Management`)
4545

4646
useEffect(() => {
47-
dispatch(fetchRdiPipeline(rdiInstanceId))
47+
if (!lastViewedPage?.startsWith(Pages.rdiPipelineManagement(rdiInstanceId))) {
48+
dispatch(fetchRdiPipeline(rdiInstanceId))
49+
}
4850
dispatch(fetchRdiPipelineSchema(rdiInstanceId))
4951
dispatch(fetchRdiPipelineJobFunctions(rdiInstanceId))
5052
}, [])

redisinsight/ui/src/utils/test-utils.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,18 @@ const expectActionsToContain = (
459459
expect(actualActions).toEqual(expect.arrayContaining(expectedActions))
460460
}
461461

462+
/**
463+
* Helper function to check if actions are not contained within actual store actions
464+
* @param actualActions - The actual actions dispatched to the store
465+
* @param expectedActions - The expected actions that should not be presented
466+
*/
467+
const expectActionsToNotContain = (
468+
actualActions: any[],
469+
expectedActions: any[],
470+
) => {
471+
expect(actualActions).not.toEqual(expect.arrayContaining(expectedActions))
472+
}
473+
462474
// re-export everything
463475
export * from '@testing-library/react'
464476
// override render method
@@ -473,4 +485,5 @@ export {
473485
waitForRiTooltipHidden,
474486
waitForRiPopoverVisible,
475487
expectActionsToContain,
488+
expectActionsToNotContain,
476489
}

0 commit comments

Comments
 (0)