mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-04-14 13:46:34 +00:00
Unit tests updated #1
This commit is contained in:
parent
aec31c5fbc
commit
b3aa58b9c9
@ -16,6 +16,7 @@ import { ServerService } from '../../../../../services/server.service';
|
||||
import { BuiltInTemplatesService } from '../../../../../services/built-in-templates.service';
|
||||
import { ToasterService } from '../../../../../services/toaster.service';
|
||||
import { TemplateMocksService } from '../../../../../services/template-mocks.service';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
|
||||
export class MockedBuiltInTemplatesService {
|
||||
public addTemplate(server: Server, cloudTemplate: CloudTemplate) {
|
||||
@ -34,7 +35,7 @@ describe('CloudNodesAddTemplateComponent', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, CommonModule, NoopAnimationsModule, RouterTestingModule.withRoutes([])],
|
||||
imports: [FormsModule, ReactiveFormsModule, MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, CommonModule, NoopAnimationsModule, RouterTestingModule.withRoutes([])],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute, useValue: activatedRoute
|
||||
@ -65,6 +66,7 @@ describe('CloudNodesAddTemplateComponent', () => {
|
||||
spyOn(mockedBuiltInTemplatesService, 'addTemplate').and.returnValue(of({} as CloudTemplate));
|
||||
component.templateName = "sample name";
|
||||
component.server = {id: 1} as Server;
|
||||
component.formGroup.controls['templateName'].setValue('template name');
|
||||
|
||||
component.addTemplate();
|
||||
|
||||
|
@ -16,6 +16,7 @@ import { ToasterService } from '../../../../../services/toaster.service';
|
||||
import { TemplateMocksService } from '../../../../../services/template-mocks.service';
|
||||
import { EthernetHubTemplate } from '../../../../../models/templates/ethernet-hub-template';
|
||||
import { EthernetHubsAddTemplateComponent } from './ethernet-hubs-add-template.component';
|
||||
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
|
||||
|
||||
export class MockedBuiltInTemplatesService {
|
||||
public addTemplate(server: Server, ethernetHubTemplate: EthernetHubTemplate) {
|
||||
@ -34,7 +35,7 @@ describe('EthernetHubsAddTemplateComponent', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, CommonModule, NoopAnimationsModule, RouterTestingModule.withRoutes([])],
|
||||
imports: [FormsModule, ReactiveFormsModule, MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, CommonModule, NoopAnimationsModule, RouterTestingModule.withRoutes([])],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute, useValue: activatedRoute
|
||||
@ -66,6 +67,8 @@ describe('EthernetHubsAddTemplateComponent', () => {
|
||||
component.templateName = "sample name";
|
||||
component.numberOfPorts = 2;
|
||||
component.server = {id: 1} as Server;
|
||||
component.formGroup.controls['templateName'].setValue('template name');
|
||||
component.formGroup.controls['numberOfPorts'].setValue('1');
|
||||
|
||||
component.addTemplate();
|
||||
|
||||
|
@ -16,6 +16,7 @@ import { ToasterService } from '../../../../../services/toaster.service';
|
||||
import { TemplateMocksService } from '../../../../../services/template-mocks.service';
|
||||
import { EthernetSwitchTemplate } from '../../../../../models/templates/ethernet-switch-template';
|
||||
import { EthernetSwitchesAddTemplateComponent } from './ethernet-switches-add-template.component';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
|
||||
export class MockedBuiltInTemplatesService {
|
||||
public addTemplate(server: Server, ethernetHubTemplate: EthernetSwitchTemplate) {
|
||||
@ -34,7 +35,7 @@ describe('EthernetSwitchesAddTemplateComponent', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, CommonModule, NoopAnimationsModule, RouterTestingModule.withRoutes([])],
|
||||
imports: [FormsModule, ReactiveFormsModule, MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, CommonModule, NoopAnimationsModule, RouterTestingModule.withRoutes([])],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute, useValue: activatedRoute
|
||||
@ -66,6 +67,8 @@ describe('EthernetSwitchesAddTemplateComponent', () => {
|
||||
component.templateName = "sample name";
|
||||
component.numberOfPorts = 2;
|
||||
component.server = {id: 1} as Server;
|
||||
component.formGroup.controls['templateName'].setValue('template name');
|
||||
component.formGroup.controls['numberOfPorts'].setValue('1');
|
||||
|
||||
component.addTemplate();
|
||||
|
||||
@ -75,8 +78,7 @@ describe('EthernetSwitchesAddTemplateComponent', () => {
|
||||
it('should not call add template when template name is empty', () => {
|
||||
spyOn(mockedBuiltInTemplatesService, 'addTemplate').and.returnValue(of({} as EthernetSwitchTemplate));
|
||||
spyOn(mockedToasterService, 'error');
|
||||
component.templateName = "";
|
||||
component.numberOfPorts = 2;
|
||||
component.formGroup.controls['numberOfPorts'].setValue('1');
|
||||
component.server = {id: 1} as Server;
|
||||
|
||||
component.addTemplate();
|
||||
@ -88,7 +90,7 @@ describe('EthernetSwitchesAddTemplateComponent', () => {
|
||||
it('should not call add template when number of ports is missing', () => {
|
||||
spyOn(mockedBuiltInTemplatesService, 'addTemplate').and.returnValue(of({} as EthernetSwitchTemplate));
|
||||
spyOn(mockedToasterService, 'error');
|
||||
component.templateName = "sample name";
|
||||
component.formGroup.controls['templateName'].setValue('template name');
|
||||
component.server = {id: 1} as Server;
|
||||
|
||||
component.addTemplate();
|
||||
|
@ -48,7 +48,7 @@ export class EthernetSwitchesAddTemplateComponent implements OnInit {
|
||||
}
|
||||
|
||||
addTemplate() {
|
||||
if (this.templateName && this.numberOfPorts) {
|
||||
if (!this.formGroup.invalid) {
|
||||
let ethernetSwitchTemplate: EthernetSwitchTemplate;
|
||||
|
||||
this.templateMocksService.getEthernetSwitchTemplate().subscribe((template: EthernetSwitchTemplate) => {
|
||||
|
@ -68,6 +68,8 @@ describe('AddIosTemplateComponent', () => {
|
||||
spyOn(mockedIosService, 'addTemplate').and.returnValue(of({} as IosTemplate));
|
||||
component.iosImageForm.controls['imageName'].setValue('image name');
|
||||
component.iosNameForm.controls['templateName'].setValue('template name');
|
||||
component.iosNameForm.controls['platform'].setValue('platform');
|
||||
component.iosNameForm.controls['chassis'].setValue('chassis');
|
||||
component.iosMemoryForm.controls['memory'].setValue(0);
|
||||
component.server = {id: 1} as Server;
|
||||
|
||||
@ -80,6 +82,8 @@ describe('AddIosTemplateComponent', () => {
|
||||
spyOn(mockedIosService, 'addTemplate').and.returnValue(of({} as IosTemplate));
|
||||
component.iosImageForm.controls['imageName'].setValue('image name');
|
||||
component.iosNameForm.controls['templateName'].setValue('');
|
||||
component.iosNameForm.controls['platform'].setValue('platform');
|
||||
component.iosNameForm.controls['chassis'].setValue('chassis');
|
||||
component.iosMemoryForm.controls['memory'].setValue(0);
|
||||
component.server = {id: 1} as Server;
|
||||
|
||||
@ -91,6 +95,8 @@ describe('AddIosTemplateComponent', () => {
|
||||
it('should not call add template when image name is not defined', () => {
|
||||
spyOn(mockedIosService, 'addTemplate').and.returnValue(of({} as IosTemplate));
|
||||
component.iosNameForm.controls['templateName'].setValue('template name');
|
||||
component.iosNameForm.controls['platform'].setValue('platform');
|
||||
component.iosNameForm.controls['chassis'].setValue('chassis');
|
||||
component.iosMemoryForm.controls['memory'].setValue(0);
|
||||
component.server = {id: 1} as Server;
|
||||
|
||||
@ -103,6 +109,8 @@ describe('AddIosTemplateComponent', () => {
|
||||
spyOn(mockedIosService, 'addTemplate').and.returnValue(of({} as IosTemplate));
|
||||
component.iosImageForm.controls['imageName'].setValue('image name');
|
||||
component.iosNameForm.controls['templateName'].setValue('template name');
|
||||
component.iosNameForm.controls['platform'].setValue('platform');
|
||||
component.iosNameForm.controls['chassis'].setValue('chassis');
|
||||
component.server = {id: 1} as Server;
|
||||
|
||||
component.addTemplate();
|
||||
|
@ -68,6 +68,20 @@ describe('IosTemplateDetailsComponent', () => {
|
||||
|
||||
it('should call save template', () => {
|
||||
spyOn(mockedIosService, 'saveTemplate').and.returnValue(of({} as IosTemplate));
|
||||
component.generalSettingsForm.controls['templateName'].setValue('template name');
|
||||
component.generalSettingsForm.controls['defaultName'].setValue('default name');
|
||||
component.generalSettingsForm.controls['symbol'].setValue('symbol');
|
||||
component.generalSettingsForm.controls['path'].setValue('path');
|
||||
component.generalSettingsForm.controls['initialConfig'].setValue('txt');
|
||||
component.memoryForm.controls['ram'].setValue('0');
|
||||
component.memoryForm.controls['nvram'].setValue('0');
|
||||
component.memoryForm.controls['iomemory'].setValue('0');
|
||||
component.memoryForm.controls['disk0'].setValue('0');
|
||||
component.memoryForm.controls['disk1'].setValue('0');
|
||||
component.advancedForm.controls['systemId'].setValue('0');
|
||||
component.advancedForm.controls['idlemax'].setValue('0');
|
||||
component.advancedForm.controls['idlesleep'].setValue('0');
|
||||
component.advancedForm.controls['execarea'].setValue('0');
|
||||
|
||||
component.onSave();
|
||||
|
||||
|
@ -66,6 +66,7 @@ describe('AddIouTemplateComponent', () => {
|
||||
spyOn(mockedIouService, 'addTemplate').and.returnValue(of({} as IouTemplate));
|
||||
component.templateNameForm.controls['templateName'].setValue('sample name');
|
||||
component.imageForm.controls['imageName'].setValue('sample name');
|
||||
component.newImageSelected = true;
|
||||
component.server = {id: 1} as Server;
|
||||
|
||||
component.addTemplate();
|
||||
@ -76,6 +77,7 @@ describe('AddIouTemplateComponent', () => {
|
||||
it('should not call add template when template name is empty', () => {
|
||||
spyOn(mockedIouService, 'addTemplate').and.returnValue(of({} as IouTemplate));
|
||||
component.imageForm.controls['imageName'].setValue('sample name');
|
||||
component.newImageSelected = true;
|
||||
component.server = {id: 1} as Server;
|
||||
|
||||
component.addTemplate();
|
||||
@ -86,6 +88,7 @@ describe('AddIouTemplateComponent', () => {
|
||||
it('should not call add template when image is not entered', () => {
|
||||
spyOn(mockedIouService, 'addTemplate').and.returnValue(of({} as IouTemplate));
|
||||
component.templateNameForm.controls['templateName'].setValue('sample name');
|
||||
component.newImageSelected = true;
|
||||
component.server = {id: 1} as Server;
|
||||
|
||||
component.addTemplate();
|
||||
|
@ -66,6 +66,13 @@ describe('IouTemplateDetailsComponent', () => {
|
||||
|
||||
it('should call save template', () => {
|
||||
spyOn(mockedIouService, 'saveTemplate').and.returnValue(of({} as IouTemplate));
|
||||
component.generalSettingsForm.controls['templateName'].setValue('template name');
|
||||
component.generalSettingsForm.controls['defaultName'].setValue('default name');
|
||||
component.generalSettingsForm.controls['symbol'].setValue('symbol');
|
||||
component.generalSettingsForm.controls['path'].setValue('path');
|
||||
component.generalSettingsForm.controls['initialConfig'].setValue('txt');
|
||||
component.networkForm.controls['ethernetAdapters'].setValue('1');
|
||||
component.networkForm.controls['serialAdapters'].setValue('1');
|
||||
|
||||
component.onSave();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user