Skip to content

Commit fcd106c

Browse files
committed
fix AutoRefresh.spec.tsx, OAuthConnectFreeDb.spec.tsx
1 parent 6fba2c6 commit fcd106c

File tree

3 files changed

+27
-41
lines changed

3 files changed

+27
-41
lines changed

redisinsight/ui/src/components/auto-refresh/AutoRefresh.spec.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('AutoRefresh', () => {
6363
render(<AutoRefresh {...instance(mockedProps)} onRefresh={onRefresh} />)
6464

6565
fireEvent.click(screen.getByTestId('refresh-btn'))
66-
expect(onRefresh).toBeCalled()
66+
expect(onRefresh).toHaveBeenCalled()
6767
})
6868

6969
it('refresh text should contain "Last refresh" time with disabled auto-refresh', async () => {
@@ -170,22 +170,23 @@ describe('AutoRefresh', () => {
170170
})
171171
expect(screen.getByTestId(INLINE_ITEM_EDITOR)).toHaveValue('1')
172172

173-
screen.getByTestId(/apply-btn/).click()
173+
await userEvent.click(screen.getByTestId(/apply-btn/))
174+
// screen.getByTestId(/apply-btn/).click()
174175

175176
await act(async () => {
176177
await new Promise((r) => setTimeout(r, 1300))
177178
})
178-
expect(onRefresh).toBeCalledTimes(1)
179+
expect(onRefresh).toHaveBeenCalledTimes(1)
179180

180181
await act(async () => {
181182
await new Promise((r) => setTimeout(r, 1300))
182183
})
183-
expect(onRefresh).toBeCalledTimes(2)
184+
expect(onRefresh).toHaveBeenCalledTimes(2)
184185

185186
await act(async () => {
186187
await new Promise((r) => setTimeout(r, 1300))
187188
})
188-
expect(onRefresh).toBeCalledTimes(3)
189+
expect(onRefresh).toHaveBeenCalledTimes(3)
189190
})
190191

