Skip to content

Commit 8f8ef39

Browse files
committed
Truncate certificate name and add delete client cert UI tests
1 parent 3b85566 commit 8f8ef39

File tree

2 files changed

+132
-2
lines changed

2 files changed

+132
-2
lines changed

redisinsight/ui/src/pages/home/components/form/TlsDetails.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const TlsDetails = (props: Props) => {
8383
inputDisplay: cert.name,
8484
dropdownDisplay: (
8585
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
86-
<div>{cert.name}</div>
86+
<div>{truncateText(cert.name, 25)}</div>
8787
<PopoverDelete
8888
header={cert.name}
8989
text="will be deleted from RedisInsight."
@@ -114,7 +114,7 @@ const TlsDetails = (props: Props) => {
114114
inputDisplay: cert.name,
115115
dropdownDisplay: (
116116
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
117-
<div>{cert.name}</div>
117+
<div>{truncateText(cert.name, 25)}</div>
118118
<PopoverDelete
119119
header={cert.name}
120120
text="will be deleted from RedisInsight."

redisinsight/ui/src/slices/tests/instances/clientCerts.spec.ts

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { AxiosError } from 'axios'
12
import { cloneDeep } from 'lodash'
23
import { apiService } from 'uiSrc/services'
4+
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
35
import { initialStateDefault, mockedStore } from 'uiSrc/utils/test-utils'
46
import reducer, {
57
initialState,
@@ -28,6 +30,26 @@ describe('clientCerts slice', () => {
2830
})
2931
})
3032

33+
describe('deleteClientCert', () => {
34+
it('should properly set loading = true', () => {
35+
// Arrange
36+
const state = {
37+
...initialState,
38+
loading: true,
39+
}
40+
41+
// Act
42+
const nextState = reducer(initialState, deleteClientCert())
43+
44+
const rootState = Object.assign(initialStateDefault, {
45+
connections: {
46+
clientCerts: nextState,
47+
},
48+
})
49+
expect(clientCertsSelector(rootState)).toEqual(state)
50+
})
51+
}
52+
3153
describe('loadClientCerts', () => {
3254
it('should properly set the state before the fetch data', () => {
3355
// Arrange
@@ -49,6 +71,27 @@ describe('clientCerts slice', () => {
4971
})
5072
})
5173

74+
describe('deleteClientCertSuccess', () => {
75+
it('should properly set the state with fetched data', () => {
76+
// Arrange
77+
const state = {
78+
...initialState,
79+
loading: false,
80+
}
81+
82+
// Act
83+
const nextState = reducer(initialState, deleteClientCertSuccess())
84+
85+
// Assert
86+
const rootState = Object.assign(initialStateDefault, {
87+
connections: {
88+
clientCerts: nextState,
89+
},
90+
})
91+
expect(clientCertsSelector(rootState)).toEqual(state)
92+
})
93+
}
94+
5295
describe('loadClientCertsSuccess', () => {
5396
it('should properly set the state with fetched data', () => {
5497
// Arrange
@@ -97,6 +140,30 @@ describe('clientCerts slice', () => {
97140
})
98141
})
99142

143+
describe('deleteClientCertFailure', () => {
144+
it('should properly set the error', () => {
145+
// Arrange
146+
const data = 'some error'
147+
const state = {
148+
...initialState,
149+
loading: false,
150+
error: data,
151+
data: [],
152+
}
153+
154+
// Act
155+
const nextState = reducer(initialState, deleteClientCertFailure(data))
156+
157+
// Assert
158+
const rootState = Object.assign(initialStateDefault, {
159+
connections: {
160+
clientCerts: nextState,
161+
},
162+
})
163+
expect(clientCertsSelector(rootState)).toEqual(state)
164+
})
165+
})
166+
100167
describe('loadClientCertsFailure', () => {
101168
it('should properly set the error', () => {
102169
// Arrange
@@ -142,5 +209,68 @@ describe('clientCerts slice', () => {
142209
]
143210
expect(store.getActions()).toEqual(expectedActions)
144211
})
212+
213+
it('call both fetchClientCerts and deleteClientCertSuccess when delete is successed', async () => {
214+
// Arrange delete
215+
const responsePayload = { status: 200 }
216+
apiService.delete = jest.fn().mockResolvedValue(responsePayload)
217+
218+
// Arrange fetch
219+
const data = [
220+
{ id: '70b95d32-c19d-4311-bb24-e684af12cf15', name: 'client cert' },
221+
]
222+
const fetchResponsePayload = { data, status: 200 }
223+
apiService.get = jest.fn().mockResolvedValue(fetchResponsePayload)
224+
225+
// mock function for onSuccessAction
226+
const onSuccessAction = jest.fn()
227+
228+
const id = '70b95d32-c19d-4311-bb24-e684af12cf15'
229+
230+
const store = cloneDeep(mockedStore)
231+
232+
// Act
233+
await store.dispatch<any>(deleteClientCert(id, onSuccessAction))
234+
235+
// Assert onSuccessAction
236+
expect(onSuccessAction).toBeCalled()
237+
238+
// Assert
239+
const expectedActions = [
240+
deleteClientCert(),
241+
deleteClientCertSuccess(),
242+
loadClientCerts(),
243+
loadClientCertsSuccess(fetchResponsePayload.data),
244+
]
245+
expect(store.getActions()).toEqual(expectedActions)
246+
})
247+
248+
it('call both fetchClientCerts and deleteClientCertFailure when delete is failed', async () => {
249+
// Arrange delete
250+
const error = 'some error'
251+
const responsePayload = {
252+
response: { data: { message: error }, status: 500 },
253+
}
254+
apiService.delete = jest.fn().mockRejectedValueOnce(responsePayload)
255+
256+
const onSuccessAction = jest.fn()
257+
const id = '70b95d32-c19d-4311-bb24-e684af12cf15'
258+
259+
const store = cloneDeep(mockedStore)
260+
261+
// Act
262+
await store.dispatch<any>(deleteClientCert(id, onSuccessAction))
263+
264+
// assert that onSuccessAction is not called
265+
expect(onSuccessAction).not.toBeCalled()
266+
267+
// Assert
268+
const expectedActions = [
269+
deleteClientCert(),
270+
addErrorNotification(responsePayload as AxiosError),
271+
deleteClientCertFailure(responsePayload.response.data.message),
272+
]
273+
expect(store.getActions()).toEqual(expectedActions)
274+
})
145275
})
146276
})

0 commit comments

Comments
 (0)