Skip to content

Commit bf23d42

Browse files
committed
RI-6615 fixed tests and navigation close when switch btw dbs
1 parent a191b4c commit bf23d42

File tree

5 files changed

+103
-42
lines changed

5 files changed

+103
-42
lines changed

redisinsight/ui/src/components/instance-header/components/instances-navigation-popover/InstancesNavigationPopover.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const InstancesNavigationPopover = ({ name }: Props) => {
137137
selectedTab={selectedTab}
138138
filteredDbInstances={filteredDbInstances}
139139
filteredRdiInstances={filteredRdiInstances}
140+
onItemClick={showPopover}
140141
/>
141142
<div>
142143
<EuiSpacer size="m" />

redisinsight/ui/src/components/instance-header/components/instances-navigation-popover/components/instances-list/InstancesList.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ export interface InstancesListProps {
1515
selectedTab: InstancesTabs
1616
filteredDbInstances: Instance[]
1717
filteredRdiInstances: RdiInstance[]
18+
onItemClick: () => void
1819
}
1920

2021
const InstancesList = ({
2122
selectedTab,
2223
filteredDbInstances,
2324
filteredRdiInstances,
25+
onItemClick,
2426
} :InstancesListProps) => {
2527
const [loading, setLoading] = useState<boolean>(false)
2628
const [selected, setSelected] = useState<string>('')
@@ -33,6 +35,7 @@ const InstancesList = ({
3335
const connectToInstance = (id = '') => {
3436
dispatch(setConnectedInstanceId(id))
3537
setLoading(false)
38+
onItemClick?.()
3639
history.push(Pages.browser(id))
3740
}
3841

@@ -65,7 +68,7 @@ const InstancesList = ({
6568
instance.id,
6669
(id: string) => {
6770
setLoading(false)
68-
71+
onItemClick?.()
6972
history.push(Pages.rdiPipelineConfig(id))
7073
},
7174
() => setLoading(false)

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
rdiPipelineSelector,
88
setChangedFile,
99
deleteChangedFile,
10+
setPipelineJobs,
1011
} from 'uiSrc/slices/rdi/pipeline'
1112
import { act, cleanup, fireEvent, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
1213

@@ -63,6 +64,23 @@ describe('Job', () => {
6364
loading: false,
6465
schema: { jobs: { test: {} } },
6566
error: '',
67+
config: `connections:
68+
target:
69+
type: redis
70+
`,
71+
jobs: [{
72+
name: 'jobName',
73+
value: `job:
74+
transform:
75+
type: sql
76+
`
77+
}, {
78+
name: 'job2',
79+
value: `job2:
80+
transform:
81+
type: redis
82+
`
83+
}],
6684
});
6785
(rdiPipelineSelector as jest.Mock).mockImplementation(rdiPipelineSelectorMock)
6886
const pushMock = jest.fn()
@@ -96,6 +114,7 @@ describe('Job', () => {
96114

97115
const expectedActions = [
98116
getPipelineStrategies(),
117+
setPipelineJobs(expect.any(Array)),
99118
]
100119

101120
expect(store.getActions()).toEqual(expectedActions)
@@ -112,6 +131,7 @@ describe('Job', () => {
112131

113132
const expectedActions = [
114133
getPipelineStrategies(),
134+
setPipelineJobs(expect.any(Array)),
115135
setChangedFile({ name: 'jobName', status: FileChangeType.Modified }),
116136
]
117137

@@ -129,6 +149,7 @@ describe('Job', () => {
129149

130150
const expectedActions = [
131151
getPipelineStrategies(),
152+
setPipelineJobs(expect.any(Array)),
132153
deleteChangedFile('jobName')
133154
]
134155

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

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { useFormikContext } from 'formik'
44
import { cloneDeep } from 'lodash'
55
import { AxiosError } from 'axios'
66

7-
import { deleteChangedFile, getPipelineStrategies, rdiPipelineSelector, setChangedFile } from 'uiSrc/slices/rdi/pipeline'
7+
import { deleteChangedFile, getPipelineStrategies, rdiPipelineSelector, setChangedFile, setPipelineJobs } from 'uiSrc/slices/rdi/pipeline'
88
import { cleanup, fireEvent, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
99
import { sendPageViewTelemetry, TelemetryPageView, sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
10-
import { MOCK_RDI_PIPELINE_CONFIG, MOCK_RDI_PIPELINE_DATA, MOCK_RDI_PIPELINE_JOB2 } from 'uiSrc/mocks/data/rdi'
10+
import { MOCK_RDI_PIPELINE_CONFIG, MOCK_RDI_PIPELINE_DATA, MOCK_RDI_PIPELINE_JOB1, MOCK_RDI_PIPELINE_JOB2 } from 'uiSrc/mocks/data/rdi'
1111
import { FileChangeType } from 'uiSrc/slices/interfaces'
1212
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
1313
import JobWrapper from './JobWrapper'
@@ -23,11 +23,26 @@ jest.mock('uiSrc/slices/rdi/pipeline', () => ({
2323
rdiPipelineSelector: jest.fn().mockReturnValue({
2424
loading: false,
2525
schema: { jobs: { test: {} } },
26+
config: `connections:
27+
target:
28+
type: redis
29+
`,
30+
jobs: [{
31+
name: 'jobName',
32+
value: `job:
33+
transform:
34+
type: sql
35+
`
36+
}, {
37+
name: 'job2',
38+
value: `job2:
39+
transform:
40+
type: redis
41+
`
42+
}],
2643
}),
2744
}))
2845

29-
jest.mock('formik')
30-
3146
let store: typeof mockedStore
3247
beforeEach(() => {
3348
cleanup()
@@ -36,14 +51,6 @@ beforeEach(() => {
3651
})
3752

3853
describe('JobWrapper', () => {
39-
beforeEach(() => {
40-
const mockUseFormikContext = {
41-
setFieldValue: jest.fn,
42-
values: MOCK_RDI_PIPELINE_DATA,
43-
};
44-
(useFormikContext as jest.Mock).mockReturnValue(mockUseFormikContext)
45-
})
46-
4754
it('should render', () => {
4855
expect(render(<JobWrapper />)).toBeTruthy()
4956
})
@@ -62,31 +69,16 @@ describe('JobWrapper', () => {
6269
})
6370
})
6471

65-
it('should render loading spinner', () => {
66-
const rdiPipelineSelectorMock = jest.fn().mockReturnValue({
67-
loading: true,
68-
});
69-
(rdiPipelineSelector as jest.Mock).mockImplementation(rdiPipelineSelectorMock)
70-
71-
render(<JobWrapper />)
72-
73-
expect(screen.getByTestId('rdi-job-loading')).toBeInTheDocument()
74-
})
75-
7672
it('should push to config page', () => {
7773
const rdiPipelineSelectorMock = jest.fn().mockReturnValue({
7874
loading: false,
75+
config: MOCK_RDI_PIPELINE_CONFIG,
76+
jobs: [MOCK_RDI_PIPELINE_JOB2],
7977
});
80-
(rdiPipelineSelector as jest.Mock).mockImplementation(rdiPipelineSelectorMock)
78+
(rdiPipelineSelector as jest.Mock).mockImplementationOnce(rdiPipelineSelectorMock)
8179
const pushMock = jest.fn()
8280
reactRouterDom.useHistory = jest.fn().mockReturnValueOnce({ push: pushMock })
8381

84-
const mockUseFormikContext = {
85-
setFieldValue: jest.fn,
86-
values: { config: MOCK_RDI_PIPELINE_CONFIG, jobs: [MOCK_RDI_PIPELINE_JOB2] },
87-
};
88-
(useFormikContext as jest.Mock).mockReturnValueOnce(mockUseFormikContext)
89-
9082
render(<JobWrapper />)
9183

9284
expect(pushMock).toBeCalledWith('/integrate/rdiInstanceId/pipeline-management/config')
@@ -97,7 +89,7 @@ describe('JobWrapper', () => {
9789
loading: false,
9890
error: '',
9991
});
100-
(rdiPipelineSelector as jest.Mock).mockImplementation(rdiPipelineSelectorMock)
92+
(rdiPipelineSelector as jest.Mock).mockImplementationOnce(rdiPipelineSelectorMock)
10193
const pushMock = jest.fn()
10294
reactRouterDom.useHistory = jest.fn().mockReturnValueOnce({ push: pushMock })
10395

@@ -141,9 +133,10 @@ describe('JobWrapper', () => {
141133
const rdiPipelineSelectorMock = jest.fn().mockReturnValue({
142134
loading: false,
143135
schema: { jobs: { test: {} } },
144-
data: { jobs: [{ name: 'jobName', value: 'value' }] }
136+
data: { jobs: [{ name: 'jobName', value: 'value' }] },
137+
jobs: [{ name: 'jobName', value: 'value' }]
145138
});
146-
(rdiPipelineSelector as jest.Mock).mockImplementation(rdiPipelineSelectorMock)
139+
(rdiPipelineSelector as jest.Mock).mockImplementationOnce(rdiPipelineSelectorMock)
147140

148141
render(<JobWrapper />)
149142

@@ -155,6 +148,7 @@ describe('JobWrapper', () => {
155148

156149
const expectedActions = [
157150
getPipelineStrategies(),
151+
setPipelineJobs(expect.any(Array)),
158152
setChangedFile({ name: 'jobName', status: FileChangeType.Modified })
159153
]
160154

@@ -165,7 +159,8 @@ describe('JobWrapper', () => {
165159
const rdiPipelineSelectorMock = jest.fn().mockReturnValue({
166160
loading: false,
167161
schema: { jobs: { test: {} } },
168-
data: { jobs: [{ name: 'jobName', value: '123' }] }
162+
data: { jobs: [{ name: 'jobName', value: '123' }] },
163+
jobs: [{ name: 'jobName' }],
169164
});
170165
(rdiPipelineSelector as jest.Mock).mockImplementation(rdiPipelineSelectorMock)
171166

@@ -179,6 +174,7 @@ describe('JobWrapper', () => {
179174

180175
const expectedActions = [
181176
getPipelineStrategies(),
177+
setPipelineJobs([{ name: 'jobName', value: '123' }]),
182178
deleteChangedFile('jobName')
183179
]
184180

@@ -189,16 +185,12 @@ describe('JobWrapper', () => {
189185
const rdiPipelineSelectorMock = jest.fn().mockReturnValue({
190186
loading: false,
191187
schema: { jobs: { test: {} } },
192-
data: { jobs: [{ name: 'jobName', value: 'sources:incorrect\n target:' }] }
188+
data: { jobs: [{ name: 'jobName', value: 'sources:incorrect\n target:' }] },
189+
config: MOCK_RDI_PIPELINE_CONFIG,
190+
jobs: [{ name: 'jobName', value: 'sources:incorrect\n target:' }]
193191
});
194192
(rdiPipelineSelector as jest.Mock).mockImplementation(rdiPipelineSelectorMock)
195193

196-
const mockUseFormikContext = {
197-
setFieldValue: jest.fn,
198-
values: { config: MOCK_RDI_PIPELINE_CONFIG, jobs: [{ name: 'jobName', value: 'sources:incorrect\n target:' }] },
199-
};
200-
(useFormikContext as jest.Mock).mockReturnValue(mockUseFormikContext)
201-
202194
const { queryByTestId } = render(<JobWrapper />)
203195

204196
fireEvent.click(screen.getByTestId('rdi-job-dry-run'))

redisinsight/ui/src/slices/tests/rdi/pipeline.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import reducer, {
4040
triggerPipelineActionSuccess,
4141
triggerPipelineActionFailure,
4242
rdiPipelineActionSelector,
43+
setPipelineConfig,
44+
setPipelineJobs,
4345
} from 'uiSrc/slices/rdi/pipeline'
4446
import { apiService } from 'uiSrc/services'
4547
import { addErrorNotification, addInfiniteNotification, addMessageNotification } from 'uiSrc/slices/app/notifications'
@@ -119,6 +121,8 @@ describe('rdi pipe slice', () => {
119121
...initialState,
120122
loading: false,
121123
data: MOCK_RDI_PIPELINE_DATA,
124+
config: MOCK_RDI_PIPELINE_DATA.config,
125+
jobs: MOCK_RDI_PIPELINE_DATA.jobs,
122126
}
123127
// Act
124128
const nextState = reducer(initialState, getPipelineSuccess(MOCK_RDI_PIPELINE_DATA))
@@ -133,6 +137,46 @@ describe('rdi pipe slice', () => {
133137
})
134138
})
135139

140+
describe('setPipelineConfig', () => {
141+
it('should properly set state', () => {
142+
// Arrange
143+
const state = {
144+
...initialState,
145+
config: MOCK_RDI_PIPELINE_DATA.config,
146+
}
147+
// Act
148+
const nextState = reducer(initialState, setPipelineConfig(MOCK_RDI_PIPELINE_DATA.config))
149+
150+
// Assert
151+
const rootState = Object.assign(initialStateDefault, {
152+
rdi: {
153+
pipeline: nextState,
154+
}
155+
})
156+
expect(rdiPipelineSelector(rootState)).toEqual(state)
157+
})
158+
})
159+
160+
describe('setPipelineJobs', () => {
161+
it('should properly set state', () => {
162+
// Arrange
163+
const state = {
164+
...initialState,
165+
jobs: MOCK_RDI_PIPELINE_DATA.jobs,
166+
}
167+
// Act
168+
const nextState = reducer(initialState, setPipelineJobs(MOCK_RDI_PIPELINE_DATA.jobs))
169+
170+
// Assert
171+
const rootState = Object.assign(initialStateDefault, {
172+
rdi: {
173+
pipeline: nextState,
174+
}
175+
})
176+
expect(rdiPipelineSelector(rootState)).toEqual(state)
177+
})
178+
})
179+
136180
describe('getPipelineFailure', () => {
137181
it('should properly set state', () => {
138182
// Arrange

0 commit comments

Comments
 (0)