From e143c85e478cc0c7949a39d37a0c51f75a603a68 Mon Sep 17 00:00:00 2001 From: ArtemHoruzhenko Date: Fri, 14 Nov 2025 09:46:58 +0200 Subject: [PATCH] RI-7730: keep progress when user navigated out of RDI management page --- .../PipelineManagementPage.spec.tsx | 46 +++++++++++++++++++ .../PipelineManagementPage.tsx | 4 +- redisinsight/ui/src/utils/test-utils.tsx | 13 ++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/redisinsight/ui/src/pages/rdi/pipeline-management/PipelineManagementPage.spec.tsx b/redisinsight/ui/src/pages/rdi/pipeline-management/PipelineManagementPage.spec.tsx index f4a7524479..cf61d268b5 100644 --- a/redisinsight/ui/src/pages/rdi/pipeline-management/PipelineManagementPage.spec.tsx +++ b/redisinsight/ui/src/pages/rdi/pipeline-management/PipelineManagementPage.spec.tsx @@ -8,6 +8,8 @@ import { cleanup, mockedStore, createMockedStore, + expectActionsToContain, + expectActionsToNotContain, } from 'uiSrc/utils/test-utils' import { appContextPipelineManagement, @@ -30,6 +32,9 @@ jest.mock('uiSrc/slices/app/context', () => ({ jest.mock('formik') +const MOCK_RDI_ID = 'id1' +const MOCK_RDI_ID2 = 'id2' + let store: typeof mockedStore beforeEach(() => { cleanup() @@ -103,4 +108,45 @@ describe('PipelineManagementPage', () => { expectedActions, ) }) + + describe('pipeline state', () => { + it('should fetch pipeline when context is empty', () => { + ;(appContextPipelineManagement as jest.Mock).mockReturnValueOnce({ + lastViewedPage: '', + }) + reactRouterDom.useParams = jest.fn().mockReturnValue({ + rdiInstanceId: MOCK_RDI_ID, + }) + + renderPipelineManagement(instance(mockedProps)) + + expectActionsToContain(store.getActions(), [getPipeline()]) + }) + + it('should fetch pipeline when context stores different visited RDI instance', () => { + ;(appContextPipelineManagement as jest.Mock).mockReturnValueOnce({ + lastViewedPage: '', + }) + reactRouterDom.useParams = jest.fn().mockReturnValue({ + rdiInstanceId: MOCK_RDI_ID2, + }) + + renderPipelineManagement(instance(mockedProps)) + + expectActionsToContain(store.getActions(), [getPipeline()]) + }) + + it('should not fetch pipeline when context stores the same visited RDI instance', () => { + ;(appContextPipelineManagement as jest.Mock).mockReturnValueOnce({ + lastViewedPage: Pages.rdiPipelineConfig(MOCK_RDI_ID), + }) + reactRouterDom.useParams = jest.fn().mockReturnValue({ + rdiInstanceId: MOCK_RDI_ID, + }) + + renderPipelineManagement(instance(mockedProps)) + + expectActionsToNotContain(store.getActions(), [getPipeline()]) + }) + }) }) diff --git a/redisinsight/ui/src/pages/rdi/pipeline-management/PipelineManagementPage.tsx b/redisinsight/ui/src/pages/rdi/pipeline-management/PipelineManagementPage.tsx index de2b8080e1..d944cd35d5 100644 --- a/redisinsight/ui/src/pages/rdi/pipeline-management/PipelineManagementPage.tsx +++ b/redisinsight/ui/src/pages/rdi/pipeline-management/PipelineManagementPage.tsx @@ -44,7 +44,9 @@ const PipelineManagementPage = ({ routes = [] }: Props) => { setTitle(`${rdiInstanceName} - Pipeline Management`) useEffect(() => { - dispatch(fetchRdiPipeline(rdiInstanceId)) + if (!lastViewedPage?.startsWith(Pages.rdiPipelineManagement(rdiInstanceId))) { + dispatch(fetchRdiPipeline(rdiInstanceId)) + } dispatch(fetchRdiPipelineSchema(rdiInstanceId)) dispatch(fetchRdiPipelineJobFunctions(rdiInstanceId)) }, []) diff --git a/redisinsight/ui/src/utils/test-utils.tsx b/redisinsight/ui/src/utils/test-utils.tsx index 1ca593cab0..ef5accd8d6 100644 --- a/redisinsight/ui/src/utils/test-utils.tsx +++ b/redisinsight/ui/src/utils/test-utils.tsx @@ -459,6 +459,18 @@ const expectActionsToContain = ( expect(actualActions).toEqual(expect.arrayContaining(expectedActions)) } +/** + * Helper function to check if actions are not contained within actual store actions + * @param actualActions - The actual actions dispatched to the store + * @param expectedActions - The expected actions that should not be presented + */ +const expectActionsToNotContain = ( + actualActions: any[], + expectedActions: any[], +) => { + expect(actualActions).not.toEqual(expect.arrayContaining(expectedActions)) +} + // re-export everything export * from '@testing-library/react' // override render method @@ -473,4 +485,5 @@ export { waitForRiTooltipHidden, waitForRiPopoverVisible, expectActionsToContain, + expectActionsToNotContain, }