Skip to content

Commit 83013c9

Browse files
committed
#RI-5348 - add tests, add handling errors
1 parent ff08666 commit 83013c9

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

redisinsight/ui/src/pages/home/components/databases-list-component/databases-list/DatabasesList.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ function DatabasesList({
5656
if (columnsToHide?.length && containerTableRef.current) {
5757
const { offsetWidth } = containerTableRef.current
5858
const beforeAdjustHiddenCols = hiddenCols.current.size
59-
const columnsResults = adjustColumns(columns, offsetWidth)
60-
if (beforeAdjustHiddenCols !== hiddenCols.current.size) {
61-
setColumns(columnsResults)
59+
try {
60+
const columnsResults = adjustColumns(columns, offsetWidth)
61+
if (beforeAdjustHiddenCols !== hiddenCols.current.size) {
62+
setColumns(columnsResults)
63+
}
64+
} catch (_) {
65+
// ignore
6266
}
6367
}
6468
}, [width])
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { getColumnWidth, findColumn, hideColumn, MIN_COLUMN_WIDTH } from './utils'
2+
3+
const getColumnWidthTests: any[] = [
4+
['10px', 10],
5+
['350px', 350],
6+
['100', MIN_COLUMN_WIDTH],
7+
['x', MIN_COLUMN_WIDTH],
8+
]
9+
10+
describe('getColumnWidth', () => {
11+
it.each(getColumnWidthTests)('for input: %s (input), should be output: %s',
12+
(input, expected) => {
13+
const result = getColumnWidth(input)
14+
expect(result).toBe(expected)
15+
})
16+
})
17+
18+
const findColumnTests: any[] = [
19+
[
20+
[
21+
[{ field: '1' }, { field: '2' }],
22+
'1'
23+
],
24+
{ field: '1' }
25+
],
26+
[
27+
[
28+
[{ field: '1' }, { field: '2' }],
29+
'3'
30+
],
31+
undefined
32+
]
33+
]
34+
35+
describe('findColumn', () => {
36+
it.each(findColumnTests)('for input: %s (input), should be output: %s',
37+
(input, expected) => {
38+
const result = findColumn(...input as [any, string])
39+
expect(result).toEqual(expected)
40+
})
41+
})
42+
43+
const hideColumnTests: any[] = [
44+
[
45+
{ field: '1' },
46+
{ field: '1', width: '0px', className: 'hiddenColumn' }
47+
],
48+
]
49+
50+
describe('hideColumn', () => {
51+
it.each(hideColumnTests)('for input: %s (input), should be output: %s',
52+
(input, expected) => {
53+
const result = hideColumn(input)
54+
expect(result).toEqual(expected)
55+
})
56+
})

redisinsight/ui/src/pages/home/components/databases-list-component/databases-list/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const findColumn = (columns: EuiTableFieldDataColumnType<Instance>[], colName: s
1313
find(columns, ({ field }) => field === colName)
1414

1515
export {
16+
MIN_COLUMN_WIDTH,
1617
getColumnWidth,
1718
hideColumn,
1819
findColumn,

0 commit comments

Comments
 (0)