Skip to content

Commit daa238b

Browse files
committed
fix FilterKeyType.spec.tsx, AddDatabaseScreen.spec.tsx, FetchPipelinePopover.spec.tsx, TemplateForm.spec.tsx
1 parent fcd106c commit daa238b

File tree

7 files changed

+83
-45
lines changed

7 files changed

+83
-45
lines changed

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,30 @@ const handlers: HttpHandler[] = [
9292
http.get(getMswURL(`${ApiEndpoints.DATABASES}/:id/connect`), async () => {
9393
return HttpResponse.text('', { status: 200 })
9494
}),
95-
]
96-
97-
// rest.post(`${ApiEndpoints.INSTANCE}`, (req, res, ctx) => {
98-
// const { username } = req.body
95+
http.post<
96+
any,
97+
{
98+
name: string
99+
host: string
100+
port: number
101+
username: string
102+
timeout: number
103+
tls: boolean
104+
},
105+
Partial<Instance>
106+
>(getMswURL(`${ApiEndpoints.DATABASES}`), async ({ request }) => {
107+
const { username } = await request.json()
99108

100-
// return res(
101-
// ctx.json({
102-
// id: 'f79e82e8-c34a-4dc7-a49e-9fadc0979fda',
103-
// username,
104-
// firstName: 'John',
105-
// lastName: 'Maverick',
106-
// }),
107-
// )
108-
// }),
109+
return HttpResponse.json(
110+
{
111+
id: 'f79e82e8-c34a-4dc7-a49e-9fadc0979fda',
112+
username,
113+
host: 'localhost',
114+
port: 6379,
115+
},
116+
{ status: 201 },
117+
)
118+
}),
119+
]
109120

110121
export default handlers

redisinsight/ui/src/mocks/handlers/rdi/rdiHandler.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,36 @@ import { http, HttpHandler, HttpResponse } from 'msw'
22
import { getMswURL } from 'uiSrc/utils/test-utils'
33
import { getUrl } from 'uiSrc/utils'
44
import { ApiEndpoints } from 'uiSrc/constants'
5-
import { Rdi as RdiInstanceResponse } from 'apiSrc/modules/rdi/models/rdi'
65

