|
1 | 1 | import React from 'react'
|
2 | 2 | import { cloneDeep } from 'lodash'
|
| 3 | +import { useSelector } from 'react-redux' |
3 | 4 | import { instance, mock } from 'ts-mockito'
|
4 | 5 | import { getDBAnalysis } from 'uiSrc/slices/analytics/dbAnalysis'
|
| 6 | +import { RootState } from 'uiSrc/slices/store' |
5 | 7 | import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
|
6 | 8 | import { INSTANCE_ID_MOCK } from 'uiSrc/mocks/handlers/analytics/clusterDetailsHandlers'
|
7 | 9 |
|
8 | 10 | import {
|
| 11 | + act, |
9 | 12 | cleanup,
|
10 | 13 | mockedStore,
|
11 | 14 | fireEvent,
|
12 | 15 | render,
|
13 | 16 | screen,
|
| 17 | + waitForEuiToolTipVisible, |
14 | 18 | } from 'uiSrc/utils/test-utils'
|
15 | 19 |
|
16 | 20 | import Header, { Props } from './Header'
|
@@ -41,7 +45,33 @@ jest.mock('uiSrc/telemetry', () => ({
|
41 | 45 | sendEventTelemetry: jest.fn(),
|
42 | 46 | }))
|
43 | 47 |
|
| 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 | + |
44 | 69 | describe('DatabaseAnalysisHeader', () => {
|
| 70 | + beforeEach(() => { |
| 71 | + const state: any = store.getState() |
| 72 | + connectType(state, 'STANDALONE') |
| 73 | + }) |
| 74 | + |
45 | 75 | it('should render', () => {
|
46 | 76 | expect(render(<Header {...instance(mockedProps)} />)).toBeTruthy()
|
47 | 77 | })
|
@@ -101,3 +131,39 @@ describe('DatabaseAnalysisHeader', () => {
|
101 | 131 | expect(onChangeSelectedAnalysis).toBeCalled()
|
102 | 132 | })
|
103 | 133 | })
|
| 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