Skip to content

Commit 28669d6

Browse files
committed
#RI-6522 - [Regression] Long vector string is not displayed
1 parent 66c842b commit 28669d6

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

redisinsight/ui/src/pages/browser/modules/key-details/components/string-details/string-details-value/StringDetailsValue.spec.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import { instance, mock } from 'ts-mockito'
3-
import { KeyValueCompressor } from 'uiSrc/constants'
3+
import { KeyValueCompressor, KeyValueFormat } from 'uiSrc/constants'
44
import {
55
fetchDownloadStringValue,
66
stringDataSelector
@@ -16,6 +16,7 @@ import {
1616
} from 'uiSrc/utils/tests/decompressors'
1717
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
1818
import { downloadFile } from 'uiSrc/utils/dom/downloadFile'
19+
import { selectedKeySelector } from 'uiSrc/slices/browser/keys'
1920
import { StringDetailsValue, Props } from './StringDetailsValue'
2021

2122
const STRING_VALUE = 'string-value'
@@ -46,6 +47,7 @@ jest.mock('uiSrc/slices/browser/keys', () => ({
4647
type: 'string',
4748
length: STRING_LENGTH
4849
}),
50+
selectedKeySelector: jest.fn(),
4951
}))
5052

5153
jest.mock('uiSrc/constants', () => ({
@@ -70,6 +72,13 @@ jest.mock('react-redux', () => ({
7072
useDispatch: () => jest.fn().mockReturnValue(() => jest.fn()),
7173
}))
7274

75+
beforeEach(async () => {
76+
const selectedKeySelectorMock = jest.fn().mockReturnValue({
77+
viewFormat: KeyValueFormat.Unicode,
78+
});
79+
(selectedKeySelector as jest.Mock).mockImplementation(selectedKeySelectorMock)
80+
})
81+
7382
describe('StringDetailsValue', () => {
7483
it('should render', () => {
7584
expect(
@@ -204,6 +213,26 @@ describe('StringDetailsValue', () => {
204213
expect(screen.getByTestId(STRING_VALUE)).toHaveTextContent(`${bufferToString(partValue)}...`)
205214
})
206215

216+
it('Should render partValue in the Unicode format', async () => {
217+
const stringDataSelectorMock = jest.fn().mockReturnValue({
218+
// vector value
219+
value: anyToBuffer(new Float32Array([1.0]).buffer)
220+
})
221+
const selectedKeySelectorMock = jest.fn().mockReturnValue({
222+
viewFormat: KeyValueFormat.Vector32Bit,
223+
});
224+
(selectedKeySelector as jest.Mock).mockImplementation(selectedKeySelectorMock);
225+
(stringDataSelector as jest.Mock).mockImplementation(stringDataSelectorMock)
226+
227+
render(
228+
<StringDetailsValue
229+
{...instance(mockedProps)}
230+
/>
231+
)
232+
expect(screen.getByTestId(STRING_VALUE)).toHaveTextContent('�?...')
233+
expect(screen.getByTestId(STRING_VALUE)).not.toHaveTextContent('[object Object]')
234+
})
235+
207236
it('Should not add "..." in the end of the full value', async () => {
208237
const stringDataSelectorMock = jest.fn().mockReturnValue({
209238
value: fullValue

redisinsight/ui/src/pages/browser/modules/key-details/components/string-details/string-details-value/StringDetailsValue.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ import {
3939
TEXT_FAILED_CONVENT_FORMATTER,
4040
TEXT_INVALID_VALUE,
4141
TEXT_UNPRINTABLE_CHARACTERS,
42-
STRING_MAX_LENGTH
42+
STRING_MAX_LENGTH,
43+
KeyValueFormat,
4344
} from 'uiSrc/constants'
4445
import { calculateTextareaLines } from 'uiSrc/utils/calculateTextareaLines'
4546
import { decompressingBuffer } from 'uiSrc/utils/decompressors'
@@ -96,10 +97,16 @@ const StringDetailsValue = (props: Props) => {
9697
const { value: decompressedValue, isCompressed } = decompressingBuffer(initialValue, compressor)
9798

9899
const initialValueString = bufferToString(decompressedValue, viewFormat)
99-
const { value: formattedValue, isValid } = formattingBuffer(decompressedValue, viewFormatProp, { expanded: true })
100+
const fullStringLoaded = isFullStringLoaded(initialValue?.data?.length, length)
101+
102+
const { value: formattedValue, isValid } = formattingBuffer(
103+
decompressedValue,
104+
fullStringLoaded ? viewFormatProp : KeyValueFormat.Unicode,
105+
{ expanded: true }
106+
)
100107
setAreaValue(initialValueString)
101108

102-
setValue(!isFullStringLoaded(initialValue?.data?.length, length) ? `${formattedValue}...` : formattedValue)
109+
setValue(!fullStringLoaded ? `${formattedValue}...` : formattedValue)
103110
setIsValid(isValid)
104111
setIsDisabled(
105112
!isNonUnicodeFormatter(viewFormatProp, isValid)
@@ -108,7 +115,7 @@ const StringDetailsValue = (props: Props) => {
108115
setIsEditable(
109116
!isCompressed
110117
&& isFormatEditable(viewFormatProp)
111-
&& isFullStringLoaded(initialValue?.data?.length, length)
118+
&& fullStringLoaded
112119
)
113120
setNoEditableText(isCompressed ? TEXT_DISABLED_COMPRESSED_VALUE : TEXT_FAILED_CONVENT_FORMATTER(viewFormatProp))
114121

redisinsight/ui/src/utils/formatters/bufferFormatters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const bufferToASCII = (reply: RedisResponseBuffer): string => {
8787
return result
8888
}
8989

90-
const anyToBuffer = (reply: UintArray): RedisResponseBuffer =>
90+
const anyToBuffer = (reply: UintArray | ArrayBuffer): RedisResponseBuffer =>
9191
({ data: reply, type: RedisResponseBufferType.Buffer }) as RedisResponseBuffer
9292

9393
const ASCIIToBuffer = (strInit: string) => {

0 commit comments

Comments
 (0)