1
1
import { act , render , screen } from "@testing-library/react"
2
2
import user from "@testing-library/user-event"
3
3
import { AiDrawerManager } from "./AiDrawerManager"
4
- import type { AiDrawerInitMessage } from "./AiDrawerManager"
4
+ import type {
5
+ AiDrawerInitMessage ,
6
+ AiDrawerManagerProps ,
7
+ } from "./AiDrawerManager"
5
8
import { ThemeProvider } from "../../components/ThemeProvider/ThemeProvider"
6
9
import * as React from "react"
7
10
import { http , HttpResponse } from "msw"
@@ -69,6 +72,17 @@ const assertTrackingEvent = (...data: unknown[]) => {
69
72
} )
70
73
trackingEvent . mockClear ( )
71
74
}
75
+ const getTrackingClient = ( ) => ( {
76
+ post : ( url : string , data : unknown ) => {
77
+ fetch ( url , {
78
+ method : "POST" ,
79
+ headers : {
80
+ "Content-Type" : "application/json" ,
81
+ } ,
82
+ body : JSON . stringify ( data ) ,
83
+ } )
84
+ } ,
85
+ } )
72
86
73
87
describe ( "AiDrawerManager" , ( ) => {
74
88
const server = setupServer (
@@ -95,12 +109,18 @@ describe("AiDrawerManager", () => {
95
109
96
110
afterAll ( ( ) => server . close ( ) )
97
111
98
- const setup = async ( message : AiDrawerInitMessage ) => {
112
+ const setup = async (
113
+ message : AiDrawerInitMessage ,
114
+ props : Partial < AiDrawerManagerProps > = { } ,
115
+ ) => {
99
116
server . listen ( )
100
117
101
- render ( < AiDrawerManager messageOrigin = "http://localhost:6006" /> , {
102
- wrapper : ThemeProvider ,
103
- } )
118
+ render (
119
+ < AiDrawerManager messageOrigin = "http://localhost:6006" { ...props } /> ,
120
+ {
121
+ wrapper : ThemeProvider ,
122
+ } ,
123
+ )
104
124
105
125
await screen . findByTestId ( "ai-drawer-manager-waiting" )
106
126
@@ -330,26 +350,31 @@ describe("AiDrawerManager", () => {
330
350
test ( "Sending Tracking Events [Video]" , async ( ) => {
331
351
const blockUsageKey = faker . string . uuid ( )
332
352
const eventPrefix = "ol_openedx_chat.drawer"
333
- await setup ( {
334
- type : "smoot-design::ai-drawer-open" ,
335
- payload : {
336
- blockType : "video" ,
337
- blockUsageKey,
338
- trackingUrl : TEST_TRACKING_EVENTS ,
339
- chat : {
340
- entryScreenTitle : "Entry screen title" ,
341
- apiUrl : TEST_API_STREAMING ,
342
- conversationStarters : [
343
- { content : "Prompt 1" } ,
344
- { content : "Prompt 2" } ,
345
- { content : "Prompt 3" } ,
346
- ] ,
347
- } ,
348
- summary : {
349
- apiUrl : CONTENT_FILE_URL ,
353
+ await setup (
354
+ {
355
+ type : "smoot-design::ai-drawer-open" ,
356
+ payload : {
357
+ blockType : "video" ,
358
+ blockUsageKey,
359
+ trackingUrl : TEST_TRACKING_EVENTS ,
360
+ chat : {
361
+ entryScreenTitle : "Entry screen title" ,
362
+ apiUrl : TEST_API_STREAMING ,
363
+ conversationStarters : [
364
+ { content : "Prompt 1" } ,
365
+ { content : "Prompt 2" } ,
366
+ { content : "Prompt 3" } ,
367
+ ] ,
368
+ } ,
369
+ summary : {
370
+ apiUrl : CONTENT_FILE_URL ,
371
+ } ,
350
372
} ,
351
373
} ,
352
- } )
374
+ {
375
+ getTrackingClient,
376
+ } ,
377
+ )
353
378
354
379
assertTrackingEvent ( {
355
380
event_type : `${ eventPrefix } .${ TrackingEventType . Open } ` ,
@@ -403,23 +428,28 @@ describe("AiDrawerManager", () => {
403
428
test ( "Sending Tracking Events [Problem]" , async ( ) => {
404
429
const blockUsageKey = faker . string . uuid ( )
405
430
const eventPrefix = "ol_openedx_chat.drawer"
406
- const { open } = await setup ( {
407
- type : "smoot-design::ai-drawer-open" ,
408
- payload : {
409
- blockType : "problem" ,
410
- blockUsageKey,
411
- trackingUrl : TEST_TRACKING_EVENTS ,
412
- chat : {
413
- entryScreenTitle : "Entry screen title" ,
414
- apiUrl : TEST_API_STREAMING ,
415
- conversationStarters : [
416
- { content : "Prompt 1" } ,
417
- { content : "Prompt 2" } ,
418
- { content : "Prompt 3" } ,
419
- ] ,
431
+ const { open } = await setup (
432
+ {
433
+ type : "smoot-design::ai-drawer-open" ,
434
+ payload : {
435
+ blockType : "problem" ,
436
+ blockUsageKey,
437
+ trackingUrl : TEST_TRACKING_EVENTS ,
438
+ chat : {
439
+ entryScreenTitle : "Entry screen title" ,
440
+ apiUrl : TEST_API_STREAMING ,
441
+ conversationStarters : [
442
+ { content : "Prompt 1" } ,
443
+ { content : "Prompt 2" } ,
444
+ { content : "Prompt 3" } ,
445
+ ] ,
446
+ } ,
420
447
} ,
421
448
} ,
422
- } )
449
+ {
450
+ getTrackingClient,
451
+ } ,
452
+ )
423
453
424
454
assertTrackingEvent ( {
425
455
event_type : `${ eventPrefix } .${ TrackingEventType . Open } ` ,
0 commit comments