Skip to content

Commit 305fcc5

Browse files
#RI-5131 - update
1 parent f945b8d commit 305fcc5

File tree

2 files changed

+32
-50
lines changed

2 files changed

+32
-50
lines changed

redisinsight/ui/src/pages/browser/components/virtual-tree/VirtualTree.spec.tsx

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react'
22
import { mock, instance } from 'ts-mockito'
33

44
import { render } from 'uiSrc/utils/test-utils'
5-
import * as Services from 'uiSrc/services'
65
import VirtualTree, { Props } from './VirtualTree'
76

87
const mockedProps = mock<Props>()
@@ -16,37 +15,36 @@ const mockedItems = [
1615
},
1716
]
1817

19-
const mockTreeItem = {
20-
children: [{
18+
export const mockVirtualTreeResult = [
19+
{
20+
children: [{
21+
children: [],
22+
fullName: 'car:110:',
23+
id: '0.snc1rc3zwgo',
24+
keyApproximate: 0.01,
25+
keyCount: 1,
26+
name: '110',
27+
}],
28+
fullName: 'car:',
29+
id: '0.sz1ie1koqi8',
30+
keyApproximate: 47.18,
31+
keyCount: 4718,
32+
name: 'car',
33+
},
34+
{
2135
children: [],
22-
fullName: 'car:110:',
23-
id: '0.snc1rc3zwgo',
36+
fullName: 'test',
37+
id: '0.snc1rc3zwg1o',
2438
keyApproximate: 0.01,
2539
keyCount: 1,
26-
name: '110',
27-
}],
28-
fullName: 'car:',
29-
id: '0.sz1ie1koqi8',
30-
keyApproximate: 47.18,
31-
keyCount: 4718,
32-
name: 'car',
33-
}
34-
35-
const mockTreeItem2 = {
36-
children: [],
37-
fullName: 'test',
38-
id: '0.snc1rc3zwg1o',
39-
keyApproximate: 0.01,
40-
keyCount: 1,
41-
name: 'test',
42-
}
43-
44-
export const mockVirtualTreeResult = [mockTreeItem, mockTreeItem2]
40+
name: 'test',
41+
}
42+
]
4543

4644
jest.mock('uiSrc/services', () => ({
4745
__esModule: true,
4846
...jest.requireActual('uiSrc/services'),
49-
useDisposableWebworker: jest.fn().mockReturnValue({ result: mockVirtualTreeResult, run: jest.fn() })
47+
useDisposableWebworker: () => ({ result: mockVirtualTreeResult, run: jest.fn() })
5048
}))
5149

5250
describe('VirtualTree', () => {
@@ -68,9 +66,6 @@ describe('VirtualTree', () => {
6866
})
6967

7068
it('should render items', async () => {
71-
jest.spyOn(Services, 'useDisposableWebworker')
72-
.mockReturnValueOnce({ result: [mockTreeItem, mockTreeItem2], run: jest.fn() })
73-
7469
const mockFn = jest.fn()
7570
const { queryByTestId } = render(
7671
<VirtualTree
@@ -83,24 +78,6 @@ describe('VirtualTree', () => {
8378
expect(queryByTestId('node-item_test')).toBeInTheDocument()
8479
})
8580

86-
it('should call onStatusOpen if only one folder is exist', () => {
87-
jest.spyOn(Services, 'useDisposableWebworker')
88-
.mockReturnValueOnce({ result: [mockTreeItem], run: jest.fn() })
89-
90-
const mockFn = jest.fn()
91-
const mockOnStatusOpen = jest.fn()
92-
93-
render(
94-
<VirtualTree
95-
{...instance(mockedProps)}
96-
onStatusOpen={mockOnStatusOpen}
97-
setConstructingTree={mockFn}
98-
/>
99-
)
100-
101-
expect(mockOnStatusOpen).toBeCalledWith('car:', true)
102-
})
103-
10481
it('should not call onStatusOpen if more than one folder is exist', () => {
10582
const mockFn = jest.fn()
10683
const mockOnStatusOpen = jest.fn()

redisinsight/ui/src/pages/browser/components/virtual-tree/VirtualTree.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const VirtualTree = (props: Props) => {
6363
onStatusOpen,
6464
onStatusSelected,
6565
setConstructingTree,
66-
webworkerFn = () => {},
66+
webworkerFn = () => { },
6767
onDeleteClicked,
6868
onDeleteLeaf,
6969
} = props
@@ -95,9 +95,7 @@ const VirtualTree = (props: Props) => {
9595
rerender({})
9696
setConstructingTree?.(false)
9797

98-
if (nodes?.current?.length === 1) {
99-
onStatusOpen?.(nodes.current[0].fullName, true)
100-
}
98+
openSingleFolderNode(nodes.current)
10199
}, [result])
102100

103101
useEffect(() => {
@@ -209,6 +207,13 @@ const VirtualTree = (props: Props) => {
209207
node,
210208
})
211209

210+
const openSingleFolderNode = useCallback((nodes?: TreeNode[]) => {
211+
if (nodes?.length === 1) {
212+
onStatusOpen?.(nodes[0].fullName, true)
213+
openSingleFolderNode(nodes[0].children)
214+
}
215+
}, [onStatusOpen])
216+
212217
// The `treeWalker` function runs only on tree re-build which is performed
213218
// whenever the `treeWalker` prop is changed.
214219
const treeWalker = useCallback(

0 commit comments

Comments
 (0)