Skip to content

Commit 4cf6128

Browse files
committed
added test for getColumns.spec.ts
1 parent 861998f commit 4cf6128

File tree

1 file changed

+79
-0
lines changed
  • redisinsight/ui/src/pages/autodiscover-sentinel/sentinel-databases/components/utils

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { getColumns } from './getColumns'
2+
import { SentinelDatabaseIds } from 'uiSrc/pages/autodiscover-sentinel/constants/constants'
3+
4+
describe('getColumns', () => {
5+
const mockHandleChangedInput = jest.fn((_name: string, _value: string) => {
6+
// Mock implementation
7+
})
8+
9+
beforeEach(() => {
10+
jest.clearAllMocks()
11+
})
12+
13+
it('should return all required column definitions in correct order', () => {
14+
const columns = getColumns(mockHandleChangedInput)
15+
16+
const columnIds = columns.map((col) => col.id)
17+
18+
expect(columnIds).toEqual([
19+
'row-selection',
20+
SentinelDatabaseIds.PrimaryGroup,
21+
SentinelDatabaseIds.Alias,
22+
SentinelDatabaseIds.Address,
23+
SentinelDatabaseIds.NumberOfReplicas,
24+
SentinelDatabaseIds.Username,
25+
SentinelDatabaseIds.Password,
26+
SentinelDatabaseIds.DatabaseIndex,
27+
])
28+
})
29+
30+
it('should include selection column as first column', () => {
31+
const columns = getColumns(mockHandleChangedInput)
32+
33+
expect(columns).toHaveLength(8)
34+
expect(columns[0].id).toBe('row-selection')
35+
expect(columns[0].isHeaderCustom).toBe(true)
36+
expect(columns[0].maxSize).toBe(50)
37+
expect(columns[0].size).toBe(50)
38+
})
39+
40+
it('should pass handleChangedInput via meta.action for columns that need it', () => {
41+
const columns = getColumns(mockHandleChangedInput)
42+
43+
const aliasColumn = columns.find(
44+
(col) => col.id === SentinelDatabaseIds.Alias,
45+
)
46+
const usernameColumn = columns.find(
47+
(col) => col.id === SentinelDatabaseIds.Username,
48+
)
49+
const passwordColumn = columns.find(
50+
(col) => col.id === SentinelDatabaseIds.Password,
51+
)
52+
const dbIndexColumn = columns.find(
53+
(col) => col.id === SentinelDatabaseIds.DatabaseIndex,
54+
)
55+
56+
expect(aliasColumn?.meta?.action).toBe(mockHandleChangedInput)
57+
expect(usernameColumn?.meta?.action).toBe(mockHandleChangedInput)
58+
expect(passwordColumn?.meta?.action).toBe(mockHandleChangedInput)
59+
expect(dbIndexColumn?.meta?.action).toBe(mockHandleChangedInput)
60+
})
61+
62+
it('should not include meta.action for columns that do not need it', () => {
63+
const columns = getColumns(mockHandleChangedInput)
64+
65+
const primaryGroupColumn = columns.find(
66+
(col) => col.id === SentinelDatabaseIds.PrimaryGroup,
67+
)
68+
const addressColumn = columns.find(
69+
(col) => col.id === SentinelDatabaseIds.Address,
70+
)
71+
const numberOfReplicasColumn = columns.find(
72+
(col) => col.id === SentinelDatabaseIds.NumberOfReplicas,
73+
)
74+
75+
expect(primaryGroupColumn?.meta?.action).toBeUndefined()
76+
expect(addressColumn?.meta?.action).toBeUndefined()
77+
expect(numberOfReplicasColumn?.meta?.action).toBeUndefined()
78+
})
79+
})

0 commit comments

Comments
 (0)