1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 import { FormFieldsComponent } from './form-fields.component';
4 import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
5 import { FormsModule } from '@angular/forms';
6 import { HttpClientTestingModule } from '@angular/common/http/testing';
7 import { MatDialogModule, MatSnackBarModule } from '@angular/material';
8 import { CommonModule } from '@angular/common';
9 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
10 import { FormFieldsService } from './form-fields.service';
11 import 'rxjs/add/observable/of';
12 import { Observable } from 'rxjs/Observable';
14 describe('FormFieldsComponent', () => {
15 let component: FormFieldsComponent;
16 let fixture: ComponentFixture<FormFieldsComponent>;
17 let _formfieldservice: FormFieldsService;
19 beforeEach(async(() => {
20 TestBed.configureTestingModule({
21 schemas:[CUSTOM_ELEMENTS_SCHEMA],
22 declarations: [ FormFieldsComponent ],
25 HttpClientTestingModule,
28 BrowserAnimationsModule
35 fixture = TestBed.createComponent(FormFieldsComponent);
36 component = fixture.componentInstance;
37 fixture.detectChanges();
38 _formfieldservice=TestBed.get(FormFieldsService);
41 it('should create', () => {
42 expect(component).toBeTruthy();
45 it('should test isFirst method',()=>{
46 expect(component.isFirst(0)).toBe(true);
47 expect(component.isFirst(2)).toBe(false);
50 it('should test isLast method1 ', () =>{
51 component.formFieldsListObj.length = 12;
52 expect(component.isLast(15)).toEqual(false);
55 it('should test isLast method2 ', () =>{
56 component.formFieldsListObj.length = 12;
57 expect(component.isLast(11)).toEqual(true);
60 it('should test ngDoCheck method for if condition',()=>{
61 component.sqlAsDefaultValue=true;
62 component.ngDoCheck();
63 expect(component.showDefaultSQLOption).toBe(true);
66 it('should test ngDoCheck method for else condition',()=>{
67 component.sqlAsDefaultValue!=true;
68 component.ngDoCheck();
69 expect(component.showDefaultSQLOption).toBe(false);
72 it('should test setDisplayMode method',()=>{
73 component.setDisplayMode("setDisplayMode");
76 it('should test edit method',()=>{
77 component.fieldDefaultSQL!=null;
78 let spy=spyOn(_formfieldservice,'getFormFieldData').and.returnValue(Observable.of('you object'));
80 expect(spy).toHaveBeenCalled();
83 it('should test add method',()=>{
85 expect(component.showDialog).toBe(true);
86 expect(component.closable).toBe(true);
87 expect(component.validationType).toEqual("");
88 expect(component.visible).toEqual("YES");
89 expect(component.message).toBe("");
90 expect(component.groupFormField).toBe(false);
91 expect(component.fieldType).toBe("");
92 expect(component.fieldSQL).toBe("");
93 expect(component.fieldName).toBe("");
94 expect(component.fieldId).toBe("");
95 expect(component.fieldDefaultSQL).toBe('');
96 expect(component.errorStackTrace).toBe("");
97 expect(component.errorMessage).toBe("");
98 expect(component.defaultValue).toBe(false);
99 expect(component.predefinedValueList).toEqual([]);
100 expect(component.showDialog).toBe(true);
101 expect(component.closable).toBe(true);
102 expect(component.mode).toEqual("Add");
105 it('should test close method1',()=>{
106 component.showDialog=true;
108 expect(component.showDialog).toBe(false);
109 expect(component.closable).toBe(false);
112 it('should test close method2',()=>{
113 component.showDialog=false;
115 expect(component.showDialog).toBe(true);
116 expect(component.closable).toBe(false);
119 it('should test loseValidateModal method1',()=>{
120 component.showDialog1=true;
121 component.closeValidateModal();
122 expect(component.showDialog1).toBe(false);
123 expect(component.showVerifySpinner).toBe(false);
126 it('should test loseValidateModal method2',()=>{
127 component.showDialog1=false;
128 component.closeValidateModal();
129 expect(component.showDialog1).toBe(true);
130 expect(component.showVerifySpinner).toBe(false);
133 it('should test addToList method',()=>{
134 component.addToList("attrib")
136 expect(component.predefinedValueList.pop()).toEqual({id:'attrib', name:'attrib',selected:false});
140 it('should test deleteFromList method',()=>{
141 component.deleteFromList("attrib");
144 it('should test save method1',()=>{
146 component.visible="YES";
147 component.defaultValue=false;
149 expect(component.showSpinner).toBe(true);
150 expect(component.showDialog).toBe(false);
151 expect(component.finalPOSTObj["validationType"]).toEqual(component.validationType);
152 expect(component.finalPOSTObj["visible"]).toBe(true);
153 expect(component.finalPOSTObj["orderSeq"]).toEqual(component.orderSeq);
154 expect(component.finalPOSTObj["message"]).toEqual(component.message);
155 expect(component.finalPOSTObj["groupFormField"]).toEqual(component.groupFormField);
156 expect(component.finalPOSTObj["fieldType"]).toEqual(component.fieldType);
157 expect(component.finalPOSTObj["fieldSQL"]).toEqual(component.fieldSQL);
158 expect(component.finalPOSTObj["fieldName"]).toEqual(component.fieldName);
159 expect(component.finalPOSTObj["fieldId"]).toEqual(component.fieldId);
160 expect(component.finalPOSTObj["errorStackTrace"]).toEqual(component.errorStackTrace);
161 expect(component.finalPOSTObj["errorMessage"]).toEqual(component.errorMessage);
162 expect(component.finalPOSTObj["defaultValue"]).toEqual(component.defaultValue);
163 expect(component.finalPOSTObj["fieldDefaultSQL"]).toBe(null);
164 expect(component.finalPOSTObj["predefinedValueList"]).toEqual(component.predefinedValueList);
168 it('should test save method for else part',()=>{
169 component.visible!="YES";
170 component.defaultValue!=false;
172 expect(component.finalPOSTObj["visible"]).toBe(false)
173 expect(component.finalPOSTObj["fieldDefalultSQL"]).toEqual(component.fieldDefaultSQL);
176 it('should test saveFormFieldGroups method',()=>{
177 component.saveFormFieldGroups();
180 it('should test openSnackBar method',()=>{
181 component.openSnackBar('message','action');
184 it('should test deleteGroup method',()=>{
185 component.deleteGroup("string");
188 it('should test deleteFormGroup method',()=>{
189 component.deleteFromGroup("formgroup");
192 it('should test delete method',()=>{
193 component.delete("delete");
196 it('should test verify method',()=>{
197 component.verify("Default");
198 component.verify("value");
202 // it('should test createGroup method',()=>{
203 // component.openDialog()