Skip to content

Commit 1398ca8

Browse files
authored
Merge pull request #1316 from RedisInsight/feature/RI-3699_memory_analisis_tooltip
#RI-3699-memory analisis tooltip
2 parents b66bc15 + 15c7c43 commit 1398ca8

File tree

2 files changed

+93
-2
lines changed

2 files changed

+93
-2
lines changed

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

Lines changed: 84 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,57 @@ describe('DatabaseAnalysisHeader', () => {
101131
expect(onChangeSelectedAnalysis).toBeCalled()
102132
})
103133
})
134+
135+
describe('CLUSTER db', () => {
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('STANDALONE db', () => {
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+
})
170+
171+
describe('SENTINEL db', () => {
172+
beforeEach(() => {
173+
const state: any = store.getState()
174+
connectType(state, 'SENTINEL')
175+
})
176+
177+
it('should render default tooltip message', async () => {
178+
render(<Header {...instance(mockedProps)} />)
179+
180+
await act(async () => {
181+
fireEvent.mouseOver(screen.getByTestId('db-new-reports-icon'))
182+
})
183+
await waitForEuiToolTipVisible()
184+
185+
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.')
186+
})
187+
})

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { numberWithSpaces } from 'uiSrc/utils/numbers'
2020
import { getApproximatePercentage } from 'uiSrc/utils/validations'
2121
import { BrowserStorageItem, DEFAULT_DELIMITER } from 'uiSrc/constants'
2222
import { appContextBrowserTree } from 'uiSrc/slices/app/context'
23+
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
24+
import { ConnectionType } from 'uiSrc/slices/interfaces'
2325
import AnalyticsTabs from 'uiSrc/components/analytics-tabs'
2426
import { Nullable } from 'uiSrc/utils'
2527
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
@@ -30,6 +32,9 @@ import styles from './styles.module.scss'
3032

3133
const dateFormat = 'd MMM yyyy HH:mm'
3234

35+
const commonTooltipMessage = 'Analyze up to 10 000 keys per Redis database to get an overview of your data.'
36+
const clusterTooltipMessage = 'Analyze up to 10 000 keys per shard to get an overview of your data.'
37+
3338
export interface Props {
3439
items: ShortDatabaseAnalysis[]
3540
selectedValue: Nullable<string>
@@ -47,6 +52,7 @@ const Header = (props: Props) => {
4752
analysisLoading
4853
} = props
4954

55+
const { connectionType } = useSelector(connectedInstanceSelector)
5056
const { instanceId } = useParams<{ instanceId: string }>()
5157
const dispatch = useDispatch()
5258

@@ -149,8 +155,9 @@ const Header = (props: Props) => {
149155
position="bottom"
150156
anchorClassName={styles.tooltipAnchor}
151157
className={styles.tooltip}
152-
title="Memory Efficiency"
153-
content="Analyze up to 10K keys in your Redis database to get an overview of your data and memory efficiency recommendations."
158+
title="Redis Database Analysis"
159+
content={connectionType === ConnectionType.Cluster ? clusterTooltipMessage : commonTooltipMessage}
160+
data-testid="db-new-reports-tooltip"
154161
>
155162
<EuiIcon
156163
className={styles.infoIcon}

0 commit comments

Comments
 (0)