mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-01-18 10:46:35 +00:00
Unit tests added
This commit is contained in:
parent
1f928690b3
commit
69e18494bb
@ -0,0 +1,63 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { LinkService } from '../../../../services/link.service';
|
||||
import { MockedLinkService } from '../../project-map.component.spec';
|
||||
import { Link } from '../../../../models/link';
|
||||
import { of } from 'rxjs';
|
||||
import { PacketFiltersDialogComponent } from './packet-filters.component';
|
||||
|
||||
describe('PacketFiltersDialogComponent', () => {
|
||||
let component: PacketFiltersDialogComponent;
|
||||
let fixture: ComponentFixture<PacketFiltersDialogComponent>;
|
||||
|
||||
let mockedLinkService = new MockedLinkService;
|
||||
let dialogRef = {
|
||||
close: jasmine.createSpy('close')
|
||||
};
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [MatDialogModule, FormsModule, ReactiveFormsModule, MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, CommonModule, NoopAnimationsModule],
|
||||
providers: [
|
||||
{ provide: MatDialogRef, useValue: dialogRef },
|
||||
{ provide: MAT_DIALOG_DATA, useValue: [] },
|
||||
{ provide: LinkService, useValue: mockedLinkService }
|
||||
],
|
||||
declarations: [
|
||||
PacketFiltersDialogComponent
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PacketFiltersDialogComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.link = {link_type: 'ethernet'} as Link;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should call update link when filters applied', () => {
|
||||
spyOn(mockedLinkService, 'updateLink').and.returnValue(of({}));
|
||||
|
||||
component.onYesClick();
|
||||
|
||||
expect(mockedLinkService.updateLink).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call update link after resetting', () => {
|
||||
spyOn(mockedLinkService, 'updateLink').and.returnValue(of({}));
|
||||
|
||||
component.onResetClick();
|
||||
|
||||
expect(mockedLinkService.updateLink).toHaveBeenCalled();
|
||||
});
|
||||
});
|
@ -5,7 +5,8 @@
|
||||
<mat-form-field class="input-field">
|
||||
<mat-select
|
||||
placeholder="Link type"
|
||||
formControlName="linkType">
|
||||
formControlName="linkType"
|
||||
ngDefaultControl>
|
||||
<mat-option *ngFor="let type of linkTypes" [value]="type[1]">
|
||||
{{type[0]}}
|
||||
</mat-option>
|
||||
|
@ -0,0 +1,80 @@
|
||||
import { StartCaptureDialogComponent } from "./start-capture.component";
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { ToasterService } from '../../../../services/toaster.service';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { MockedToasterService } from '../../../../services/toaster.service.spec';
|
||||
import { LinkService } from '../../../../services/link.service';
|
||||
import { MockedLinkService } from '../../project-map.component.spec';
|
||||
import { Link } from '../../../../models/link';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
describe('StartCaptureDialogComponent', () => {
|
||||
let component: StartCaptureDialogComponent;
|
||||
let fixture: ComponentFixture<StartCaptureDialogComponent>;
|
||||
|
||||
let mockedToasterService = new MockedToasterService;
|
||||
let mockedLinkService = new MockedLinkService;
|
||||
let dialogRef = {
|
||||
close: jasmine.createSpy('close')
|
||||
};
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [MatDialogModule, FormsModule, ReactiveFormsModule, MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, CommonModule, NoopAnimationsModule],
|
||||
providers: [
|
||||
{ provide: MatDialogRef, useValue: dialogRef },
|
||||
{ provide: MAT_DIALOG_DATA, useValue: [] },
|
||||
{ provide: ToasterService, useValue: mockedToasterService },
|
||||
{ provide: LinkService, useValue: mockedLinkService }
|
||||
],
|
||||
declarations: [
|
||||
StartCaptureDialogComponent
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(StartCaptureDialogComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.link = {link_type: 'ethernet'} as Link;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should call link service when input is valid', () => {
|
||||
component.inputForm.controls['linkType'].setValue('Ethernet');
|
||||
component.inputForm.controls['fileName'].setValue('SampleFileName');
|
||||
spyOn(mockedLinkService, 'startCaptureOnLink').and.returnValue(of({}));
|
||||
|
||||
component.onYesClick();
|
||||
|
||||
expect(mockedLinkService.startCaptureOnLink).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not call link service when link type is not set', () => {
|
||||
component.inputForm.controls['fileName'].setValue('SampleFileName');
|
||||
spyOn(mockedLinkService, 'startCaptureOnLink').and.returnValue(of({}));
|
||||
|
||||
component.onYesClick();
|
||||
|
||||
expect(mockedLinkService.startCaptureOnLink).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call link service when filename is empty', () => {
|
||||
component.inputForm.controls['linkType'].setValue('Ethernet');
|
||||
component.inputForm.controls['fileName'].setValue('');
|
||||
spyOn(mockedLinkService, 'startCaptureOnLink').and.returnValue(of({}));
|
||||
|
||||
component.onYesClick();
|
||||
|
||||
expect(mockedLinkService.startCaptureOnLink).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
@ -40,6 +40,7 @@ import { RecentlyOpenedProjectService } from '../../services/recentlyOpenedProje
|
||||
import { MapLinkToLinkConverter } from '../../cartography/converters/map/map-link-to-link-converter';
|
||||
import { Link } from '../../models/link';
|
||||
import { Project } from '../../models/project';
|
||||
import { CapturingSettings } from '../../models/capturingSettings';
|
||||
|
||||
export class MockedProgressService {
|
||||
public activate() {}
|
||||
@ -110,8 +111,16 @@ export class MockedDrawingService {
|
||||
export class MockedLinkService {
|
||||
constructor() {}
|
||||
|
||||
getLink(server: Server, projectId: string, linkId: string) {
|
||||
return of({});
|
||||
}
|
||||
|
||||
deleteLink(_server: Server, link: Link){
|
||||
return of({})
|
||||
return of({});
|
||||
}
|
||||
|
||||
updateLink(server: Server, link: Link) {
|
||||
return of({});
|
||||
}
|
||||
|
||||
createLink() {
|
||||
@ -121,6 +130,14 @@ export class MockedLinkService {
|
||||
updateNodes() {
|
||||
return of({});
|
||||
}
|
||||
|
||||
startCaptureOnLink(server: Server, link: Link, settings: CapturingSettings) {
|
||||
return of({});
|
||||
}
|
||||
|
||||
getAvailableFilters(server: Server, link: Link) {
|
||||
return of({});
|
||||
}
|
||||
}
|
||||
|
||||
export class MockedDrawingsDataSource {
|
||||
|
Loading…
Reference in New Issue
Block a user