@@ -10,6 +10,7 @@ import {
1010} from '@mongodb-js/testing-library-compass' ;
1111import {
1212 CompassAssistantProvider ,
13+ createDefaultChat ,
1314 useAssistantActions ,
1415 type AssistantMessage ,
1516} from './compass-assistant-provider' ;
@@ -24,8 +25,10 @@ import {
2425import type { AtlasAuthService } from '@mongodb-js/atlas-service/provider' ;
2526import type { AtlasService } from '@mongodb-js/atlas-service/provider' ;
2627import { CompassAssistantDrawer } from './compass-assistant-drawer' ;
27- import { createMockChat } from '../test/utils' ;
28+ import { createBrokenTransport , createMockChat } from '../test/utils' ;
2829import type { AtlasAiService } from '@mongodb-js/compass-generative-ai/provider' ;
30+ import type { TrackFunction } from '@mongodb-js/compass-telemetry' ;
31+ import { createLogger } from '@mongodb-js/compass-logging' ;
2932
3033function createMockProvider ( {
3134 mockAtlasService,
@@ -463,6 +466,44 @@ describe('CompassAssistantProvider', function () {
463466 expect ( screen . queryByText ( 'Hello assistant!' ) ) . to . not . exist ;
464467 } ) ;
465468
469+ describe ( 'error handling with default chat' , function ( ) {
470+ it ( 'fires a telemetry event and displays error banner an when error occurs' , async function ( ) {
471+ const track = sinon . stub ( ) ;
472+ const chat = createDefaultChat ( {
473+ options : {
474+ transport : createBrokenTransport ( ) ,
475+ } ,
476+ originForPrompt : 'mongodb-compass' ,
477+ appNameForPrompt : 'MongoDB Compass' ,
478+ atlasService : {
479+ assistantApiEndpoint : sinon
480+ . stub ( )
481+ . returns ( 'https://localhost:3000' ) ,
482+ } as unknown as AtlasService ,
483+ logger : createLogger ( 'COMPASS-ASSISTANT-TEST' ) ,
484+ track : track as unknown as TrackFunction ,
485+ } ) ;
486+ await renderOpenAssistantDrawer ( {
487+ chat,
488+ } ) ;
489+
490+ // Send a message
491+ userEvent . type (
492+ screen . getByPlaceholderText ( 'Ask a question' ) ,
493+ 'Hello assistant!'
494+ ) ;
495+ userEvent . click ( screen . getByLabelText ( 'Send message' ) ) ;
496+
497+ await waitFor ( ( ) => {
498+ expect ( screen . getByText ( / T e s t c o n n e c t i o n e r r o r / ) ) . to . exist ;
499+ } ) ;
500+
501+ expect ( track ) . to . have . been . calledWith ( 'Assistant Response Failed' , {
502+ error_name : 'ConnectionError' ,
503+ } ) ;
504+ } ) ;
505+ } ) ;
506+
466507 describe ( 'clear chat button' , function ( ) {
467508 it ( 'is hidden when the chat is empty' , async function ( ) {
468509 const mockChat = createMockChat ( { messages : [ ] } ) ;
@@ -613,49 +654,47 @@ describe('CompassAssistantProvider', function () {
613654 } ) ;
614655 } ) ;
615656
616- describe ( 'CompassAssistantProvider' , function ( ) {
617- it ( 'uses the Atlas Service assistantApiEndpoint' , async function ( ) {
618- const mockAtlasService = {
619- assistantApiEndpoint : sinon
620- . stub ( )
621- . returns ( 'https://example.com/assistant/api/v1' ) ,
622- } ;
657+ it ( 'uses the Atlas Service assistantApiEndpoint' , async function ( ) {
658+ const mockAtlasService = {
659+ assistantApiEndpoint : sinon
660+ . stub ( )
661+ . returns ( 'https://example.com/assistant/api/v1' ) ,
662+ } ;
623663
624- const mockAtlasAiService = {
625- ensureAiFeatureAccess : sinon . stub ( ) . callsFake ( ( ) => {
626- return Promise . resolve ( ) ;
627- } ) ,
628- } ;
664+ const mockAtlasAiService = {
665+ ensureAiFeatureAccess : sinon . stub ( ) . callsFake ( ( ) => {
666+ return Promise . resolve ( ) ;
667+ } ) ,
668+ } ;
629669
630- const mockAtlasAuthService = { } ;
670+ const mockAtlasAuthService = { } ;
631671
632- const MockedProvider = CompassAssistantProvider . withMockServices ( {
633- atlasService : mockAtlasService as unknown as AtlasService ,
634- atlasAiService : mockAtlasAiService as unknown as AtlasAiService ,
635- atlasAuthService : mockAtlasAuthService as unknown as AtlasAuthService ,
636- } ) ;
672+ const MockedProvider = CompassAssistantProvider . withMockServices ( {
673+ atlasService : mockAtlasService as unknown as AtlasService ,
674+ atlasAiService : mockAtlasAiService as unknown as AtlasAiService ,
675+ atlasAuthService : mockAtlasAuthService as unknown as AtlasAuthService ,
676+ } ) ;
637677
638- render (
639- < DrawerContentProvider >
640- < DrawerAnchor />
641- < MockedProvider
642- originForPrompt = "mongodb-compass"
643- appNameForPrompt = "MongoDB Compass"
644- />
645- </ DrawerContentProvider > ,
646- {
647- preferences : {
648- enableAIAssistant : true ,
649- enableGenAIFeatures : true ,
650- enableGenAIFeaturesAtlasOrg : true ,
651- cloudFeatureRolloutAccess : { GEN_AI_COMPASS : true } ,
652- } ,
653- }
654- ) ;
678+ render (
679+ < DrawerContentProvider >
680+ < DrawerAnchor />
681+ < MockedProvider
682+ originForPrompt = "mongodb-compass"
683+ appNameForPrompt = "MongoDB Compass"
684+ />
685+ </ DrawerContentProvider > ,
686+ {
687+ preferences : {
688+ enableAIAssistant : true ,
689+ enableGenAIFeatures : true ,
690+ enableGenAIFeaturesAtlasOrg : true ,
691+ cloudFeatureRolloutAccess : { GEN_AI_COMPASS : true } ,
692+ } ,
693+ }
694+ ) ;
655695
656- await waitFor ( ( ) => {
657- expect ( mockAtlasService . assistantApiEndpoint . calledOnce ) . to . be . true ;
658- } ) ;
696+ await waitFor ( ( ) => {
697+ expect ( mockAtlasService . assistantApiEndpoint . calledOnce ) . to . be . true ;
659698 } ) ;
660699 } ) ;
661700} ) ;
0 commit comments