Skip to content

Commit 16fc15c

Browse files
#RI-3699-add tooltip tests
1 parent 4c3d07d commit 16fc15c

File tree

1 file changed

+66
-0
lines changed
  • redisinsight/ui/src/pages/databaseAnalysis/components/header

1 file changed

+66
-0
lines changed

redisinsight/ui/src/pages/databaseAnalysis/components/header/Header.spec.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import React from 'react'
22
import { cloneDeep } from 'lodash'
3+
import { useSelector } from 'react-redux'
34
import { instance, mock } from 'ts-mockito'
45
import { getDBAnalysis } from 'uiSrc/slices/analytics/dbAnalysis'
6+
import { RootState } from 'uiSrc/slices/store'
57
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
68
import { INSTANCE_ID_MOCK } from 'uiSrc/mocks/handlers/analytics/clusterDetailsHandlers'
79

810
import {
11+
act,
912
cleanup,
1013
mockedStore,
1114
fireEvent,
1215
render,
1316
screen,
17+
waitForEuiToolTipVisible,
1418
} from 'uiSrc/utils/test-utils'
1519

1620
import Header, { Props } from './Header'
@@ -41,7 +45,33 @@ jest.mock('uiSrc/telemetry', () => ({
4145
sendEventTelemetry: jest.fn(),
4246
}))
4347

48+
jest.mock('react-redux', () => ({
49+
...jest.requireActual('react-redux'),
50+
useSelector: jest.fn(),
51+
}))
52+
53+
const connectType = (state: any, connectionType: any) => {
54+
(useSelector as jest.Mock).mockImplementation((callback: (arg0: RootState) => RootState) => callback({
55+
...state,
56+
connections: {
57+
...state.connections,
58+
instances: {
59+
...state.connections.instances,
60+
connectedInstance: {
61+
...state.connections.instances.connectedInstance,
62+
connectionType,
63+
}
64+
}
65+
},
66+
}))
67+
}
68+
4469
describe('DatabaseAnalysisHeader', () => {
70+
beforeEach(() => {
71+
const state: any = store.getState()
72+
connectType(state, 'STANDALONE')
73+
})
74+
4575
it('should render', () => {
4676
expect(render(<Header {...instance(mockedProps)} />)).toBeTruthy()
4777
})
@@ -101,3 +131,39 @@ describe('DatabaseAnalysisHeader', () => {
101131
expect(onChangeSelectedAnalysis).toBeCalled()
102132
})
103133
})
134+
135+
describe('Cluster tooltip', () => {
136+
beforeEach(() => {
137+
const state: any = store.getState()
138+
connectType(state, 'CLUSTER')
139+
})
140+
141+
it('should render cluster tooltip message', async () => {
142+
render(<Header {...instance(mockedProps)} />)
143+
144+
await act(async () => {
145+
fireEvent.mouseOver(screen.getByTestId('db-new-reports-icon'))
146+
})
147+
await waitForEuiToolTipVisible()
148+
149+
expect(screen.getByTestId('db-new-reports-tooltip')).toHaveTextContent('Analyze up to 10 000 keys per shard to get an overview of your data.')
150+
})
151+
})
152+
153+
describe('Default tooltip', () => {
154+
beforeEach(() => {
155+
const state: any = store.getState()
156+
connectType(state, 'STANDALONE')
157+
})
158+
159+
it('should render default tooltip message', async () => {
160+
render(<Header {...instance(mockedProps)} />)
161+
162+
await act(async () => {
163+
fireEvent.mouseOver(screen.getByTestId('db-new-reports-icon'))
164+
})
165+
await waitForEuiToolTipVisible()
166+
167+
expect(screen.getByTestId('db-new-reports-tooltip')).toHaveTextContent('Redis Database AnalysisAnalyze up to 10 000 keys per Redis database to get an overview of your data.')
168+
})
169+
})

0 commit comments

Comments
 (0)