Skip to content

Commit e1e64b4

Browse files
committed
fix tests
1 parent 2e18576 commit e1e64b4

File tree

5 files changed

+42
-106
lines changed

5 files changed

+42
-106
lines changed

redisinsight/ui/src/components/analytics-tabs/AnalyticsTabs.spec.tsx

Lines changed: 15 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import React from 'react'
2-
import { useSelector } from 'react-redux'
32
import reactRouterDom from 'react-router-dom'
43
import { AnalyticsViewTab } from 'uiSrc/slices/interfaces/analytics'
5-
import { RootState, store } from 'uiSrc/slices/store'
64
import { ConnectionType } from 'uiSrc/slices/interfaces'
75
import { act, fireEvent, render, screen } from 'uiSrc/utils/test-utils'
6+
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
87
import AnalyticsTabs from './AnalyticsTabs'
98

10-
jest.mock('react-redux', () => ({
11-
...jest.requireActual('react-redux'),
12-
useSelector: jest.fn()
9+
const mockedStandaloneConnection = ConnectionType.Standalone
10+
jest.mock('uiSrc/slices/instances/instances', () => ({
11+
...jest.requireActual('uiSrc/slices/instances/instances'),
12+
connectedInstanceSelector: jest.fn().mockReturnValue({
13+
connectionType: mockedStandaloneConnection
14+
}),
1315
}))
1416

1517
jest.mock('react-router-dom', () => ({
@@ -19,20 +21,6 @@ jest.mock('react-router-dom', () => ({
1921
}),
2022
}))
2123

22-
beforeEach(() => {
23-
const state: RootState = store.getState();
24-
25-
(useSelector as jest.Mock).mockImplementation((callback: (arg0: RootState) => RootState) => callback({
26-
...state,
27-
analytics: {
28-
...state.analytics
29-
},
30-
connections: {
31-
...state.connections
32-
}
33-
}))
34-
})
35-
3624
describe('AnalyticsTabs', () => {
3725
it('should render', () => {
3826
expect(render(<AnalyticsTabs />)).toBeTruthy()
@@ -66,65 +54,27 @@ describe('AnalyticsTabs', () => {
6654
})
6755

6856
it('should render cluster details tab when connectionType is Cluster', async () => {
69-
const state: RootState = store.getState();
70-
71-
(useSelector as jest.Mock).mockImplementation((callback: (arg0: RootState) => RootState) => callback({
72-
...state,
73-
connections: {
74-
...state.connections,
75-
instances: {
76-
...state.connections.instances,
77-
connectedInstance: {
78-
...state.connections.instances.connectedInstance,
79-
connectionType: ConnectionType.Cluster
80-
}
81-
},
82-
}
83-
}))
57+
const mockConnectionType = ConnectionType.Cluster;
58+
(connectedInstanceSelector as jest.Mock).mockReturnValueOnce({
59+
connectionType: mockConnectionType
60+
})
8461

8562
render(<AnalyticsTabs />)
8663

8764
expect(screen.getByTestId(`analytics-tab-${AnalyticsViewTab.ClusterDetails}`)).toBeInTheDocument()
8865
})
8966

9067
it('should not render cluster details tab when connectionType is not Cluster', async () => {
91-
const state: RootState = store.getState();
92-
93-
(useSelector as jest.Mock).mockImplementation((callback: (arg0: RootState) => RootState) => callback({
94-
...state,
95-
connections: {
96-
...state.connections,
97-
instances: {
98-
...state.connections.instances,
99-
connectedInstance: {
100-
...state.connections.instances.connectedInstance,
101-
connectionType: ConnectionType.Standalone
102-
}
103-
},
104-
}
105-
}))
106-
10768
const { queryByTestId } = render(<AnalyticsTabs />)
10869

10970
expect(queryByTestId(`analytics-tab-${AnalyticsViewTab.ClusterDetails}`)).not.toBeInTheDocument()
11071
})
11172

11273
it('should call History push with /cluster-details path when click on ClusterDetails tab ', async () => {
113-
const state: RootState = store.getState();
114-
115-
(useSelector as jest.Mock).mockImplementation((callback: (arg0: RootState) => RootState) => callback({
116-
...state,
117-
connections: {
118-
...state.connections,
119-
instances: {
120-
...state.connections.instances,
121-
connectedInstance: {
122-
...state.connections.instances.connectedInstance,
123-
connectionType: ConnectionType.Cluster
124-
}
125-
},
126-
}
127-
}))
74+
const mockConnectionType = ConnectionType.Cluster;
75+
(connectedInstanceSelector as jest.Mock).mockReturnValueOnce({
76+
connectionType: mockConnectionType
77+
})
12878
const pushMock = jest.fn()
12979
reactRouterDom.useHistory = jest.fn().mockReturnValue({ push: pushMock })
13080

redisinsight/ui/src/pages/instance/InstancePage.spec.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ import { resetKeys, resetPatternKeysData } from 'uiSrc/slices/browser/keys'
1111
import { setMonitorInitialState } from 'uiSrc/slices/cli/monitor'
1212
import { setInitialPubSubState } from 'uiSrc/slices/pubsub/pubsub'
1313
import { setBulkActionsInitialState } from 'uiSrc/slices/browser/bulkActions'
14-
import { setAppContextConnectedInstanceId, setAppContextInitialState, setDbConfig } from 'uiSrc/slices/app/context'
15-
import { clearSearchingCommand, resetCliHelperSettings, setCliEnteringCommand } from 'uiSrc/slices/cli/cli-settings'
14+
import {
15+
appContextSelector,
16+
setAppContextConnectedInstanceId,
17+
setAppContextInitialState,
18+
setDbConfig
19+
} from 'uiSrc/slices/app/context'
20+
import { resetCliHelperSettings } from 'uiSrc/slices/cli/cli-settings'
1621
import { resetRedisearchKeysData, setRedisearchInitialState } from 'uiSrc/slices/browser/redisearch'
1722
import { setClusterDetailsInitialState } from 'uiSrc/slices/analytics/clusterDetails'
1823
import { setDatabaseAnalysisInitialState } from 'uiSrc/slices/analytics/dbAnalysis'
@@ -27,6 +32,7 @@ import {
2732
} from 'uiSrc/slices/instances/instances'
2833
import InstancePage, { getDefaultSizes, Props } from './InstancePage'
2934

35+
const INSTANCE_ID_MOCK = 'instanceId'
3036
const mockedProps = mock<Props>()
3137

3238
jest.mock('uiSrc/services', () => ({
@@ -48,12 +54,10 @@ jest.mock('uiSrc/slices/app/features', () => ({
4854
jest.mock('uiSrc/slices/app/context', () => ({
4955
...jest.requireActual('uiSrc/slices/app/context'),
5056
appContextSelector: jest.fn().mockReturnValue({
51-
contextInstanceId: 'prevId'
57+
contextInstanceId: INSTANCE_ID_MOCK
5258
}),
5359
}))
5460

55-
const INSTANCE_ID_MOCK = 'instanceId'
56-
5761
let store: typeof mockedStore
5862
beforeEach(() => {
5963
cleanup()
@@ -131,6 +135,10 @@ describe('InstancePage', () => {
131135
})
132136

133137
it('should call proper actions with resetting context', async () => {
138+
(appContextSelector as jest.Mock).mockReturnValue({
139+
contextInstanceId: 'prevId'
140+
})
141+
134142
await act(() => {
135143
render(
136144
<BrowserRouter>

redisinsight/ui/src/pages/pubSub/components/messages-list/MessagesListWrapper.spec.tsx

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
import React from 'react'
2-
import { useSelector } from 'react-redux'
3-
import { RootState, store } from 'uiSrc/slices/store'
42
import { render } from 'uiSrc/utils/test-utils'
53

4+
import { pubSubSelector } from 'uiSrc/slices/pubsub/pubsub'
65
import MessagesListWrapper from './MessagesListWrapper'
76

8-
jest.mock('react-redux', () => ({
9-
...jest.requireActual('react-redux'),
10-
useSelector: jest.fn()
7+
jest.mock('uiSrc/slices/pubsub/pubsub', () => ({
8+
...jest.requireActual('uiSrc/slices/pubsub/pubsub'),
9+
pubSubSelector: jest.fn().mockReturnValue({
10+
isSubscribed: false,
11+
messages: []
12+
}),
1113
}))
1214

13-
beforeEach(() => {
14-
const state: RootState = store.getState();
15-
16-
(useSelector as jest.Mock).mockImplementation((callback: (arg0: RootState) => RootState) => callback({
17-
...state,
18-
pubsub: {
19-
...state.pubsub,
20-
}
21-
}))
22-
})
23-
2415
describe('MessagesListWrapper', () => {
2516
it('should render', () => {
2617
expect(
@@ -36,15 +27,9 @@ describe('MessagesListWrapper', () => {
3627
})
3728

3829
it('should render MessagesList if isSubscribed === true', () => {
39-
const state: RootState = store.getState();
40-
41-
(useSelector as jest.Mock).mockImplementation((callback: (arg0: RootState) => RootState) => callback({
42-
...state,
43-
pubsub: {
44-
...state.pubsub,
45-
isSubscribed: true,
46-
}
47-
}))
30+
(pubSubSelector as jest.Mock).mockReturnValue({
31+
isSubscribed: true
32+
})
4833

4934
const { queryByTestId } = render(<MessagesListWrapper />)
5035

@@ -53,15 +38,9 @@ describe('MessagesListWrapper', () => {
5338
})
5439

5540
it('should render MessagesList if messages.length !== 0', () => {
56-
const state: RootState = store.getState();
57-
58-
(useSelector as jest.Mock).mockImplementation((callback: (arg0: RootState) => RootState) => callback({
59-
...state,
60-
pubsub: {
61-
...state.pubsub,
62-
messages: [{ time: 123, channel: 'channel', message: 'msg' }],
63-
}
64-
}))
41+
(pubSubSelector as jest.Mock).mockReturnValue({
42+
messages: [{ time: 123, channel: 'channel', message: 'msg' }]
43+
})
6544

6645
const { queryByTestId } = render(<MessagesListWrapper />)
6746

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
DEFAULT_SLOWLOG_DURATION_UNIT,
99
KeyTypes,
1010
DEFAULT_SHOW_HIDDEN_RECOMMENDATIONS,
11-
DurationUnits,
1211
} from 'uiSrc/constants'
1312
import { localStorageService, setDBConfigStorageField } from 'uiSrc/services'
1413
import { RootState } from '../store'

redisinsight/ui/src/slices/instances/instances.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import ApiErrors from 'uiSrc/constants/apiErrors'
66
import { apiService, localStorageService, sessionStorageService } from 'uiSrc/services'
77
import { ApiEndpoints, BrowserStorageItem, CustomErrorCodes } from 'uiSrc/constants'
88
import { setAppContextInitialState } from 'uiSrc/slices/app/context'
9+
import { resetKeys } from 'uiSrc/slices/browser/keys'
910
import successMessages from 'uiSrc/components/notifications/success-messages'
1011
import { checkRediStack, getApiErrorMessage, isStatusSuccessful, Nullable } from 'uiSrc/utils'
1112
import { INFINITE_MESSAGES, InfiniteMessagesIds } from 'uiSrc/components/notifications/components'
12-
import { resetKeys } from 'uiSrc/slices/browser/keys'
1313
import { Database as DatabaseInstanceResponse } from 'apiSrc/modules/database/models/database'
1414
import { RedisNodeInfoResponse } from 'apiSrc/modules/database/dto/redis-info.dto'
1515
import { ExportDatabase } from 'apiSrc/modules/database/models/export-database'

0 commit comments

Comments
 (0)