Skip to content

Commit e3f1735

Browse files
author
KIvanow
committed
RI-6336 updated unit tests
1 parent ae373d8 commit e3f1735

File tree

6 files changed

+33
-74
lines changed

6 files changed

+33
-74
lines changed

redisinsight/api/src/modules/browser/set/set.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const REDIS_SCAN_CONFIG = config.get('redis_scan');
3636
export class SetService {
3737
private logger = new Logger('SetService');
3838

39-
constructor(private databaseClientFactory: DatabaseClientFactory) {}
39+
constructor(private databaseClientFactory: DatabaseClientFactory) { }
4040

4141
public async createSet(
4242
clientMetadata: ClientMetadata,

redisinsight/ui/src/constants/browser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ export enum BrowserColumns {
2929
Size = 'size',
3030
TTL = 'ttl',
3131
}
32+
33+
export const DEFAULT_SHOWN_COLUMNS = [BrowserColumns.Size, BrowserColumns.TTL]

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

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -213,58 +213,19 @@ describe('Node', () => {
213213
expect(screen.queryByTestId(`size-${mockDataFullName}`)).not.toBeInTheDocument()
214214
})
215215

216-
it('should refetch metadata when TTL column is re-enabled even with existing metadata', () => {
217-
const mockGetMetadata = jest.fn()
218-
const mockData: TreeData = {
219-
...mockedDataWithMetadata,
220-
getMetadata: mockGetMetadata,
221-
}
222-
223-
const store = {
224-
getState: () => ({
225-
browser: {
226-
keys: {
227-
shownColumns: []
228-
}
229-
}
230-
}),
231-
subscribe: jest.fn(),
232-
dispatch: jest.fn(),
233-
}
234-
235-
const { rerender } = render(
236-
<Node {...instance(mockedProps)} data={mockData} />,
237-
{ store }
238-
)
239-
240-
store.getState = () => ({
241-
browser: {
242-
keys: {
243-
shownColumns: [BrowserColumns.TTL]
244-
}
245-
} as any
246-
})
247-
248-
rerender(<Node {...instance(mockedProps)} data={mockData} />)
249-
250-
expect(mockGetMetadata).toHaveBeenCalledWith(mockData.nameBuffer, mockData.path)
251-
})
252-
253-
it('should refetch metadata when Size column is re-enabled even with existing metadata', () => {
216+
it.each`
217+
description | initialState | updatedState
218+
${'TTL column'} | ${{ app: { context: { dbConfig: { shownColumns: [] } } } }} | ${{ app: { context: { dbConfig: { shownColumns: [BrowserColumns.TTL] } } } }}
219+
${'Size column'} | ${{ app: { context: { dbConfig: { shownColumns: [] } } } }} | ${{ app: { context: { dbConfig: { shownColumns: [BrowserColumns.Size] } } } }}
220+
`('should refetch metadata when $description is re-enabled even with existing metadata', ({ initialState, updatedState }) => {
254221
const mockGetMetadata = jest.fn()
255222
const mockData: TreeData = {
256223
...mockedDataWithMetadata,
257224
getMetadata: mockGetMetadata,
258225
}
259226

260227
const store = {
261-
getState: () => ({
262-
browser: {
263-
keys: {
264-
shownColumns: []
265-
}
266-
}
267-
}),
228+
getState: () => initialState,
268229
subscribe: jest.fn(),
269230
dispatch: jest.fn(),
270231
}
@@ -274,13 +235,7 @@ describe('Node', () => {
274235
{ store }
275236
)
276237

277-
store.getState = () => ({
278-
browser: {
279-
keys: {
280-
shownColumns: [BrowserColumns.Size]
281-
}
282-
} as any
283-
})
238+
store.getState = () => updatedState
284239

285240
rerender(<Node {...instance(mockedProps)} data={mockData} />)
286241

@@ -302,9 +257,11 @@ describe('Node', () => {
302257

303258
const store = {
304259
getState: () => ({
305-
browser: {
306-
keys: {
307-
shownColumns: columns
260+
app: {
261+
context: {
262+
dbConfig: {
263+
shownColumns: columns
264+
}
308265
}
309266
}
310267
}),

redisinsight/ui/src/slices/app/context.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
KeyTypes, Pages,
1313
SortOrder,
1414
BrowserColumns,
15+
DEFAULT_SHOWN_COLUMNS,
1516
} from 'uiSrc/constants'
1617
import { localStorageService, setCapabilityStorageField, setDBConfigStorageField } from 'uiSrc/services'
1718
import { clearExpertChatHistory } from 'uiSrc/slices/panels/aiAssistant'
@@ -31,8 +32,6 @@ import { SearchMode } from '../interfaces/keys'
3132
import { AppWorkspace, RedisResponseBuffer, StateAppContext } from '../interfaces'
3233
import { AppDispatch, RootState } from '../store'
3334

34-
const DEFAULT_SHOWN_COLUMNS = [BrowserColumns.Size, BrowserColumns.TTL]
35-
3635
export const initialState: StateAppContext = {
3736
workspace: localStorageService.get(BrowserStorageItem.homePage) === Pages.rdi
3837
? AppWorkspace.RDI

redisinsight/ui/src/slices/browser/keys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ export function fetchKeyInfo(
661661
onSuccess?: (data: Nullable<IKeyPropTypes>) => void
662662
) {
663663
return async (dispatch: AppDispatch, stateInit: () => RootState) => {
664+
dispatch(defaultSelectedKeyAction())
664665
const { shownColumns } = stateInit()?.app?.context?.dbConfig
665666
try {
666667
const state = stateInit()

redisinsight/ui/src/slices/tests/browser/keys.spec.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { cloneDeep } from 'lodash'
22
import { AxiosError } from 'axios'
33
import { configureStore } from '@reduxjs/toolkit'
4-
import { BrowserColumns, KeyTypes, KeyValueFormat, ModulesKeyTypes } from 'uiSrc/constants'
4+
import { BrowserColumns, DEFAULT_SHOWN_COLUMNS, KeyTypes, KeyValueFormat, ModulesKeyTypes } from 'uiSrc/constants'
55
import { apiService } from 'uiSrc/services'
66
import { parseKeysListResponse, stringToBuffer, UTF8ToBuffer } from 'uiSrc/utils'
7-
import { cleanup, clearStoreActions, initialStateDefault, mockedStore } from 'uiSrc/utils/test-utils'
7+
import { cleanup, clearStoreActions, initialStateDefault, mockedStore, mockStore } from 'uiSrc/utils/test-utils'
88
import { addErrorNotification, addMessageNotification } from 'uiSrc/slices/app/notifications'
99
import successMessages from 'uiSrc/components/notifications/success-messages'
1010
import { SearchHistoryItem, SearchMode } from 'uiSrc/slices/interfaces/keys'
@@ -1639,13 +1639,13 @@ describe('keys slice', () => {
16391639
it(`success to fetch keys metadata with ${name}`, async () => {
16401640
const initialStateWithColumns = {
16411641
...initialStateDefault,
1642-
browser: {
1643-
...initialStateDefault.browser,
1644-
keys: {
1645-
...initialStateDefault.browser.keys,
1646-
shownColumns,
1647-
}
1648-
}
1642+
app: {
1643+
context: {
1644+
dbConfig: {
1645+
shownColumns,
1646+
},
1647+
},
1648+
},
16491649
}
16501650

16511651
const testStore = configureStore({
@@ -1717,13 +1717,13 @@ describe('keys slice', () => {
17171717
it(`success to fetch keys metadata with ${name}`, async () => {
17181718
const initialStateWithColumns = {
17191719
...initialStateDefault,
1720-
browser: {
1721-
...initialStateDefault.browser,
1722-
keys: {
1723-
...initialStateDefault.browser.keys,
1724-
shownColumns,
1725-
}
1726-
}
1720+
app: {
1721+
context: {
1722+
dbConfig: {
1723+
shownColumns,
1724+
},
1725+
},
1726+
},
17271727
}
17281728

17291729
const testStore = configureStore({

0 commit comments

Comments
 (0)