Skip to content

Commit

Permalink
Adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcguillemdev committed Jun 15, 2024
1 parent c940995 commit 4a83ebb
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/app/components/config/config.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ConfigComponent } from './config.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatDialogRef } from '@angular/material/dialog';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ConfigComponent } from './config.component';
import { LMSTudioAPIConfiguration } from '../../interface/configuration';

describe('ConfigComponent', () => {
let component: ConfigComponent;
let fixture: ComponentFixture<ConfigComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
ConfigComponent,
BrowserAnimationsModule
],
declarations: [],
imports: [ConfigComponent, BrowserAnimationsModule],
providers: [
{ provide: MatDialogRef, useValue: {} }
]
})
.compileComponents();
{ provide: MatDialogRef, useValue: jasmine.createSpyObj('MatDialogRef', ['close']) }
],
}).compileComponents();

fixture = TestBed.createComponent(ConfigComponent);
component = fixture.componentInstance;
Expand All @@ -28,4 +25,21 @@ describe('ConfigComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should reset formGroup to default configuration', () => {
component.resetToDefaults();
expect(component.formGroup.value).toEqual(component["configService"]._defaultConfiguration);
});

it('should set configuration and close dialog', () => {
const reloadModelsAfterCloseThisModal = true;
component.formGroup.setValue({
host: 'example.com',
systemPrompt: 'Hello',
});
spyOn(component["configService"], "setConfiguration");
component.setConfiguration(reloadModelsAfterCloseThisModal);
expect(component["configService"].setConfiguration).toHaveBeenCalledWith(component.formGroup.value as LMSTudioAPIConfiguration);
expect(component["matDialogRef"].close).toHaveBeenCalledWith(reloadModelsAfterCloseThisModal);
});
});

0 comments on commit 4a83ebb

Please sign in to comment.