From f45d43f248be5b0ffaad703fa50901f943214502 Mon Sep 17 00:00:00 2001 From: Indrijeet kumar Date: Thu, 5 Mar 2020 18:24:49 +0530 Subject: more test cases in form-fields component more test cases in form-fields component Issue-ID: PORTAL-813 Change-Id: Iaf4640c866527121b190171b301aff62446825ea Signed-off-by: Indrijeet Kumar --- .../form-fields/form-fields.component.spec.ts | 84 +++++++++++++++++----- 1 file changed, 66 insertions(+), 18 deletions(-) (limited to 'ecomp-sdk/epsdk-app-overlay') diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/form-fields/form-fields.component.spec.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/form-fields/form-fields.component.spec.ts index 8d9003fc..88010f96 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/form-fields/form-fields.component.spec.ts +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/form-fields/form-fields.component.spec.ts @@ -7,10 +7,14 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { MatDialogModule, MatSnackBarModule } from '@angular/material'; import { CommonModule } from '@angular/common'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { FormFieldsService } from './form-fields.service'; +import 'rxjs/add/observable/of'; +import { Observable } from 'rxjs/Observable'; describe('FormFieldsComponent', () => { let component: FormFieldsComponent; let fixture: ComponentFixture; + let _formfieldservice: FormFieldsService; beforeEach(async(() => { TestBed.configureTestingModule({ @@ -21,7 +25,7 @@ describe('FormFieldsComponent', () => { HttpClientTestingModule, MatDialogModule, MatSnackBarModule, - // BrowserAnimationsModule + BrowserAnimationsModule ] }) .compileComponents(); @@ -31,6 +35,7 @@ describe('FormFieldsComponent', () => { fixture = TestBed.createComponent(FormFieldsComponent); component = fixture.componentInstance; fixture.detectChanges(); + _formfieldservice=TestBed.get(FormFieldsService); }); it('should create', () => { @@ -42,28 +47,37 @@ describe('FormFieldsComponent', () => { expect(component.isFirst(2)).toBe(false); }); - it('should test isLast method', () =>{ + it('should test isLast method1 ', () =>{ component.formFieldsListObj.length = 12; expect(component.isLast(15)).toEqual(false); }); - it('should test ngDoCheck method',()=>{ + it('should test isLast method2 ', () =>{ + component.formFieldsListObj.length = 12; + expect(component.isLast(11)).toEqual(true); + }); + + it('should test ngDoCheck method for if condition',()=>{ component.sqlAsDefaultValue=true; - if(component.sqlAsDefaultValue==true){ - expect(component.showDefaultSQLOption).toBe(false); - } - else{ - expect(component.showDefaultSQLOption).toBe(true); - } + component.ngDoCheck(); + expect(component.showDefaultSQLOption).toBe(true); }); + it('should test ngDoCheck method for else condition',()=>{ + component.sqlAsDefaultValue!=true; + component.ngDoCheck(); + expect(component.showDefaultSQLOption).toBe(false); +}); + it('should test setDisplayMode method',()=>{ component.setDisplayMode("setDisplayMode"); }); it('should test edit method',()=>{ + component.fieldDefaultSQL!=null; + let spy=spyOn(_formfieldservice,'getFormFieldData').and.returnValue(Observable.of('you object')); component.edit("Id"); - + expect(spy).toHaveBeenCalled(); }) it('should test add method',()=>{ @@ -127,15 +141,15 @@ it('should test deleteFromList method',()=>{ component.deleteFromList("attrib"); }); -it('should test save method',()=>{ +it('should test save method1',()=>{ + + component.visible="YES"; + component.defaultValue=false; component.save(); expect(component.showSpinner).toBe(true); expect(component.showDialog).toBe(false); expect(component.finalPOSTObj["validationType"]).toEqual(component.validationType); - if(component.visible=="YES") expect(component.finalPOSTObj["visible"]).toBe(true); - else - expect(component.finalPOSTObj["visible"]).toBe(false); expect(component.finalPOSTObj["orderSeq"]).toEqual(component.orderSeq); expect(component.finalPOSTObj["message"]).toEqual(component.message); expect(component.finalPOSTObj["groupFormField"]).toEqual(component.groupFormField); @@ -146,13 +160,47 @@ it('should test save method',()=>{ expect(component.finalPOSTObj["errorStackTrace"]).toEqual(component.errorStackTrace); expect(component.finalPOSTObj["errorMessage"]).toEqual(component.errorMessage); expect(component.finalPOSTObj["defaultValue"]).toEqual(component.defaultValue); - if(component.defaultValue===false) - expect(component.finalPOSTObj["fieldDefaultSQL"]).toBe(null); - else - expect(component.finalPOSTObj["fieldDefalultSQL"]).toEqual(component.fieldDefaultSQL); + expect(component.finalPOSTObj["fieldDefaultSQL"]).toBe(null); expect(component.finalPOSTObj["predefinedValueList"]).toEqual(component.predefinedValueList); }); +it('should test save method for else part',()=>{ + component.visible!="YES"; + component.defaultValue!=false; + component.save(); + expect(component.finalPOSTObj["visible"]).toBe(false) + expect(component.finalPOSTObj["fieldDefalultSQL"]).toEqual(component.fieldDefaultSQL); +}) + +it('should test saveFormFieldGroups method',()=>{ + component.saveFormFieldGroups(); +}) + +it('should test openSnackBar method',()=>{ + component.openSnackBar('message','action'); +}) + +it('should test deleteGroup method',()=>{ + component.deleteGroup("string"); +}) + +it('should test deleteFormGroup method',()=>{ + component.deleteFromGroup("formgroup"); +}) + +it('should test delete method',()=>{ + component.delete("delete"); +}) + +it('should test verify method',()=>{ +component.verify("Default"); +component.verify("value"); + +}) + +// it('should test createGroup method',()=>{ +// component.openDialog() +// }) }); -- cgit 1.2.3-korg