1
1
import React from 'react'
2
2
import { instance , mock } from 'ts-mockito'
3
- import { KeyValueCompressor } from 'uiSrc/constants'
3
+ import { KeyValueCompressor , KeyValueFormat } from 'uiSrc/constants'
4
4
import {
5
5
fetchDownloadStringValue ,
6
6
stringDataSelector
@@ -16,6 +16,7 @@ import {
16
16
} from 'uiSrc/utils/tests/decompressors'
17
17
import { sendEventTelemetry , TelemetryEvent } from 'uiSrc/telemetry'
18
18
import { downloadFile } from 'uiSrc/utils/dom/downloadFile'
19
+ import { selectedKeySelector } from 'uiSrc/slices/browser/keys'
19
20
import { StringDetailsValue , Props } from './StringDetailsValue'
20
21
21
22
const STRING_VALUE = 'string-value'
@@ -46,6 +47,7 @@ jest.mock('uiSrc/slices/browser/keys', () => ({
46
47
type : 'string' ,
47
48
length : STRING_LENGTH
48
49
} ) ,
50
+ selectedKeySelector : jest . fn ( ) ,
49
51
} ) )
50
52
51
53
jest . mock ( 'uiSrc/constants' , ( ) => ( {
@@ -70,6 +72,13 @@ jest.mock('react-redux', () => ({
70
72
useDispatch : ( ) => jest . fn ( ) . mockReturnValue ( ( ) => jest . fn ( ) ) ,
71
73
} ) )
72
74
75
+ beforeEach ( async ( ) => {
76
+ const selectedKeySelectorMock = jest . fn ( ) . mockReturnValue ( {
77
+ viewFormat : KeyValueFormat . Unicode ,
78
+ } ) ;
79
+ ( selectedKeySelector as jest . Mock ) . mockImplementation ( selectedKeySelectorMock )
80
+ } )
81
+
73
82
describe ( 'StringDetailsValue' , ( ) => {
74
83
it ( 'should render' , ( ) => {
75
84
expect (
@@ -204,6 +213,26 @@ describe('StringDetailsValue', () => {
204
213
expect ( screen . getByTestId ( STRING_VALUE ) ) . toHaveTextContent ( `${ bufferToString ( partValue ) } ...` )
205
214
} )
206
215
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
+
207
236
it ( 'Should not add "..." in the end of the full value' , async ( ) => {
208
237
const stringDataSelectorMock = jest . fn ( ) . mockReturnValue ( {
209
238
value : fullValue
0 commit comments