From b3aa58b9c9b271af23b373308635ff158d15a024 Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Mon, 18 Feb 2019 04:06:21 -0800 Subject: [PATCH] Unit tests updated #1 --- .../cloud-nodes-add-template.component.spec.ts | 4 +++- .../ethernet-hubs-add-template.component.spec.ts | 5 ++++- ...thernet-switches-add-template.component.spec.ts | 10 ++++++---- .../ethernet-switches-add-template.component.ts | 2 +- .../add-ios-template.component.spec.ts | 8 ++++++++ .../ios-template-details.component.spec.ts | 14 ++++++++++++++ .../add-iou-template.component.spec.ts | 3 +++ .../iou-template-details.component.spec.ts | 7 +++++++ 8 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/app/components/preferences/built-in/cloud-nodes/cloud-nodes-add-template/cloud-nodes-add-template.component.spec.ts b/src/app/components/preferences/built-in/cloud-nodes/cloud-nodes-add-template/cloud-nodes-add-template.component.spec.ts index 43bfa6f0..f8910ac3 100644 --- a/src/app/components/preferences/built-in/cloud-nodes/cloud-nodes-add-template/cloud-nodes-add-template.component.spec.ts +++ b/src/app/components/preferences/built-in/cloud-nodes/cloud-nodes-add-template/cloud-nodes-add-template.component.spec.ts @@ -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(); diff --git a/src/app/components/preferences/built-in/ethernet-hubs/ethernet-hubs-add-template/ethernet-hubs-add-template.component.spec.ts b/src/app/components/preferences/built-in/ethernet-hubs/ethernet-hubs-add-template/ethernet-hubs-add-template.component.spec.ts index d37634e0..184a3eba 100644 --- a/src/app/components/preferences/built-in/ethernet-hubs/ethernet-hubs-add-template/ethernet-hubs-add-template.component.spec.ts +++ b/src/app/components/preferences/built-in/ethernet-hubs/ethernet-hubs-add-template/ethernet-hubs-add-template.component.spec.ts @@ -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(); diff --git a/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-add-template/ethernet-switches-add-template.component.spec.ts b/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-add-template/ethernet-switches-add-template.component.spec.ts index 4b1fcee6..05d42e0e 100644 --- a/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-add-template/ethernet-switches-add-template.component.spec.ts +++ b/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-add-template/ethernet-switches-add-template.component.spec.ts @@ -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(); diff --git a/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-add-template/ethernet-switches-add-template.component.ts b/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-add-template/ethernet-switches-add-template.component.ts index f5126369..74482f6b 100644 --- a/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-add-template/ethernet-switches-add-template.component.ts +++ b/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-add-template/ethernet-switches-add-template.component.ts @@ -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) => { diff --git a/src/app/components/preferences/dynamips/add-ios-template/add-ios-template.component.spec.ts b/src/app/components/preferences/dynamips/add-ios-template/add-ios-template.component.spec.ts index 226ebd85..942dcb36 100644 --- a/src/app/components/preferences/dynamips/add-ios-template/add-ios-template.component.spec.ts +++ b/src/app/components/preferences/dynamips/add-ios-template/add-ios-template.component.spec.ts @@ -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(); diff --git a/src/app/components/preferences/dynamips/ios-template-details/ios-template-details.component.spec.ts b/src/app/components/preferences/dynamips/ios-template-details/ios-template-details.component.spec.ts index e46e6c8c..b4755441 100644 --- a/src/app/components/preferences/dynamips/ios-template-details/ios-template-details.component.spec.ts +++ b/src/app/components/preferences/dynamips/ios-template-details/ios-template-details.component.spec.ts @@ -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(); diff --git a/src/app/components/preferences/ios-on-unix/add-iou-template/add-iou-template.component.spec.ts b/src/app/components/preferences/ios-on-unix/add-iou-template/add-iou-template.component.spec.ts index 1da49684..a64f24f2 100644 --- a/src/app/components/preferences/ios-on-unix/add-iou-template/add-iou-template.component.spec.ts +++ b/src/app/components/preferences/ios-on-unix/add-iou-template/add-iou-template.component.spec.ts @@ -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(); diff --git a/src/app/components/preferences/ios-on-unix/iou-template-details/iou-template-details.component.spec.ts b/src/app/components/preferences/ios-on-unix/iou-template-details/iou-template-details.component.spec.ts index b22f4dad..6d09910d 100644 --- a/src/app/components/preferences/ios-on-unix/iou-template-details/iou-template-details.component.spec.ts +++ b/src/app/components/preferences/ios-on-unix/iou-template-details/iou-template-details.component.spec.ts @@ -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();