Skip to content

Commit 536fbe8

Browse files
committed
#RI-4810 - fix unit tests
1 parent 8b4e418 commit 536fbe8

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

redisinsight/ui/src/components/live-time-recommendations/components/recommendation/Recommendation.spec.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Pages } from 'uiSrc/constants'
99
import { updateRecommendation } from 'uiSrc/slices/recommendations/recommendations'
1010
import { INSTANCE_ID_MOCK } from 'uiSrc/mocks/handlers/instances/instancesHandlers'
1111
import { MOCK_RECOMMENDATIONS } from 'uiSrc/constants/mocks/mock-recommendations'
12+
import { openNewWindowDatabase } from 'uiSrc/utils'
1213
import Recommendation, { IProps } from './Recommendation'
1314

1415
const recommendationsContent = MOCK_RECOMMENDATIONS
@@ -24,6 +25,11 @@ jest.mock('uiSrc/telemetry', () => ({
2425
sendEventTelemetry: jest.fn(),
2526
}))
2627

28+
jest.mock('uiSrc/utils', () => ({
29+
...jest.requireActual('uiSrc/utils'),
30+
openNewWindowDatabase: jest.fn(),
31+
}))
32+
2733
let store: typeof mockedStore
2834
beforeEach(() => {
2935
cleanup()
@@ -88,10 +94,10 @@ describe('Recommendation', () => {
8894
sendEventTelemetry.mockRestore()
8995
})
9096

91-
it('should properly push history on workbench page to specific guide', () => {
97+
it('should properly call openNewWindowDatabase and open a new window on workbench page to specific guide', () => {
9298
// will be improved
93-
const pushMock = jest.fn()
94-
reactRouterDom.useHistory = jest.fn().mockReturnValue({ push: pushMock })
99+
const openNewWindowDatabaseMock = jest.fn();
100+
(openNewWindowDatabase as jest.Mock).mockImplementation(() => openNewWindowDatabaseMock)
95101

96102
const { container } = render(
97103
<Recommendation
@@ -106,7 +112,7 @@ describe('Recommendation', () => {
106112
fireEvent.click(container.querySelector('[data-test-subj="searchJSON-button"]') as HTMLButtonElement)
107113
fireEvent.click(screen.getByTestId('searchJSON-to-tutorial-btn'))
108114

109-
expect(pushMock)
115+
expect(openNewWindowDatabase)
110116
.toHaveBeenCalledWith(`${Pages.workbench(INSTANCE_ID_MOCK)}?guidePath=quick-guides/working-with-hash.html`)
111117
expect(sendEventTelemetry).toBeCalledWith({
112118
event: TelemetryEvent.INSIGHTS_RECOMMENDATION_TUTORIAL_CLICKED,
@@ -117,12 +123,13 @@ describe('Recommendation', () => {
117123
}
118124
})
119125
sendEventTelemetry.mockRestore()
126+
openNewWindowDatabase.mockRestore()
120127
})
121128

122129
it('should properly push history on workbench page to specific tutorial', () => {
123130
// will be improved
124-
const pushMock = jest.fn()
125-
reactRouterDom.useHistory = jest.fn().mockReturnValue({ push: pushMock })
131+
const openNewWindowDatabaseMock = jest.fn();
132+
(openNewWindowDatabase as jest.Mock).mockImplementation(() => openNewWindowDatabaseMock)
126133

127134
const { container } = render(
128135
<Recommendation
@@ -137,7 +144,7 @@ describe('Recommendation', () => {
137144
fireEvent.click(container.querySelector('[data-test-subj="searchJSON-button"]') as HTMLButtonElement)
138145
fireEvent.click(screen.getByTestId('searchJSON-to-tutorial-btn'))
139146

140-
expect(pushMock)
147+
expect(openNewWindowDatabase)
141148
.toHaveBeenCalledWith(`${Pages.workbench(INSTANCE_ID_MOCK)}?guidePath=/redis_stack/working_with_json.md`)
142149
expect(sendEventTelemetry).toBeCalledWith({
143150
event: TelemetryEvent.INSIGHTS_RECOMMENDATION_TUTORIAL_CLICKED,
@@ -148,6 +155,7 @@ describe('Recommendation', () => {
148155
}
149156
})
150157
sendEventTelemetry.mockRestore()
158+
openNewWindowDatabase.mockRestore()
151159
})
152160

153161
it('should render hide/unhide button', () => {

redisinsight/ui/src/components/oauth/oauth-connect-free-db/OAuthConnectFreeDb.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('OAuthConnectFreeDb', () => {
5656
}
5757
})
5858

59-
const expectedActions = [setDefaultInstance(), resetConnectedInstance()]
59+
const expectedActions = [setDefaultInstance()]
6060
expect(store.getActions()).toEqual(expectedActions)
6161
})
6262

redisinsight/ui/src/pages/databaseAnalysis/components/recommendations-view/Recommendations.spec.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import React from 'react'
2-
import reactRouterDom from 'react-router-dom'
32
import { fireEvent, render, screen } from 'uiSrc/utils/test-utils'
43
import { dbAnalysisSelector } from 'uiSrc/slices/analytics/dbAnalysis'
54
import { INSTANCE_ID_MOCK } from 'uiSrc/mocks/handlers/analytics/clusterDetailsHandlers'
65
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
76
import { recommendationsSelector } from 'uiSrc/slices/recommendations/recommendations'
87

98
import { MOCK_RECOMMENDATIONS } from 'uiSrc/constants/mocks/mock-recommendations'
9+
import { openNewWindowDatabase } from 'uiSrc/utils'
1010
import Recommendations from './Recommendations'
1111

1212
const recommendationsContent = MOCK_RECOMMENDATIONS
1313
const mockdbAnalysisSelector = jest.requireActual('uiSrc/slices/analytics/dbAnalysis')
1414
const mockRecommendationsSelector = jest.requireActual('uiSrc/slices/recommendations/recommendations')
1515

16+
jest.mock('uiSrc/utils', () => ({
17+
...jest.requireActual('uiSrc/utils'),
18+
openNewWindowDatabase: jest.fn(),
19+
}))
20+
1621
jest.mock('uiSrc/telemetry', () => ({
1722
...jest.requireActual('uiSrc/telemetry'),
1823
sendEventTelemetry: jest.fn(),
@@ -470,8 +475,8 @@ describe('Recommendations', () => {
470475
})
471476

472477
it('should call proper telemetry after click go tutorial button', () => {
473-
const pushMock = jest.fn()
474-
reactRouterDom.useHistory = jest.fn().mockReturnValue({ push: pushMock });
478+
const openNewWindowDatabaseMock = jest.fn();
479+
(openNewWindowDatabase as jest.Mock).mockImplementation(() => openNewWindowDatabaseMock);
475480

476481
(dbAnalysisSelector as jest.Mock).mockImplementation(() => ({
477482
...mockdbAnalysisSelector,
@@ -485,6 +490,7 @@ describe('Recommendations', () => {
485490
expect(screen.getByTestId('bigHashes-to-tutorial-btn')).toBeInTheDocument()
486491
fireEvent.click(screen.getByTestId('bigHashes-to-tutorial-btn'))
487492

488-
expect(pushMock).toBeCalledWith('/instanceId/workbench?guidePath=/quick-guides/document/introduction.md')
493+
expect(openNewWindowDatabase).toBeCalledWith('/instanceId/workbench?guidePath=/quick-guides/document/introduction.md')
494+
openNewWindowDatabase.mockRestore()
489495
})
490496
})

redisinsight/ui/src/pages/databaseAnalysis/components/recommendations-view/Recommendations.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ import { resetWorkbenchEASearch, setWorkbenchEAMinimized } from 'uiSrc/slices/ap
2828
import { EXTERNAL_LINKS } from 'uiSrc/constants/links'
2929
import { RecommendationVoting, RecommendationCopyComponent } from 'uiSrc/components'
3030
import { recommendationsSelector } from 'uiSrc/slices/recommendations/recommendations'
31+
import { openNewWindowDatabase } from 'uiSrc/utils'
3132

3233
import {
3334
sortRecommendations,
3435
renderRecommendationBadgesLegend,
3536
renderRecommendationBadges,
3637
renderRecommendationContent,
3738
} from 'uiSrc/utils/recommendation/utils'
38-
import { openNewWindowDatabase } from 'uiSrc/utils'
3939

4040
import styles from './styles.module.scss'
4141

0 commit comments

Comments
 (0)