@@ -3,15 +3,17 @@ import { instance, mock } from 'ts-mockito'
3
3
import { cloneDeep } from 'lodash'
4
4
import {
5
5
KeyValueCompressor ,
6
+ KeyValueFormat ,
6
7
TEXT_DISABLED_ACTION_WITH_TRUNCATED_DATA ,
7
8
TEXT_DISABLED_COMPRESSED_VALUE ,
9
+ TEXT_DISABLED_FORMATTER_EDITING ,
8
10
} from 'uiSrc/constants'
9
11
import { hashDataSelector } from 'uiSrc/slices/browser/hash'
10
12
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
11
13
import { anyToBuffer , bufferToString } from 'uiSrc/utils'
12
14
import { act , cleanup , fireEvent , mockedStore , render , screen , waitForEuiToolTipVisible } from 'uiSrc/utils/test-utils'
13
15
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'
15
17
import { MOCK_TRUNCATED_BUFFER_VALUE , MOCK_TRUNCATED_STRING_VALUE } from 'uiSrc/mocks/data/bigString'
16
18
import { HashDetailsTable , Props } from './HashDetailsTable'
17
19
@@ -45,11 +47,20 @@ jest.mock('uiSrc/slices/instances/instances', () => ({
45
47
} ) ,
46
48
} ) )
47
49
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
+
48
58
let store : typeof mockedStore
49
59
beforeEach ( ( ) => {
50
60
cleanup ( )
51
61
store = cloneDeep ( mockedStore )
52
62
store . clearActions ( )
63
+ jest . clearAllMocks ( )
53
64
} )
54
65
55
66
describe ( 'HashDetailsTable' , ( ) => {
@@ -143,6 +154,39 @@ describe('HashDetailsTable', () => {
143
154
] )
144
155
} )
145
156
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
+
146
190
describe ( 'decompressed data' , ( ) => {
147
191
it ( 'should render decompressed GZIP data' , ( ) => {
148
192
const defaultState = jest . requireActual ( 'uiSrc/slices/browser/hash' ) . initialState
0 commit comments