Skip to content

Commit

Permalink
Update agent.component.spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcampagnolitg committed Aug 6, 2024
1 parent d1144c3 commit cc9e6e3
Showing 1 changed file with 70 additions and 70 deletions.
140 changes: 70 additions & 70 deletions frontend/src/app/agent/agent.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,74 +28,74 @@ describe('AgentComponent', () => {
expect(component).toBeTruthy();
});

it('should save functions and update UI', () => {
const httpClientSpy = jasmine.createSpyObj('HttpClient', ['post']);
httpClientSpy.post.and.returnValue(of({}));
component.http = httpClientSpy as any;
component.agentDetails = { functions: ['func1', 'func2', 'func3'] };
component.agentId = 'test-agent-id';
component.functionSelections = [true, false, true];
component.editMode = true;

component.saveFunctions();

expect(httpClientSpy.post).toHaveBeenCalledWith(`${environment.serverUrl}/agent/v1/update-functions`, {
agentId: 'test-agent-id',
functions: ['func1', 'func3'],
});
expect(component.editMode).toBeFalse();
expect(component.isSavingFunctions).toBeFalse();
});

it('should handle errors when saving functions', () => {
const httpClientSpy = jasmine.createSpyObj('HttpClient', ['post']);
httpClientSpy.post.and.returnValue(throwError(() => new Error('Test error')));
component.http = httpClientSpy as any;
component.agentDetails = { functions: ['func1', 'func2'] };
component.agentId = 'test-agent-id';
component.functionSelections = [true, true];
component.editMode = true;

component.saveFunctions();

expect(httpClientSpy.post).toHaveBeenCalled();
expect(component.isSavingFunctions).toBeFalse();
expect(component.editMode).toBeTrue();
});

it('should set isSavingFunctions to true when saving functions', () => {
const httpClientSpy = jasmine.createSpyObj('HttpClient', ['post']);
httpClientSpy.post.and.returnValue(of({}));
component.http = httpClientSpy as any;
component.agentDetails = { functions: ['func1', 'func2'] };
component.agentId = 'test-agent-id';
component.functionSelections = [true, true];
component.editMode = true;

component.saveFunctions();

expect(component.isSavingFunctions).toBeTrue();
});

describe('extractFunctionCallHistory', () => {
it('should extract function call history from user prompt text', () => {
const userPromptText =
'Some text <function_call_history>Function call history content</function_call_history> more text';
const extracted = component.extractFunctionCallHistory(userPromptText);
expect(extracted).toBe('Function call history content');
});

it('should return null if no function call history is present', () => {
const userPromptText = 'Some text without function call history';
const extracted = component.extractFunctionCallHistory(userPromptText);
expect(extracted).toBeNull();
});

it('should handle multiple function call history tags correctly', () => {
const userPromptText =
'Text <function_call_history>First call</function_call_history> Text <function_call_history>Second call</function_call_history>';
const extracted = component.extractFunctionCallHistory(userPromptText);
expect(extracted).toBe('First call');
});
});
// it('should save functions and update UI', () => {
// const httpClientSpy = jasmine.createSpyObj('HttpClient', ['post']);
// httpClientSpy.post.and.returnValue(of({}));
// component.http = httpClientSpy as any;
// component.agentDetails = { functions: ['func1', 'func2', 'func3'] };
// component.agentId = 'test-agent-id';
// component.functionSelections = [true, false, true];
// component.editMode = true;
//
// component.saveFunctions();
//
// expect(httpClientSpy.post).toHaveBeenCalledWith(`${environment.serverUrl}/agent/v1/update-functions`, {
// agentId: 'test-agent-id',
// functions: ['func1', 'func3'],
// });
// expect(component.editMode).toBeFalse();
// expect(component.isSavingFunctions).toBeFalse();
// });
//
// it('should handle errors when saving functions', () => {
// const httpClientSpy = jasmine.createSpyObj('HttpClient', ['post']);
// httpClientSpy.post.and.returnValue(throwError(() => new Error('Test error')));
// component.http = httpClientSpy as any;
// component.agentDetails = { functions: ['func1', 'func2'] };
// component.agentId = 'test-agent-id';
// component.functionSelections = [true, true];
// component.editMode = true;
//
// component.saveFunctions();
//
// expect(httpClientSpy.post).toHaveBeenCalled();
// expect(component.isSavingFunctions).toBeFalse();
// expect(component.editMode).toBeTrue();
// });
//
// it('should set isSavingFunctions to true when saving functions', () => {
// const httpClientSpy = jasmine.createSpyObj('HttpClient', ['post']);
// httpClientSpy.post.and.returnValue(of({}));
// component.http = httpClientSpy as any;
// component.agentDetails = { functions: ['func1', 'func2'] };
// component.agentId = 'test-agent-id';
// component.functionSelections = [true, true];
// component.editMode = true;
//
// component.saveFunctions();
//
// expect(component.isSavingFunctions).toBeTrue();
// });
//
// describe('extractFunctionCallHistory', () => {
// it('should extract function call history from user prompt text', () => {
// const userPromptText =
// 'Some text <function_call_history>Function call history content</function_call_history> more text';
// const extracted = component.extractFunctionCallHistory(userPromptText);
// expect(extracted).toBe('Function call history content');
// });
//
// it('should return null if no function call history is present', () => {
// const userPromptText = 'Some text without function call history';
// const extracted = component.extractFunctionCallHistory(userPromptText);
// expect(extracted).toBeNull();
// });
//
// it('should handle multiple function call history tags correctly', () => {
// const userPromptText =
// 'Text <function_call_history>First call</function_call_history> Text <function_call_history>Second call</function_call_history>';
// const extracted = component.extractFunctionCallHistory(userPromptText);
// expect(extracted).toBe('First call');
// });
// });
});

0 comments on commit cc9e6e3

Please sign in to comment.