@@ -9,6 +9,7 @@ import { Pages } from 'uiSrc/constants'
9
9
import { updateRecommendation } from 'uiSrc/slices/recommendations/recommendations'
10
10
import { INSTANCE_ID_MOCK } from 'uiSrc/mocks/handlers/instances/instancesHandlers'
11
11
import { MOCK_RECOMMENDATIONS } from 'uiSrc/constants/mocks/mock-recommendations'
12
+ import { openNewWindowDatabase } from 'uiSrc/utils'
12
13
import Recommendation , { IProps } from './Recommendation'
13
14
14
15
const recommendationsContent = MOCK_RECOMMENDATIONS
@@ -24,6 +25,11 @@ jest.mock('uiSrc/telemetry', () => ({
24
25
sendEventTelemetry : jest . fn ( ) ,
25
26
} ) )
26
27
28
+ jest . mock ( 'uiSrc/utils' , ( ) => ( {
29
+ ...jest . requireActual ( 'uiSrc/utils' ) ,
30
+ openNewWindowDatabase : jest . fn ( ) ,
31
+ } ) )
32
+
27
33
let store : typeof mockedStore
28
34
beforeEach ( ( ) => {
29
35
cleanup ( )
@@ -88,10 +94,10 @@ describe('Recommendation', () => {
88
94
sendEventTelemetry . mockRestore ( )
89
95
} )
90
96
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' , ( ) => {
92
98
// 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 )
95
101
96
102
const { container } = render (
97
103
< Recommendation
@@ -106,7 +112,7 @@ describe('Recommendation', () => {
106
112
fireEvent . click ( container . querySelector ( '[data-test-subj="searchJSON-button"]' ) as HTMLButtonElement )
107
113
fireEvent . click ( screen . getByTestId ( 'searchJSON-to-tutorial-btn' ) )
108
114
109
- expect ( pushMock )
115
+ expect ( openNewWindowDatabase )
110
116
. toHaveBeenCalledWith ( `${ Pages . workbench ( INSTANCE_ID_MOCK ) } ?guidePath=quick-guides/working-with-hash.html` )
111
117
expect ( sendEventTelemetry ) . toBeCalledWith ( {
112
118
event : TelemetryEvent . INSIGHTS_RECOMMENDATION_TUTORIAL_CLICKED ,
@@ -117,12 +123,13 @@ describe('Recommendation', () => {
117
123
}
118
124
} )
119
125
sendEventTelemetry . mockRestore ( )
126
+ openNewWindowDatabase . mockRestore ( )
120
127
} )
121
128
122
129
it ( 'should properly push history on workbench page to specific tutorial' , ( ) => {
123
130
// 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 )
126
133
127
134
const { container } = render (
128
135
< Recommendation
@@ -137,7 +144,7 @@ describe('Recommendation', () => {
137
144
fireEvent . click ( container . querySelector ( '[data-test-subj="searchJSON-button"]' ) as HTMLButtonElement )
138
145
fireEvent . click ( screen . getByTestId ( 'searchJSON-to-tutorial-btn' ) )
139
146
140
- expect ( pushMock )
147
+ expect ( openNewWindowDatabase )
141
148
. toHaveBeenCalledWith ( `${ Pages . workbench ( INSTANCE_ID_MOCK ) } ?guidePath=/redis_stack/working_with_json.md` )
142
149
expect ( sendEventTelemetry ) . toBeCalledWith ( {
143
150
event : TelemetryEvent . INSIGHTS_RECOMMENDATION_TUTORIAL_CLICKED ,
@@ -148,6 +155,7 @@ describe('Recommendation', () => {
148
155
}
149
156
} )
150
157
sendEventTelemetry . mockRestore ( )
158
+ openNewWindowDatabase . mockRestore ( )
151
159
} )
152
160
153
161
it ( 'should render hide/unhide button' , ( ) => {
0 commit comments