mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-21 02:01:19 +00:00
Unit tests added
This commit is contained in:
parent
42821f28b2
commit
eed6466df5
@ -0,0 +1,57 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MatCheckboxModule, MatIconModule, MatToolbarModule, MatMenuModule } from '@angular/material';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { PreferencesComponent } from './preferences.component';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
|
||||
describe('SettingsComponent', () => {
|
||||
let component: PreferencesComponent;
|
||||
let fixture: ComponentFixture<PreferencesComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, CommonModule, NoopAnimationsModule, RouterTestingModule.withRoutes([])],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute, useValue: {
|
||||
params: Observable.of({ id: 3 }),
|
||||
snapshot: {
|
||||
parent: {
|
||||
params: {
|
||||
id: 1
|
||||
}
|
||||
},
|
||||
paramMap: {
|
||||
get(name: string): string {
|
||||
return '1';
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
],
|
||||
declarations: [
|
||||
PreferencesComponent
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PreferencesComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should save correct server id', () => {
|
||||
expect(component.serverId).toBe('1');
|
||||
});
|
||||
});
|
@ -0,0 +1,159 @@
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { HttpServer } from './http-server.service';
|
||||
import { Server } from '../models/server';
|
||||
import { getTestServer } from './testing';
|
||||
import { AppTestingModule } from '../testing/app-testing/app-testing.module';
|
||||
import { BuiltInTemplatesService } from './built-in-templates.service';
|
||||
import { CloudTemplate } from '../models/templates/cloud-template';
|
||||
import { EthernetHubTemplate } from '../models/templates/ethernet-hub-template';
|
||||
|
||||
describe('BuiltInTemplatesService', () => {
|
||||
let httpClient: HttpClient;
|
||||
let httpTestingController: HttpTestingController;
|
||||
let httpServer: HttpServer;
|
||||
let server: Server;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule, AppTestingModule],
|
||||
providers: [HttpServer, BuiltInTemplatesService]
|
||||
});
|
||||
|
||||
httpClient = TestBed.get(HttpClient);
|
||||
httpTestingController = TestBed.get(HttpTestingController);
|
||||
httpServer = TestBed.get(HttpServer);
|
||||
server = getTestServer();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpTestingController.verify();
|
||||
});
|
||||
|
||||
it('should be created', inject([BuiltInTemplatesService], (service: BuiltInTemplatesService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should update cloud template', inject([BuiltInTemplatesService], (service: BuiltInTemplatesService) => {
|
||||
const cloudtemplate = {
|
||||
builtin: false,
|
||||
category: 'guest',
|
||||
compute_id: 'local',
|
||||
default_name_format: 'Cloud{0}',
|
||||
name: '',
|
||||
ports_mapping: [],
|
||||
remote_console_type: 'none',
|
||||
symbol: ':/symbols/cloud.svg',
|
||||
template_id: '1',
|
||||
template_type: 'cloud'
|
||||
} as CloudTemplate;
|
||||
|
||||
service.saveTemplate(server, cloudtemplate).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates/1');
|
||||
expect(req.request.method).toEqual('PUT');
|
||||
expect(req.request.body).toEqual(cloudtemplate);
|
||||
}));
|
||||
|
||||
it('should update ethernet hub template', inject([BuiltInTemplatesService], (service: BuiltInTemplatesService) => {
|
||||
let ethernethubtemplate: EthernetHubTemplate = {
|
||||
builtin: false,
|
||||
category: 'switch',
|
||||
compute_id: 'local',
|
||||
default_name_format: 'Hub{0}',
|
||||
name: '',
|
||||
ports_mapping: [],
|
||||
symbol: ':/symbols/hub.svg',
|
||||
template_id: '2',
|
||||
template_type: 'ethernet_hub'
|
||||
}
|
||||
|
||||
service.saveTemplate(server, ethernethubtemplate).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates/2');
|
||||
expect(req.request.method).toEqual('PUT');
|
||||
expect(req.request.body).toEqual(ethernethubtemplate);
|
||||
}));
|
||||
|
||||
it('should update ethernet switch template', inject([BuiltInTemplatesService], (service: BuiltInTemplatesService) => {
|
||||
let ethernetswitchtemplate: EthernetHubTemplate = {
|
||||
builtin: false,
|
||||
category: 'switch',
|
||||
compute_id: 'local',
|
||||
default_name_format: 'Hub{0}',
|
||||
name: '',
|
||||
ports_mapping: [],
|
||||
symbol: ':/symbols/hub.svg',
|
||||
template_id: '3',
|
||||
template_type: 'ethernet_hub'
|
||||
}
|
||||
|
||||
service.saveTemplate(server, ethernetswitchtemplate).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates/3');
|
||||
expect(req.request.method).toEqual('PUT');
|
||||
expect(req.request.body).toEqual(ethernetswitchtemplate);
|
||||
}));
|
||||
|
||||
it('should add cloud template', inject([BuiltInTemplatesService], (service: BuiltInTemplatesService) => {
|
||||
const cloudtemplate = {
|
||||
builtin: false,
|
||||
category: 'guest',
|
||||
compute_id: 'local',
|
||||
default_name_format: 'Cloud{0}',
|
||||
name: '',
|
||||
ports_mapping: [],
|
||||
remote_console_type: 'none',
|
||||
symbol: ':/symbols/cloud.svg',
|
||||
template_id: '1',
|
||||
template_type: 'cloud'
|
||||
} as CloudTemplate;
|
||||
|
||||
service.addTemplate(server, cloudtemplate).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates');
|
||||
expect(req.request.method).toEqual('POST');
|
||||
expect(req.request.body).toEqual(cloudtemplate);
|
||||
}));
|
||||
|
||||
it('should add ethernet hub template', inject([BuiltInTemplatesService], (service: BuiltInTemplatesService) => {
|
||||
let ethernethubtemplate: EthernetHubTemplate = {
|
||||
builtin: false,
|
||||
category: 'switch',
|
||||
compute_id: 'local',
|
||||
default_name_format: 'Hub{0}',
|
||||
name: '',
|
||||
ports_mapping: [],
|
||||
symbol: ':/symbols/hub.svg',
|
||||
template_id: '2',
|
||||
template_type: 'ethernet_hub'
|
||||
}
|
||||
|
||||
service.addTemplate(server, ethernethubtemplate).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates');
|
||||
expect(req.request.method).toEqual('POST');
|
||||
expect(req.request.body).toEqual(ethernethubtemplate);
|
||||
}));
|
||||
|
||||
it('should add ethernet switch template', inject([BuiltInTemplatesService], (service: BuiltInTemplatesService) => {
|
||||
let ethernetswitchtemplate: EthernetHubTemplate = {
|
||||
builtin: false,
|
||||
category: 'switch',
|
||||
compute_id: 'local',
|
||||
default_name_format: 'Hub{0}',
|
||||
name: '',
|
||||
ports_mapping: [],
|
||||
symbol: ':/symbols/hub.svg',
|
||||
template_id: '3',
|
||||
template_type: 'ethernet_hub'
|
||||
}
|
||||
|
||||
service.addTemplate(server, ethernetswitchtemplate).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates');
|
||||
expect(req.request.method).toEqual('POST');
|
||||
expect(req.request.body).toEqual(ethernetswitchtemplate);
|
||||
}));
|
||||
});
|
@ -16,12 +16,12 @@ export class BuiltInTemplatesService {
|
||||
return this.httpServer.get<any>(server, `/templates/${template_id}`) as Observable<any>;
|
||||
}
|
||||
|
||||
addTemplate(server: Server, ethernetHubTemplate: any): Observable<any> {
|
||||
return this.httpServer.post<any>(server, `/templates`, ethernetHubTemplate) as Observable<any>;
|
||||
addTemplate(server: Server, builtInTemplate: any): Observable<any> {
|
||||
return this.httpServer.post<any>(server, `/templates`, builtInTemplate) as Observable<any>;
|
||||
}
|
||||
|
||||
saveTemplate(server: Server, ethernetHubTemplate: any): Observable<any> {
|
||||
return this.httpServer.put<any>(server, `/templates/${ethernetHubTemplate.template_id}`, ethernetHubTemplate) as Observable<any>;
|
||||
saveTemplate(server: Server, builtInTemplate: any): Observable<any> {
|
||||
return this.httpServer.put<any>(server, `/templates/${builtInTemplate.template_id}`, builtInTemplate) as Observable<any>;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,142 @@
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { HttpServer } from './http-server.service';
|
||||
import { Server } from '../models/server';
|
||||
import { getTestServer } from './testing';
|
||||
import { AppTestingModule } from '../testing/app-testing/app-testing.module';
|
||||
import { QemuService } from './qemu.service';
|
||||
import { QemuTemplate } from '../models/templates/qemu-template';
|
||||
|
||||
describe('QemuService', () => {
|
||||
let httpClient: HttpClient;
|
||||
let httpTestingController: HttpTestingController;
|
||||
let httpServer: HttpServer;
|
||||
let server: Server;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule, AppTestingModule],
|
||||
providers: [HttpServer, QemuService]
|
||||
});
|
||||
|
||||
httpClient = TestBed.get(HttpClient);
|
||||
httpTestingController = TestBed.get(HttpTestingController);
|
||||
httpServer = TestBed.get(HttpServer);
|
||||
server = getTestServer();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpTestingController.verify();
|
||||
});
|
||||
|
||||
it('should be created', inject([QemuService], (service: QemuService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should update qemu template', inject([QemuService], (service: QemuService) => {
|
||||
const template : QemuTemplate = {
|
||||
adapter_type: 'e1000',
|
||||
adapters: 4,
|
||||
bios_image: '',
|
||||
boot_priority: 'c',
|
||||
builtin: false,
|
||||
category: 'guest',
|
||||
cdrom_image: '',
|
||||
compute_id: 'local',
|
||||
console_auto_start: false,
|
||||
console_type: 'telnet',
|
||||
cpu_throttling: 0,
|
||||
cpus: 1,
|
||||
custom_adapters: [],
|
||||
default_name_format: '{name}-{0}',
|
||||
first_port_name: '',
|
||||
hda_disk_image: '',
|
||||
hda_disk_interface: 'ide',
|
||||
hdb_disk_image: '',
|
||||
hdb_disk_interface: 'ide',
|
||||
hdc_disk_image: '',
|
||||
hdc_disk_interface: 'ide',
|
||||
hdd_disk_image: '',
|
||||
hdd_disk_interface: 'ide',
|
||||
initrd: '',
|
||||
kernel_command_line: '',
|
||||
kernel_image: '',
|
||||
legacy_networking: false,
|
||||
linked_clone: true,
|
||||
mac_address: '',
|
||||
name: '',
|
||||
on_close: 'power_off',
|
||||
options: '-nographic',
|
||||
platform: '',
|
||||
port_name_format: 'Ethernet{0}',
|
||||
port_segment_size: 0,
|
||||
process_priority: 'normal',
|
||||
qemu_path: '',
|
||||
ram: 256,
|
||||
symbol: ':/symbols/qemu_guest.svg',
|
||||
template_id: '1',
|
||||
template_type: 'qemu',
|
||||
usage: ''
|
||||
}
|
||||
|
||||
service.saveTemplate(server, template).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates/1');
|
||||
expect(req.request.method).toEqual('PUT');
|
||||
expect(req.request.body).toEqual(template);
|
||||
}));
|
||||
|
||||
it('should add qemu template', inject([QemuService], (service: QemuService) => {
|
||||
const template : QemuTemplate = {
|
||||
adapter_type: 'e1000',
|
||||
adapters: 4,
|
||||
bios_image: '',
|
||||
boot_priority: 'c',
|
||||
builtin: false,
|
||||
category: 'guest',
|
||||
cdrom_image: '',
|
||||
compute_id: 'local',
|
||||
console_auto_start: false,
|
||||
console_type: 'telnet',
|
||||
cpu_throttling: 0,
|
||||
cpus: 1,
|
||||
custom_adapters: [],
|
||||
default_name_format: '{name}-{0}',
|
||||
first_port_name: '',
|
||||
hda_disk_image: '',
|
||||
hda_disk_interface: 'ide',
|
||||
hdb_disk_image: '',
|
||||
hdb_disk_interface: 'ide',
|
||||
hdc_disk_image: '',
|
||||
hdc_disk_interface: 'ide',
|
||||
hdd_disk_image: '',
|
||||
hdd_disk_interface: 'ide',
|
||||
initrd: '',
|
||||
kernel_command_line: '',
|
||||
kernel_image: '',
|
||||
legacy_networking: false,
|
||||
linked_clone: true,
|
||||
mac_address: '',
|
||||
name: '',
|
||||
on_close: 'power_off',
|
||||
options: '-nographic',
|
||||
platform: '',
|
||||
port_name_format: 'Ethernet{0}',
|
||||
port_segment_size: 0,
|
||||
process_priority: 'normal',
|
||||
qemu_path: '',
|
||||
ram: 256,
|
||||
symbol: ':/symbols/qemu_guest.svg',
|
||||
template_id: '',
|
||||
template_type: 'qemu',
|
||||
usage: ''
|
||||
}
|
||||
|
||||
service.addTemplate(server, template).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates');
|
||||
expect(req.request.method).toEqual('POST');
|
||||
expect(req.request.body).toEqual(template);
|
||||
}));
|
||||
});
|
@ -0,0 +1,104 @@
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { HttpServer } from './http-server.service';
|
||||
import { Server } from '../models/server';
|
||||
import { getTestServer } from './testing';
|
||||
import { AppTestingModule } from '../testing/app-testing/app-testing.module';
|
||||
import { VirtualBoxTemplate } from '../models/templates/virtualbox-template';
|
||||
import { VirtualBoxService } from './virtual-box.service';
|
||||
|
||||
describe('VirtualBoxService', () => {
|
||||
let httpClient: HttpClient;
|
||||
let httpTestingController: HttpTestingController;
|
||||
let httpServer: HttpServer;
|
||||
let server: Server;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule, AppTestingModule],
|
||||
providers: [HttpServer, VirtualBoxService]
|
||||
});
|
||||
|
||||
httpClient = TestBed.get(HttpClient);
|
||||
httpTestingController = TestBed.get(HttpTestingController);
|
||||
httpServer = TestBed.get(HttpServer);
|
||||
server = getTestServer();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpTestingController.verify();
|
||||
});
|
||||
|
||||
it('should be created', inject([VirtualBoxService], (service: VirtualBoxService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should update virtual box template', inject([VirtualBoxService], (service: VirtualBoxService) => {
|
||||
const template: VirtualBoxTemplate = {
|
||||
adapter_type: 'Intel PRO/1000 MT Desktop (82540EM)',
|
||||
adapters: 1,
|
||||
builtin: false,
|
||||
category: 'guest',
|
||||
compute_id: 'local',
|
||||
console_auto_start: false,
|
||||
console_type: 'none',
|
||||
custom_adapters: [],
|
||||
default_name_format: '{name}-{0}',
|
||||
first_port_name: '',
|
||||
headless: false,
|
||||
linked_clone: false,
|
||||
name: '',
|
||||
on_close: 'power_off',
|
||||
port_name_format: 'Ethernet{0}',
|
||||
port_segment_size: 0,
|
||||
ram: 0,
|
||||
symbol: ':/symbols/vbox_guest.svg',
|
||||
template_id: '1',
|
||||
template_type: 'virtualbox',
|
||||
usage: '',
|
||||
use_any_adapter: false,
|
||||
vmname: ''
|
||||
}
|
||||
|
||||
service.saveTemplate(server, template).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates/1');
|
||||
expect(req.request.method).toEqual('PUT');
|
||||
expect(req.request.body).toEqual(template);
|
||||
}));
|
||||
|
||||
it('should add virtual box template', inject([VirtualBoxService], (service: VirtualBoxService) => {
|
||||
const template: VirtualBoxTemplate = {
|
||||
adapter_type: 'Intel PRO/1000 MT Desktop (82540EM)',
|
||||
adapters: 1,
|
||||
builtin: false,
|
||||
category: 'guest',
|
||||
compute_id: 'local',
|
||||
console_auto_start: false,
|
||||
console_type: 'none',
|
||||
custom_adapters: [],
|
||||
default_name_format: '{name}-{0}',
|
||||
first_port_name: '',
|
||||
headless: false,
|
||||
linked_clone: false,
|
||||
name: '',
|
||||
on_close: 'power_off',
|
||||
port_name_format: 'Ethernet{0}',
|
||||
port_segment_size: 0,
|
||||
ram: 0,
|
||||
symbol: ':/symbols/vbox_guest.svg',
|
||||
template_id: '',
|
||||
template_type: 'virtualbox',
|
||||
usage: '',
|
||||
use_any_adapter: false,
|
||||
vmname: ''
|
||||
}
|
||||
|
||||
service.addTemplate(server, template).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates');
|
||||
expect(req.request.method).toEqual('POST');
|
||||
expect(req.request.body).toEqual(template);
|
||||
}));
|
||||
});
|
@ -0,0 +1,80 @@
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { HttpServer } from './http-server.service';
|
||||
import { Server } from '../models/server';
|
||||
import { getTestServer } from './testing';
|
||||
import { AppTestingModule } from '../testing/app-testing/app-testing.module';
|
||||
import { VpcsService } from './vpcs.service';
|
||||
import { VpcsTemplate } from '../models/templates/vpcs-template';
|
||||
|
||||
describe('VpcsService', () => {
|
||||
let httpClient: HttpClient;
|
||||
let httpTestingController: HttpTestingController;
|
||||
let httpServer: HttpServer;
|
||||
let server: Server;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule, AppTestingModule],
|
||||
providers: [HttpServer, VpcsService]
|
||||
});
|
||||
|
||||
httpClient = TestBed.get(HttpClient);
|
||||
httpTestingController = TestBed.get(HttpTestingController);
|
||||
httpServer = TestBed.get(HttpServer);
|
||||
server = getTestServer();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpTestingController.verify();
|
||||
});
|
||||
|
||||
it('should be created', inject([VpcsService], (service: VpcsService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should update vpcs template', inject([VpcsService], (service: VpcsService) => {
|
||||
const template: VpcsTemplate = {
|
||||
base_script_file: 'vpcs_base_config.txt',
|
||||
builtin: false,
|
||||
category: 'guest',
|
||||
compute_id: 'local',
|
||||
console_auto_start: false,
|
||||
console_type: 'telnet',
|
||||
default_name_format: 'PC{0}',
|
||||
name: '',
|
||||
symbol: ':/symbols/vpcs_guest.svg',
|
||||
template_id: '1',
|
||||
template_type: 'vpcs'
|
||||
}
|
||||
|
||||
service.saveTemplate(server, template).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates/1');
|
||||
expect(req.request.method).toEqual('PUT');
|
||||
expect(req.request.body).toEqual(template);
|
||||
}));
|
||||
|
||||
it('should add vpcs template', inject([VpcsService], (service: VpcsService) => {
|
||||
const template: VpcsTemplate = {
|
||||
base_script_file: 'vpcs_base_config.txt',
|
||||
builtin: false,
|
||||
category: 'guest',
|
||||
compute_id: 'local',
|
||||
console_auto_start: false,
|
||||
console_type: 'telnet',
|
||||
default_name_format: 'PC{0}',
|
||||
name: '',
|
||||
symbol: ':/symbols/vpcs_guest.svg',
|
||||
template_id: '',
|
||||
template_type: 'vpcs'
|
||||
}
|
||||
|
||||
service.addTemplate(server, template).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates');
|
||||
expect(req.request.method).toEqual('POST');
|
||||
expect(req.request.body).toEqual(template);
|
||||
}));
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user