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>
diff --git a/portal-FE-os/package.json b/portal-FE-os/package.json
index 265cab7..77cef69 100644
--- a/portal-FE-os/package.json
+++ b/portal-FE-os/package.json
@@ -5,9 +5,10 @@
"ng": "ng",
"start": "ng serve --host www.portal.onap.org --port 8989 --open",
"build": "ng build --prod --aot=false --build-optimizer=false",
- "test": "ng test",
+ "test": "ng test --watch=false --code-coverage --browsers=ChromeHeadless",
"lint": "ng lint",
- "e2e": "ng e2e"
+ "e2e": "ng e2e",
+ "sonar": "sonar-scanner"
},
"private": true,
"dependencies": {
@@ -65,6 +66,7 @@
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
+ "sonar-scanner": "^3.1.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.1.6"
diff --git a/portal-FE-os/pom.xml b/portal-FE-os/pom.xml
index 626addb..21bdd50 100644
--- a/portal-FE-os/pom.xml
+++ b/portal-FE-os/pom.xml
@@ -10,6 +10,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipnode>false</skipnode>
<skipcopy>false</skipcopy>
+ <sonar.typescript.lcov.reportPaths>coverage/lcov.info</sonar.typescript.lcov.reportPaths>
+ <sonar.sources>src</sonar.sources>
+ <sonar.projectKey>portal-FE-os</sonar.projectKey>
+ <sonar.projectName>portal-FE-os</sonar.projectName>
+ <sonar.exclusions>**/node_modules/**,**/*.spec.ts,**/*.module.ts,**/environment.prod.ts,**/*.js,**/main.ts,**/header-interceptor.ts,**/dynamic-widget.component.ts</sonar.exclusions>
+ <sonar.test.inclusions>**/*.spec.ts</sonar.test.inclusions>
+ <sonar.tests>src</sonar.tests>
+ <sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>
</properties>
<build>
@@ -97,6 +105,19 @@
<arguments>install</arguments>
</configuration>
</execution>
+
+ <execution>
+ <id>npm run test</id>
+ <goals>
+ <goal>npm</goal>
+ </goals>
+
+ <phase>generate-resources</phase>
+
+ <configuration>
+ <arguments>run-script test</arguments>
+ </configuration>
+ </execution>
<execution>
<id>npm build</id>
diff --git a/portal-FE-os/src/app/app.component.spec.ts b/portal-FE-os/src/app/app.component.spec.ts
index afc476f..cd96a77 100644
--- a/portal-FE-os/src/app/app.component.spec.ts
+++ b/portal-FE-os/src/app/app.component.spec.ts
@@ -34,7 +34,7 @@
* ============LICENSE_END============================================
*
*
- */s
+ */
import { TestBed, async } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
@@ -56,17 +56,4 @@
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});
-
- it(`should have as title 'portal-FE-os'`, () => {
- const fixture = TestBed.createComponent(AppComponent);
- const app = fixture.debugElement.componentInstance;
- expect(app.title).toEqual('portal-FE-os');
- });
-
- it('should render title in a h1 tag', () => {
- const fixture = TestBed.createComponent(AppComponent);
- fixture.detectChanges();
- const compiled = fixture.debugElement.nativeElement;
- expect(compiled.querySelector('h1').textContent).toContain('Welcome to portal-FE-os!');
- });
});
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 0ea2762..629e5fa 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 6065446..39d2ffd 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 @@
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();
diff --git a/portal-FE-os/src/app/pages/application-onboarding/application-onboarding.component.spec.ts b/portal-FE-os/src/app/pages/application-onboarding/application-onboarding.component.spec.ts
index 8e19838..3f75099 100644
--- a/portal-FE-os/src/app/pages/application-onboarding/application-onboarding.component.spec.ts
+++ b/portal-FE-os/src/app/pages/application-onboarding/application-onboarding.component.spec.ts
@@ -39,6 +39,9 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ApplicationOnboardingComponent } from './application-onboarding.component';
+import { NgMaterialModule } from 'src/app/ng-material-module';
+import { HttpClientTestingModule } from '@angular/common/http/testing';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
describe('ApplicationOnboardingComponent', () => {
let component: ApplicationOnboardingComponent;
@@ -46,7 +49,8 @@
beforeEach(async(() => {
TestBed.configureTestingModule({
- declarations: [ ApplicationOnboardingComponent ]
+ declarations: [ ApplicationOnboardingComponent ],
+ imports: [NgMaterialModule,HttpClientTestingModule,BrowserAnimationsModule]
})
.compileComponents();
}));
diff --git a/portal-FE-os/src/app/pages/pages.component.spec.ts b/portal-FE-os/src/app/pages/pages.component.spec.ts
index 1bef834..25383aa 100644
--- a/portal-FE-os/src/app/pages/pages.component.spec.ts
+++ b/portal-FE-os/src/app/pages/pages.component.spec.ts
@@ -38,6 +38,7 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PagesComponent } from './pages.component';
+import { Component } from '@angular/core';
describe('PagesComponent', () => {
let component: PagesComponent;
@@ -45,7 +46,7 @@
beforeEach(async(() => {
TestBed.configureTestingModule({
- declarations: [ PagesComponent ]
+ declarations: [ PagesComponent,RouterOutletStubComponent ]
})
.compileComponents();
}));
@@ -60,3 +61,6 @@
expect(component).toBeTruthy();
});
});
+
+@Component({selector: 'router-outlet', template: ''})
+class RouterOutletStubComponent { }
diff --git a/portal-FE-os/src/app/pages/users/new-user-modal/new-user-modal.component.spec.ts b/portal-FE-os/src/app/pages/users/new-user-modal/new-user-modal.component.spec.ts
index beb998c..85a2d9e 100644
--- a/portal-FE-os/src/app/pages/users/new-user-modal/new-user-modal.component.spec.ts
+++ b/portal-FE-os/src/app/pages/users/new-user-modal/new-user-modal.component.spec.ts
@@ -38,6 +38,13 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NewUserModalComponent } from './new-user-modal.component';
+import { HttpClientTestingModule } from '@angular/common/http/testing';
+import { NgMaterialModule } from 'src/app/ng-material-module';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
+import { Component, Input } from '@angular/core';
+import { FormsModule } from '@angular/forms';
+import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
+import { MatRadioChange } from '@angular/material';
describe('NewUserModalComponent', () => {
let component: NewUserModalComponent;
@@ -45,7 +52,9 @@
beforeEach(async(() => {
TestBed.configureTestingModule({
- declarations: [ NewUserModalComponent ]
+ declarations: [ NewUserModalComponent,AppSearchUsersStubComponent,AppUserdetailsFormStubComponent ],
+ imports:[HttpClientTestingModule,FormsModule,NgMaterialModule,BrowserAnimationsModule],
+ providers:[NgbActiveModal]
})
.compileComponents();
}));
@@ -59,4 +68,67 @@
it('should create', () => {
expect(component).toBeTruthy();
});
+
+ it('addNewUser should return stubbed value', () => {
+ spyOn(component, 'addNewUser').and.callThrough();
+ component.addNewUser(true);
+ expect(component.addNewUser).toHaveBeenCalledWith(true);
+ });
+
+ it('changeSelectedUser should return stubbed value', () => {
+ spyOn(component, 'changeSelectedUser').and.callThrough();
+ let user = {};
+ component.changeSelectedUser(user);
+ expect(component.changeSelectedUser).toHaveBeenCalledWith(user);
+ user = {"firstName":"FirstTestName","lastName":"LastTestName","orgUserId":"TestOrgId"};
+ component.changeSelectedUser(user);
+ expect(component.changeSelectedUser).toHaveBeenCalledWith(user);
+
+ });
+
+ // it('searchUserRadioChange should return stubbed value', () => {
+ // spyOn(component, 'searchUserRadioChange').and.callThrough();
+ // MatRadio = {"value":""};
+ // component.searchUserRadioChange(eventCheck);
+ // expect(component.searchUserRadioChange).toHaveBeenCalledWith(event);
+ // event = {"value":"System"};
+ // component.searchUserRadioChange(event);
+ // expect(component.searchUserRadioChange).toHaveBeenCalledWith(event);
+
+ // });
+
+ it('navigateBack should return stubbed value', () => {
+ spyOn(component, 'navigateBack').and.callThrough();
+ component.navigateBack();
+ expect(component.navigateBack).toHaveBeenCalledWith();
+ });
+
+ it('roleSelectChange should return stubbed value', () => {
+ spyOn(component, 'roleSelectChange').and.callThrough();
+ let element = {"id":2};
+ component.roleSelectChange(element);
+ expect(component.roleSelectChange).toHaveBeenCalledWith(element);
+ });
+
+ it('getUserAppsRoles should return stubbed value', () => {
+ spyOn(component, 'getUserAppsRoles').and.callThrough();
+ component.changedSelectedUser = 'Test';
+ component.getUserAppsRoles();
+ expect(component.getUserAppsRoles).toHaveBeenCalledWith();
+ });
+
+
+
});
+
+@Component({selector: 'app-search-users', template: ''})
+class AppSearchUsersStubComponent {
+ @Input() searchTitle:any;
+ @Input() isSystemUser:any;
+ @Input() placeHolder:any;
+}
+
+@Component({selector: 'app-user-details-form', template: ''})
+class AppUserdetailsFormStubComponent {
+
+}
diff --git a/portal-FE-os/src/app/pages/users/user-details-form/user-details-form.component.spec.ts b/portal-FE-os/src/app/pages/users/user-details-form/user-details-form.component.spec.ts
index 3262174..b687cd5 100644
--- a/portal-FE-os/src/app/pages/users/user-details-form/user-details-form.component.spec.ts
+++ b/portal-FE-os/src/app/pages/users/user-details-form/user-details-form.component.spec.ts
@@ -1,6 +1,11 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { UserDetailsFormComponent } from './user-details-form.component';
+import { HttpClientTestingModule } from '@angular/common/http/testing';
+import { FormsModule, ReactiveFormsModule } from '@angular/forms';
+import { NgMaterialModule } from 'src/app/ng-material-module';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
+import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
describe('UserDetailsFormComponent', () => {
let component: UserDetailsFormComponent;
@@ -8,7 +13,9 @@
beforeEach(async(() => {
TestBed.configureTestingModule({
- declarations: [ UserDetailsFormComponent ]
+ declarations: [ UserDetailsFormComponent ],
+ imports:[HttpClientTestingModule,FormsModule,ReactiveFormsModule,NgMaterialModule,BrowserAnimationsModule],
+ providers:[NgbActiveModal]
})
.compileComponents();
}));
diff --git a/portal-FE-os/src/testing/router-link-directive-stub.ts b/portal-FE-os/src/testing/router-link-directive-stub.ts
new file mode 100644
index 0000000..73e75cb
--- /dev/null
+++ b/portal-FE-os/src/testing/router-link-directive-stub.ts
@@ -0,0 +1,14 @@
+import { Directive, Input, HostListener } from "@angular/core";
+
+@Directive({
+ selector: '[routerLink]'
+ })
+ export class RouterLinkDirectiveStub {
+ @Input('routerLink') linkParams: any;
+ navigatedTo: any = null;
+
+ @HostListener('click')
+ onClick() {
+ this.navigatedTo = this.linkParams;
+ }
+ }
\ No newline at end of file