76
const handlers: HttpHandler[] = [
87
// fetch rdi instances
9-
http.get<any, RdiInstanceResponse[]>(
10-
getMswURL(getUrl(ApiEndpoints.RDI_INSTANCES)),
8+
http.get(getMswURL(getUrl(ApiEndpoints.RDI_INSTANCES)), async () => {
9+
return HttpResponse.json(
10+
[
11+
{
12+
id: '1',
13+
name: 'My first integration',
14+
url: 'redis-12345.c253.us-central1-1.gce.cloud.redislabs.com:12345',
15+
lastConnection: new Date(),
16+
version: '1.2',
17+
type: 'api',
18+
username: 'user',
19+
},
20+
],
21+
{ status: 200 },
22+
)
23+
}),
24+
http.get(
25+
getMswURL(`/${ApiEndpoints.RDI_INSTANCES}/:id/pipeline`),
1126
async () => {
1227
return HttpResponse.json(
13-
[
14-
{
15-
id: '1',
16-
name: 'My first integration',
17-
url: 'redis-12345.c253.us-central1-1.gce.cloud.redislabs.com:12345',
18-
lastConnection: new Date(),
19-
version: '1.2',
20-
type: 'api',
21-
username: 'user',
22-
},
23-
],
28+
{
29+
jobs: [
30+
{ name: 'job1', value: 'value' },
31+
{ name: 'job2', value: 'value' },
32+
],
33+
config: { field: 'value' },
34+
},
2435
{ status: 200 },
2536
)
2637
},

redisinsight/ui/src/pages/browser/components/filter-key-type/FilterKeyType.spec.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { cloneDeep, set } from 'lodash'
22
import React from 'react'
33
import {
44
cleanup,
5-
clearStoreActions,
5+
expectActionsToContain,
66
fireEvent,
77
initialStateDefault,
88
mockedStore,
@@ -68,10 +68,13 @@ describe('FilterKeyType', () => {
6868
await userEvent.click(screen.getByTestId(filterSelectId))
6969
await userEvent.click(await findByText('Hash'))
7070

71-
const expectedActions = [setFilter(KeyTypes.Hash), resetBrowserTree(), loadKeys()]
72-
expect(clearStoreActions(store.getActions())).toEqual(
73-
clearStoreActions(expectedActions),
74-
)
71+
const expectedActions = [
72+
setFilter(KeyTypes.Hash),
73+
resetBrowserTree(),
74+
loadKeys(),
75+
]
76+
77+
expectActionsToContain(store.getActions(), expectedActions)
7578
})
7679

7780
it('should be disabled filter with database redis version < 6.0', () => {

redisinsight/ui/src/pages/home/components/add-database-screen/AddDatabaseScreen.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
mockedStore,
99
cleanup,
1010
act,
11+
expectActionsToContain,
1112
} from 'uiSrc/utils/test-utils'
1213

1314
import { defaultInstanceChanging } from 'uiSrc/slices/instances/instances'
@@ -35,7 +36,7 @@ describe('AddDatabaseScreen', () => {
3536
fireEvent.click(screen.getByTestId('btn-submit'))
3637
})
3738

38-
expect(store.getActions()).toEqual([defaultInstanceChanging()])
39+
expectActionsToContain(store.getActions(), [defaultInstanceChanging()])
3940
})
4041

4142
it('should disable test connection and submit buttons when connection url is invalid', async () => {

redisinsight/ui/src/pages/rdi/instance/components/header/components/fetch-pipeline-popover/FetchPipelinePopover.spec.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { cloneDeep } from 'lodash'
33
import {
44
act,
55
cleanup,
6+
expectActionsToContain,
67
fireEvent,
78
mockedStore,
89
render,
910
screen,
11+
userEvent,
1012
} from 'uiSrc/utils/test-utils'
1113
import { getPipeline, rdiPipelineSelector } from 'uiSrc/slices/rdi/pipeline'
1214
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
@@ -57,26 +59,24 @@ describe('FetchPipelinePopover', () => {
5759

5860
expect(screen.queryByTestId('confirm-btn')).not.toBeInTheDocument()
5961

60-
await act(() => {
61-
fireEvent.click(screen.getByTestId('upload-pipeline-btn'))
62-
})
62+
await userEvent.click(screen.getByTestId('upload-pipeline-btn'))
6363

6464
expect(screen.queryByTestId('upload-confirm-btn')).toBeInTheDocument()
6565
})
6666

6767
it('should call proper actions', async () => {
6868
render(<FetchPipelinePopover />)
6969

70-
await act(() => {
70+
await act(async () => {
7171
fireEvent.click(screen.getByTestId('upload-pipeline-btn'))
7272
})
7373

74-
await act(() => {
74+
await act(async () => {
7575
fireEvent.click(screen.getByTestId('upload-confirm-btn'))
7676
})
7777

7878
const expectedActions = [getPipeline()]
79-
expect(store.getActions()).toEqual(expectedActions)
79+
expectActionsToContain(store.getActions(), expectedActions)
8080
})
8181

8282
it('should call proper telemetry event', async () => {
@@ -87,11 +87,11 @@ describe('FetchPipelinePopover', () => {
8787

8888
render(<FetchPipelinePopover />)
8989

90-
await act(() => {
90+
await act(async () => {
9191
fireEvent.click(screen.getByTestId('upload-pipeline-btn'))
9292
})
9393

94-
expect(sendEventTelemetry).toBeCalledWith({
94+
expect(sendEventTelemetry).toHaveBeenCalledWith({
9595
event: TelemetryEvent.RDI_PIPELINE_UPLOAD_FROM_SERVER_CLICKED,
9696
eventData: {
9797
id: 'rdiInstanceId',

redisinsight/ui/src/pages/rdi/pipeline-management/components/template-form/TemplateForm.spec.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { instance, mock } from 'ts-mockito'
55
import {
66
act,
77
cleanup,
8+
expectActionsToContain,
89
fireEvent,
910
mockedStore,
1011
render,
@@ -66,11 +67,9 @@ describe('TemplateForm', () => {
6667
render(<TemplateForm {...instance(mockedProps)} />)
6768
})
6869

69-
const expectedActions = getPipelineStrategies()
70+
const expectedActions = [getPipelineStrategies()]
7071

71-
expect(store.getActions()).toEqual(
72-
expect.arrayContaining([expectedActions]),
73-
)
72+
expectActionsToContain(store.getActions(), expectedActions)
7473
})
7574

7675
it('apply btn should be disabled if there is any value', () => {

redisinsight/ui/src/utils/test-utils.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,18 @@ export const mockFeatureFlags = (
442442
})
443443
}
444444

445+
/**
446+
* Helper function to check if expected actions are contained within actual store actions
447+
* @param actualActions - The actual actions dispatched to the store
448+
* @param expectedActions - The expected actions that should be present
449+
*/
450+
const expectActionsToContain = (
451+
actualActions: any[],
452+
expectedActions: any[],
453+
) => {
454+
expect(actualActions).toEqual(expect.arrayContaining(expectedActions))
455+
}
456+
445457
// re-export everything
446458
export * from '@testing-library/react'
447459
// override render method
@@ -455,4 +467,5 @@ export {
455467
waitForRiTooltipVisible,
456468
waitForRiTooltipHidden,
457469
waitForRiPopoverVisible,
470+
expectActionsToContain,
458471
}

0 commit comments

Comments
 (0)