191192
it('should respect minimumRefreshRate when setting refresh rate', async () => {
@@ -279,7 +280,7 @@ describe('AutoRefresh', () => {
279280

280281
screen.getByTestId(/apply-btn/).click()
281282

282-
await act(() => {
283+
await act(async () => {
283284
rerender(
284285
<AutoRefresh
285286
{...instance(mockedProps)}
@@ -292,14 +293,14 @@ describe('AutoRefresh', () => {
292293
await act(async () => {
293294
await new Promise((r) => setTimeout(r, 1300))
294295
})
295-
expect(onRefresh).toBeCalledTimes(0)
296+
expect(onRefresh).toHaveBeenCalledTimes(0)
296297

297298
await act(async () => {
298299
await new Promise((r) => setTimeout(r, 1300))
299300
})
300-
expect(onRefresh).toBeCalledTimes(0)
301+
expect(onRefresh).toHaveBeenCalledTimes(0)
301302

302-
await act(() => {
303+
await act(async () => {
303304
rerender(
304305
<AutoRefresh
305306
{...instance(mockedProps)}
@@ -312,7 +313,7 @@ describe('AutoRefresh', () => {
312313
await act(async () => {
313314
await new Promise((r) => setTimeout(r, 1300))
314315
})
315-
expect(onRefresh).toBeCalledTimes(1)
316+
expect(onRefresh).toHaveBeenCalledTimes(1)
316317
})
317318

318319
it('refresh tooltip text should contain disabled refresh button reason message when button disabled', async () => {

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import React from 'react'
22
import { cloneDeep } from 'lodash'
3-
import {
4-
act,
5-
cleanup,
6-
fireEvent,
7-
mockedStore,
8-
render,
9-
} from 'uiSrc/utils/test-utils'
3+
import { cleanup, mockedStore, render, userEvent } from 'uiSrc/utils/test-utils'
104
import {
115
getRedisModulesSummary,
126
sendEventTelemetry,
@@ -15,6 +9,7 @@ import {
159
import {
1610
freeInstancesSelector,
1711
setDefaultInstance,
12+
setDefaultInstanceSuccess,
1813
} from 'uiSrc/slices/instances/instances'
1914
import { OAuthSocialSource } from 'uiSrc/slices/interfaces'
2015
import { setCapability } from 'uiSrc/slices/app/context'
@@ -63,10 +58,8 @@ describe('OAuthConnectFreeDb', () => {
6358

6459
const { queryByTestId } = render(<OAuthConnectFreeDb id="providedId" />)
6560

66-
await act(() =>
67-
fireEvent.click(
68-
queryByTestId('connect-free-db-btn') as HTMLButtonElement,
69-
),
61+
await userEvent.click(
62+
queryByTestId('connect-free-db-btn') as HTMLButtonElement,
7063
)
7164

7265
expect(sendEventTelemetry).toHaveBeenCalledWith({
@@ -86,6 +79,7 @@ describe('OAuthConnectFreeDb', () => {
8679
tutorialPopoverShown: false,
8780
}),
8881
setDefaultInstance(),
82+
setDefaultInstanceSuccess(),
8983
]
9084
expect(store.getActions()).toEqual(expectedActions)
9185
})

redisinsight/ui/src/mocks/handlers/instances/instancesHandlers.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { http, HttpHandler, HttpResponse } from 'msw'
2-
import { RedisNodeInfoResponse } from 'src/modules/database/dto/redis-info.dto'
32
import { ApiEndpoints } from 'uiSrc/constants'
43
import { ConnectionType, Instance } from 'uiSrc/slices/interfaces'
54
import { getMswURL } from 'uiSrc/utils/test-utils'
65
import { getUrl } from 'uiSrc/utils'
76
import { MOCK_INFO_API_RESPONSE } from 'uiSrc/mocks/data/instances'
8-
import { Database as DatabaseInstanceResponse } from 'apiSrc/modules/database/models/database'
9-
import { ExportDatabase } from 'apiSrc/modules/database/models/export-database'
107

118
export const INSTANCE_ID_MOCK = 'instanceId'
129
export const INSTANCES_MOCK: Instance[] = [
@@ -78,29 +75,23 @@ export const getDatabasesApiSpy = jest
7875

7976
const handlers: HttpHandler[] = [
8077
// fetchInstancesAction
81-
http.get<any, DatabaseInstanceResponse[]>(
82-
getMswURL(ApiEndpoints.DATABASES),
83-
getDatabasesApiSpy,
84-
),
85-
http.post<any, ExportDatabase>(
86-
getMswURL(ApiEndpoints.DATABASES_EXPORT),
87-
async () => {
88-
return HttpResponse.json(INSTANCES_MOCK, { status: 200 })
89-
},
90-
),
91-
http.get<any, DatabaseInstanceResponse>(
92-
getMswURL(getUrl(INSTANCE_ID_MOCK)),
93-
async () => {
94-
return HttpResponse.json(INSTANCES_MOCK[0], { status: 200 })
95-
},
96-
),
97-
http.get<any, RedisNodeInfoResponse>(
78+
http.get(getMswURL(ApiEndpoints.DATABASES), getDatabasesApiSpy),
79+
http.post(getMswURL(ApiEndpoints.DATABASES_EXPORT), async () => {
80+
return HttpResponse.json(INSTANCES_MOCK, { status: 200 })
81+
}),
82+
http.get(getMswURL(getUrl(INSTANCE_ID_MOCK)), async () => {
83+
return HttpResponse.json(INSTANCES_MOCK[0], { status: 200 })
84+
}),
85+
http.get(
9886
getMswURL(`/${ApiEndpoints.DATABASES}/:id/info`),
9987
// getMswURL(getUrl(INSTANCE_ID_MOCK, 'info')),
10088
async () => {
10189
return HttpResponse.json(MOCK_INFO_API_RESPONSE, { status: 200 })
10290
},
10391
),
92+
http.get(getMswURL(`${ApiEndpoints.DATABASES}/:id/connect`), async () => {
93+
return HttpResponse.text('', { status: 200 })
94+
}),
10495
]
10596

10697
// rest.post(`${ApiEndpoints.INSTANCE}`, (req, res, ctx) => {

0 commit comments

Comments
 (0)