Skip to content

Commit feb0f92

Browse files
committed
fix AssistanceChat.spec.tsx
1 parent daa238b commit feb0f92

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

redisinsight/ui/src/components/side-panels/panels/ai-assistant/components/assistance-chat/AssistanceChat.spec.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { cloneDeep } from 'lodash'
33
import {
44
act,
55
cleanup,
6+
expectActionsToContain,
67
fireEvent,
78
mockedStore,
89
mockedStoreFn,
@@ -122,7 +123,7 @@ describe('AssistanceChat', () => {
122123
sendQuestion(expect.objectContaining({ content: 'test' })),
123124
])
124125

125-
expect(sendEventTelemetry).toBeCalledWith({
126+
expect(sendEventTelemetry).toHaveBeenCalledWith({
126127
event: TelemetryEvent.AI_CHAT_MESSAGE_SENT,
127128
eventData: {
128129
chat: AiChatType.Assistance,
@@ -155,7 +156,7 @@ describe('AssistanceChat', () => {
155156

156157
await waitForRiPopoverVisible()
157158

158-
expect(sendEventTelemetry).toBeCalledWith({
159+
expect(sendEventTelemetry).toHaveBeenCalledWith({
159160
event: TelemetryEvent.AI_CHAT_BOT_TERMS_DISPLAYED,
160161
eventData: {
161162
chat: AiChatType.Assistance,
@@ -167,7 +168,7 @@ describe('AssistanceChat', () => {
167168
fireEvent.click(screen.getByTestId('ai-accept-agreements'))
168169
})
169170

170-
expect(sendEventTelemetry).toBeCalledWith({
171+
expect(sendEventTelemetry).toHaveBeenCalledWith({
171172
event: TelemetryEvent.AI_CHAT_BOT_TERMS_ACCEPTED,
172173
eventData: {
173174
chat: AiChatType.Assistance,
@@ -204,12 +205,12 @@ describe('AssistanceChat', () => {
204205
fireEvent.click(screen.getByTestId('ai-chat-restart-confirm'))
205206
})
206207

207-
expect(store.getActions()).toEqual([
208+
expectActionsToContain(store.getActions(), [
208209
...afterRenderActions,
209210
removeAssistantChatHistory(),
210211
])
211212

212-
expect(sendEventTelemetry).toBeCalledWith({
213+
expect(sendEventTelemetry).toHaveBeenCalledWith({
213214
event: TelemetryEvent.AI_CHAT_SESSION_RESTARTED,
214215
eventData: {
215216
chat: AiChatType.Assistance,
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { http, HttpHandler, HttpResponse } from 'msw'
2+
import { ApiEndpoints } from 'uiSrc/constants'
3+
import { getMswURL } from 'uiSrc/utils/test-utils'
4+
5+
const handlers: HttpHandler[] = [
6+
http.get<{ id: string }>(
7+
getMswURL(`/${ApiEndpoints.AI_ASSISTANT_CHATS}/:id`),
8+
async ({ params }) => {
9+
const { id } = params
10+
11+
return HttpResponse.json({ id, messages: [] }, { status: 200 })
12+
},
13+
),
14+
http.post<{ id: string }, { content: string }>(
15+
getMswURL(`/${ApiEndpoints.AI_ASSISTANT_CHATS}/:id/messages`),
16+
async ({ request }) => {
17+
const { content } = await request.json()
18+
19+
return HttpResponse.json([content], { status: 200 })
20+
},
21+
),
22+
http.post<{ id: string }, { content: string }>(
23+
getMswURL(`/${ApiEndpoints.AI_ASSISTANT_CHATS}`),
24+
async ({ request }) => {
25+
const { content } = await request.json()
26+
27+
return HttpResponse.json([content], { status: 200 })
28+
},
29+
),
30+
http.delete<{ id: string }>(
31+
getMswURL(`/${ApiEndpoints.AI_ASSISTANT_CHATS}/:id`),
32+
async () => {
33+
return HttpResponse.text('', { status: 200 })
34+
},
35+
),
36+
http.options(getMswURL(`/${ApiEndpoints.AI_ASSISTANT_CHATS}*`), () => {
37+
return new Response(null, {
38+
status: 200,
39+
headers: {
40+
Allow: 'GET,HEAD,POST,DELETE',
41+
},
42+
})
43+
}),
44+
]
45+
46+
export default handlers
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { HttpHandler } from 'msw'
2+
import assistant from 'uiSrc/mocks/handlers/ai/assistantHandlers'
3+
4+
const handlers: HttpHandler[] = [...assistant]
5+
export default handlers

redisinsight/ui/src/mocks/handlers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import tutorials from './tutorials'
99
import rdi from './rdi'
1010
import user from './user'
1111
import workbench from './workbench'
12+
import ai from './ai'
1213

1314
// @ts-ignore
1415
export const handlers = [
@@ -23,4 +24,5 @@ export const handlers = [
2324
...rdi,
2425
...user,
2526
...workbench,
27+
...ai,
2628
]

0 commit comments

Comments
 (0)