11import { ComponentFixture , TestBed } from '@angular/core/testing' ;
22import { ChatbotComponent } from './chatbot.component' ;
33import { ChatbotService } from './chatbot.service' ;
4- import { AwsBedRockService } from './awsBedRock.service' ;
54import { ConfigService } from '../../assets/wise5/services/configService' ;
65import { DataService } from '../services/data.service' ;
76import { ProjectService } from '../../assets/wise5/services/projectService' ;
87import { BreakpointObserver } from '@angular/cdk/layout' ;
98import { of , throwError } from 'rxjs' ;
109import { Chat , ChatMessage } from './chat' ;
1110import { provideHttpClient } from '@angular/common/http' ;
11+ import { OpenAiChatService } from '../services/chat/openAiChat.service' ;
1212
1313describe ( 'ChatbotComponent' , ( ) => {
1414 let component : ChatbotComponent ;
1515 let fixture : ComponentFixture < ChatbotComponent > ;
1616 let chatbotService : jasmine . SpyObj < ChatbotService > ;
17- let awsBedRockService : jasmine . SpyObj < AwsBedRockService > ;
17+ let chatService : jasmine . SpyObj < OpenAiChatService > ;
1818 let configService : jasmine . SpyObj < ConfigService > ;
1919 let dataService : jasmine . SpyObj < DataService > ;
2020 let projectService : jasmine . SpyObj < ProjectService > ;
@@ -41,7 +41,7 @@ describe('ChatbotComponent', () => {
4141 'updateChat' ,
4242 'deleteChat'
4343 ] ) ;
44- const awsBedRockServiceSpy = jasmine . createSpyObj ( 'AwsBedRockService ' , [
44+ const chatServiceSpy = jasmine . createSpyObj ( 'OpenAiChatService ' , [
4545 'sendMessage' ,
4646 'generateChatTitle'
4747 ] ) ;
@@ -66,7 +66,7 @@ describe('ChatbotComponent', () => {
6666 imports : [ ChatbotComponent ] ,
6767 providers : [
6868 { provide : ChatbotService , useValue : chatbotServiceSpy } ,
69- { provide : AwsBedRockService , useValue : awsBedRockServiceSpy } ,
69+ { provide : OpenAiChatService , useValue : chatServiceSpy } ,
7070 { provide : ConfigService , useValue : configServiceSpy } ,
7171 { provide : DataService , useValue : dataServiceSpy } ,
7272 { provide : ProjectService , useValue : projectServiceSpy } ,
@@ -76,7 +76,7 @@ describe('ChatbotComponent', () => {
7676 } ) . compileComponents ( ) ;
7777
7878 chatbotService = TestBed . inject ( ChatbotService ) as jasmine . SpyObj < ChatbotService > ;
79- awsBedRockService = TestBed . inject ( AwsBedRockService ) as jasmine . SpyObj < AwsBedRockService > ;
79+ chatService = TestBed . inject ( OpenAiChatService ) as jasmine . SpyObj < OpenAiChatService > ;
8080 configService = TestBed . inject ( ConfigService ) as jasmine . SpyObj < ConfigService > ;
8181 dataService = TestBed . inject ( DataService ) as jasmine . SpyObj < DataService > ;
8282 projectService = TestBed . inject ( ProjectService ) as jasmine . SpyObj < ProjectService > ;
@@ -134,8 +134,8 @@ describe('ChatbotComponent', () => {
134134 const assistantResponse = 'Hi there!' ;
135135 component [ 'userInput' ] = userMessage ;
136136
137- awsBedRockService . sendMessage . and . returnValue ( Promise . resolve ( assistantResponse ) ) ;
138- awsBedRockService . generateChatTitle . and . returnValue ( Promise . resolve ( 'New Title' ) ) ;
137+ chatService . sendMessage . and . returnValue ( Promise . resolve ( assistantResponse ) ) ;
138+ spyOn ( component , ' generateChatTitle' ) . and . returnValue ( Promise . resolve ( 'New Title' ) ) ;
139139 await component [ 'sendMessage' ] ( ) ;
140140
141141 expect ( component [ 'messages' ] . length ) . toBe ( 2 ) ;
@@ -156,12 +156,12 @@ describe('ChatbotComponent', () => {
156156
157157 // First user message (only system message exists initially)
158158 component [ 'messages' ] = [ ] ;
159- awsBedRockService . sendMessage . and . returnValue ( Promise . resolve ( assistantResponse ) ) ;
160- awsBedRockService . generateChatTitle . and . returnValue ( Promise . resolve ( newTitle ) ) ;
159+ chatService . sendMessage . and . returnValue ( Promise . resolve ( assistantResponse ) ) ;
160+ spyOn ( component , ' generateChatTitle' ) . and . returnValue ( Promise . resolve ( newTitle ) ) ;
161161
162162 await component [ 'sendMessage' ] ( ) ;
163163
164- expect ( awsBedRockService . generateChatTitle ) . toHaveBeenCalledWith ( userMessage ) ;
164+ expect ( component [ ' generateChatTitle' ] ) . toHaveBeenCalledWith ( userMessage ) ;
165165 expect ( component [ 'currentChat' ] ?. title ) . toBe ( newTitle ) ;
166166 expect ( chatbotService . updateChat ) . toHaveBeenCalled ( ) ;
167167 } ) ;
@@ -171,7 +171,7 @@ describe('ChatbotComponent', () => {
171171
172172 await component [ 'sendMessage' ] ( ) ;
173173
174- expect ( awsBedRockService . sendMessage ) . not . toHaveBeenCalled ( ) ;
174+ expect ( chatService . sendMessage ) . not . toHaveBeenCalled ( ) ;
175175 expect ( component [ 'messages' ] . length ) . toBe ( 0 ) ;
176176 } ) ;
177177
@@ -181,7 +181,7 @@ describe('ChatbotComponent', () => {
181181
182182 await component [ 'sendMessage' ] ( ) ;
183183
184- expect ( awsBedRockService . sendMessage ) . not . toHaveBeenCalled ( ) ;
184+ expect ( chatService . sendMessage ) . not . toHaveBeenCalled ( ) ;
185185 } ) ;
186186
187187 it ( 'should not send messages when no current chat' , async ( ) => {
@@ -190,12 +190,12 @@ describe('ChatbotComponent', () => {
190190
191191 await component [ 'sendMessage' ] ( ) ;
192192
193- expect ( awsBedRockService . sendMessage ) . not . toHaveBeenCalled ( ) ;
193+ expect ( chatService . sendMessage ) . not . toHaveBeenCalled ( ) ;
194194 } ) ;
195195
196196 it ( 'should handle errors when sending messages' , async ( ) => {
197197 component [ 'userInput' ] = 'Hello' ;
198- awsBedRockService . sendMessage . and . returnValue ( Promise . reject ( new Error ( 'API error' ) ) ) ;
198+ chatService . sendMessage . and . returnValue ( Promise . reject ( new Error ( 'API error' ) ) ) ;
199199
200200 await component [ 'sendMessage' ] ( ) ;
201201
@@ -336,8 +336,8 @@ describe('ChatbotComponent', () => {
336336
337337 it ( 'should send message on Enter key press' , ( ) => {
338338 component [ 'userInput' ] = 'Hello' ;
339- awsBedRockService . sendMessage . and . returnValue ( Promise . resolve ( 'Response' ) ) ;
340- awsBedRockService . generateChatTitle . and . returnValue ( Promise . resolve ( 'New Title' ) ) ;
339+ chatService . sendMessage . and . returnValue ( Promise . resolve ( 'Response' ) ) ;
340+ spyOn ( component , ' generateChatTitle' ) . and . returnValue ( Promise . resolve ( 'New Title' ) ) ;
341341
342342 const event = new KeyboardEvent ( 'keypress' , { key : 'Enter' } ) ;
343343 spyOn ( event , 'preventDefault' ) ;
@@ -356,7 +356,7 @@ describe('ChatbotComponent', () => {
356356 component [ 'handleKeyPress' ] ( event ) ;
357357
358358 expect ( event . preventDefault ) . not . toHaveBeenCalled ( ) ;
359- expect ( awsBedRockService . sendMessage ) . not . toHaveBeenCalled ( ) ;
359+ expect ( chatService . sendMessage ) . not . toHaveBeenCalled ( ) ;
360360 } ) ;
361361 } ) ;
362362
0 commit comments