Skip to content

Commit 31c3bfe

Browse files
authored
RI-6797: Prevent editing of Hex and Binary values (#4393)
1 parent dd6358b commit 31c3bfe

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

redisinsight/ui/src/pages/browser/modules/key-details/components/hash-details/hash-details-table/HashDetailsTable.spec.tsx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ import { instance, mock } from 'ts-mockito'
33
import { cloneDeep } from 'lodash'
44
import {
55
KeyValueCompressor,
6+
KeyValueFormat,
67
TEXT_DISABLED_ACTION_WITH_TRUNCATED_DATA,
78
TEXT_DISABLED_COMPRESSED_VALUE,
9+
TEXT_DISABLED_FORMATTER_EDITING,
810
} from 'uiSrc/constants'
911
import { hashDataSelector } from 'uiSrc/slices/browser/hash'
1012
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
1113
import { anyToBuffer, bufferToString } from 'uiSrc/utils'
1214
import { act, cleanup, fireEvent, mockedStore, render, screen, waitForEuiToolTipVisible } from 'uiSrc/utils/test-utils'
1315
import { GZIP_COMPRESSED_VALUE_1, GZIP_COMPRESSED_VALUE_2, DECOMPRESSED_VALUE_STR_1, DECOMPRESSED_VALUE_STR_2 } from 'uiSrc/utils/tests/decompressors'
14-
import { setSelectedKeyRefreshDisabled } from 'uiSrc/slices/browser/keys'
16+
import { setSelectedKeyRefreshDisabled, selectedKeySelector } from 'uiSrc/slices/browser/keys'
1517
import { MOCK_TRUNCATED_BUFFER_VALUE, MOCK_TRUNCATED_STRING_VALUE } from 'uiSrc/mocks/data/bigString'
1618
import { HashDetailsTable, Props } from './HashDetailsTable'
1719

@@ -45,11 +47,20 @@ jest.mock('uiSrc/slices/instances/instances', () => ({
4547
}),
4648
}))
4749

50+
jest.mock('uiSrc/slices/browser/keys', () => ({
51+
...jest.requireActual('uiSrc/slices/browser/keys'),
52+
selectedKeySelector: jest.fn().mockReturnValue({
53+
viewFormat: 'Unicode',
54+
lastRefreshTime: Date.now(),
55+
}),
56+
}))
57+
4858
let store: typeof mockedStore
4959
beforeEach(() => {
5060
cleanup()
5161
store = cloneDeep(mockedStore)
5262
store.clearActions()
63+
jest.clearAllMocks()
5364
})
5465

5566
describe('HashDetailsTable', () => {
@@ -143,6 +154,39 @@ describe('HashDetailsTable', () => {
143154
])
144155
})
145156

157+
const nonEditableFormats = [
158+
KeyValueFormat.HEX,
159+
KeyValueFormat.Binary,
160+
]
161+
162+
test.each(nonEditableFormats)(
163+
'should disable edit button when viewFormat is not editable for format: %s',
164+
async (format) => {
165+
(selectedKeySelector as jest.Mock).mockReturnValueOnce({
166+
viewFormat: format,
167+
lastRefreshTime: Date.now(),
168+
})
169+
170+
render(<HashDetailsTable {...instance(mockedProps)} />)
171+
172+
act(() => {
173+
fireEvent.mouseEnter(screen.getByTestId('hash_content-value-1'))
174+
})
175+
176+
const editBtn = screen.getByTestId('hash_edit-btn-1')
177+
expect(editBtn).toBeDisabled()
178+
179+
act(() => {
180+
fireEvent.mouseOver(editBtn)
181+
})
182+
183+
await waitForEuiToolTipVisible()
184+
expect(screen.getByTestId('hash_edit-tooltip-1')).toHaveTextContent(
185+
TEXT_DISABLED_FORMATTER_EDITING,
186+
)
187+
},
188+
)
189+
146190
describe('decompressed data', () => {
147191
it('should render decompressed GZIP data', () => {
148192
const defaultState = jest.requireActual('uiSrc/slices/browser/hash').initialState

redisinsight/ui/src/utils/formatters/valueFormatters.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const isFormatEditable = (format: KeyValueFormat) => ![
5151
KeyValueFormat.Pickle,
5252
KeyValueFormat.Vector32Bit,
5353
KeyValueFormat.Vector64Bit,
54+
KeyValueFormat.HEX,
55+
KeyValueFormat.Binary,
5456
].includes(format)
5557

5658
const isFullStringLoaded = (currentLength: Maybe<number>, fullLength: Maybe<number>) => currentLength === fullLength

0 commit comments

Comments
 (0)