Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
cleanup,
mockedStore,
createMockedStore,
expectActionsToContain,
expectActionsToNotContain,
} from 'uiSrc/utils/test-utils'
import {
appContextPipelineManagement,
Expand All @@ -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()
Expand Down Expand Up @@ -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()])
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}, [])
Expand Down
13 changes: 13 additions & 0 deletions redisinsight/ui/src/utils/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -473,4 +485,5 @@ export {
waitForRiTooltipHidden,
waitForRiPopoverVisible,
expectActionsToContain,
expectActionsToNotContain,
}
Loading