diff options
author | jegadeeshbabu3 <jegadeesh.babu@att.com> | 2020-02-28 17:42:20 +0530 |
---|---|---|
committer | Jegadeesh Babu <jegadeesh.babu@att.com> | 2020-02-28 15:35:27 +0000 |
commit | 4c6f6a443cb2e6effa995e77d56689c1c2dab4ad (patch) | |
tree | 7a961f7c4e2c7de9cea8f2acff473c9f4b11182e /portal-FE-os/src/app/pages/application-onboarding/application-details-dialog | |
parent | a03dfa273ef6e196bf65acc54b9357d35eb0ed5e (diff) |
Fixed the test cases,added sonar config
Fixed test cases and added sonar config details
Issue-ID: PORTAL-837
Change-Id: Ie4aa104871cfbbd6c6e36500f5ef2e250bafb575
Signed-off-by: jz385p <jegadeesh.babu@att.com>
Diffstat (limited to 'portal-FE-os/src/app/pages/application-onboarding/application-details-dialog')
2 files changed, 81 insertions, 5 deletions
diff --git a/portal-FE-os/src/app/pages/application-onboarding/application-details-dialog/application-details-dialog.component.spec.ts b/portal-FE-os/src/app/pages/application-onboarding/application-details-dialog/application-details-dialog.component.spec.ts index 0ea27629..629e5fa6 100644 --- a/portal-FE-os/src/app/pages/application-onboarding/application-details-dialog/application-details-dialog.component.spec.ts +++ b/portal-FE-os/src/app/pages/application-onboarding/application-details-dialog/application-details-dialog.component.spec.ts @@ -39,25 +39,94 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { ApplicationDetailsDialogComponent } from './application-details-dialog.component'; +import { NgMaterialModule } from 'src/app/ng-material-module'; +import { FormsModule } from '@angular/forms'; +import { NgbActiveModal, NgbModal, NgbModule } from '@ng-bootstrap/ng-bootstrap'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { IApplications } from 'src/app/shared/model/applications-onboarding/applications'; +import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component'; +import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing'; +import { NgbModalBackdrop } from '@ng-bootstrap/ng-bootstrap/modal/modal-backdrop'; +import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component'; + describe('ApplicationDetailsDialogComponent', () => { let component: ApplicationDetailsDialogComponent; let fixture: ComponentFixture<ApplicationDetailsDialogComponent>; + const applicationObj: IApplications = {"id":"testID"}; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ ApplicationDetailsDialogComponent ] - }) + declarations: [ ApplicationDetailsDialogComponent,InformationModalComponent,ConfirmationModalComponent], + imports: [NgMaterialModule,FormsModule,HttpClientTestingModule,NgbModule.forRoot()], + providers: [NgbActiveModal] + }).overrideModule(BrowserDynamicTestingModule, { set: { entryComponents: [InformationModalComponent,ConfirmationModalComponent] } }) .compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(ApplicationDetailsDialogComponent); component = fixture.componentInstance; + component.applicationObj = applicationObj; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); + it('removeImage should return stubbed value', () => { + spyOn(component, 'removeImage').and.callThrough(); + component.removeImage(); + expect(component.removeImage).toHaveBeenCalledWith(); + }); + it('saveChanges should return stubbed value', () => { + component.applicationObj.isCentralAuth = true; + component.applicationObj.isEnabled = false; + spyOn(component, 'saveChanges').and.callThrough(); + component.saveChanges(); + expect(component.saveChanges).toHaveBeenCalledWith(); + component.applicationObj.isEnabled = true; + component.applicationObj.url = 'www.test.com' + component.applicationObj.restrictedApp =true; + + //spyOn(component, 'saveChanges').and.callThrough(); + component.saveChanges(); + expect(component.saveChanges).toHaveBeenCalledWith(); + component.applicationObj.isCentralAuth = false; + component.applicationObj.url = 'test' + component.applicationObj.restrictedApp =false; + component.applicationObj.isOpen = true; + component.isEditMode =true; + //spyOn(component, 'saveChanges').and.callThrough(); + component.saveChanges(); + expect(component.saveChanges).toHaveBeenCalledWith(); + }); + it('saveChanges Central Auth is disabled', () => { + component.applicationObj.isCentralAuth = false; + component.applicationObj.isEnabled = false; + spyOn(component, 'saveChanges').and.callThrough(); + component.saveChanges(); + expect(component.saveChanges).toHaveBeenCalledWith(); + component.applicationObj.isEnabled = true; + component.applicationObj.restrictedApp = true; + component.saveChanges(); + expect(component.saveChanges).toHaveBeenCalledWith(); + + }); + + it('saveChanges URL validation changes', () => { + component.applicationObj.isCentralAuth = true; + component.applicationObj.isEnabled = true; + component.applicationObj.name ='test'; + component.applicationObj.url = 'https://www.test.com' + component.applicationObj.username ='test' + component.applicationObj.nameSpace ='ONAP' + spyOn(component, 'saveChanges').and.callThrough(); + component.saveChanges(); + expect(component.saveChanges).toHaveBeenCalledWith(); + component.applicationObj.restrictedApp = false; + component.isEditMode = true; + component.saveChanges(); + expect(component.saveChanges).toHaveBeenCalledWith(); + }); }); diff --git a/portal-FE-os/src/app/pages/application-onboarding/application-details-dialog/application-details-dialog.component.ts b/portal-FE-os/src/app/pages/application-onboarding/application-details-dialog/application-details-dialog.component.ts index 60654461..39d2ffde 100644 --- a/portal-FE-os/src/app/pages/application-onboarding/application-details-dialog/application-details-dialog.component.ts +++ b/portal-FE-os/src/app/pages/application-onboarding/application-details-dialog/application-details-dialog.component.ts @@ -36,12 +36,13 @@ * */ -import { Component, OnInit, Input, Output, EventEmitter} from '@angular/core'; +import { Component, OnInit, Input, Output, EventEmitter, PLATFORM_ID, Inject, Injector} from '@angular/core'; import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { IApplications } from 'src/app/shared/model/applications-onboarding/applications'; import { ApplicationsService } from 'src/app/shared/services'; import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component'; import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component'; +import { isPlatformBrowser } from '@angular/common'; @Component({ selector: 'app-application-details-dialog', @@ -59,9 +60,15 @@ export class ApplicationDetailsDialogComponent implements OnInit { isSaving: boolean = false; originalImage: any; ECOMP_URL_REGEX = "/^((?:https?\:\/\/|ftp?\:\/\/)?(w{3}.)?(?:[-a-z0-9]+\.)*[-a-z0-9]+.*)[^-_.]$/i"; + private ngbModal:NgbModal; - constructor(public activeModal: NgbActiveModal, public ngbModal: NgbModal, - public applicationsService : ApplicationsService) { } + constructor(public activeModal: NgbActiveModal, + public applicationsService : ApplicationsService,@Inject(PLATFORM_ID)private platformId:Object,private injector:Injector) { + if(isPlatformBrowser(this.platformId)) + { + this.ngbModal = this.injector.get(NgbModal); + } + } @Input() applicationObj: IApplications; @Output() passEntry: EventEmitter<any> = new EventEmitter(); |