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;
18 let fieldDefaultSQL : string;
20 beforeEach(async(() => {
21 TestBed.configureTestingModule({
22 schemas:[CUSTOM_ELEMENTS_SCHEMA],
23 declarations: [ FormFieldsComponent ],
26 HttpClientTestingModule,
29 BrowserAnimationsModule
36 fixture = TestBed.createComponent(FormFieldsComponent);
37 component = fixture.componentInstance;
38 fixture.detectChanges();
39 _formfieldservice=TestBed.get(FormFieldsService);
42 it('should create', () => {
43 expect(component).toBeTruthy();
46 it('should test isFirst method',()=>{
47 expect(component.isFirst(0)).toBe(true);
48 expect(component.isFirst(2)).toBe(false);
51 it('should test isLast method1 ', () =>{
52 component.formFieldsListObj.length = 12;
53 expect(component.isLast(15)).toEqual(false);
56 it('should test isLast method2 ', () =>{
57 component.formFieldsListObj.length = 12;
58 expect(component.isLast(11)).toEqual(true);
61 it('should test ngDoCheck method for if condition',()=>{
62 component.sqlAsDefaultValue=true;
63 component.ngDoCheck();
64 expect(component.showDefaultSQLOption).toBe(true);
67 it('should test ngDoCheck method for else condition',()=>{
68 component.sqlAsDefaultValue!=true;
69 component.ngDoCheck();
70 expect(component.showDefaultSQLOption).toBe(false);
73 it('should test setDisplayMode method',()=>{
74 component.setDisplayMode("setDisplayMode");
77 it('should test edit method',()=>{
78 component.fieldDefaultSQL!=null;
79 let spy=spyOn(_formfieldservice,'getFormFieldData').and.returnValue(Observable.of('you object'));
81 expect(spy).toHaveBeenCalled();
84 it('should test add method',()=>{
86 expect(component.showDialog).toBe(true);
87 expect(component.closable).toBe(true);
88 expect(component.validationType).toEqual("");
89 expect(component.visible).toEqual("YES");
90 expect(component.message).toBe("");
91 expect(component.groupFormField).toBe(false);
92 expect(component.fieldType).toBe("");
93 expect(component.fieldSQL).toBe("");
94 expect(component.fieldName).toBe("");
95 expect(component.fieldId).toBe("");
96 expect(component.fieldDefaultSQL).toBe('');
97 expect(component.errorStackTrace).toBe("");
98 expect(component.errorMessage).toBe("");
99 expect(component.defaultValue).toBe("");
100 expect(component.predefinedValueList).toEqual([]);
101 expect(component.showDialog).toBe(true);
102 expect(component.closable).toBe(true);
103 expect(component.mode).toEqual("Add");
106 it('should test close method1',()=>{
107 component.showDialog=true;
109 expect(component.showDialog).toBe(false);
110 expect(component.closable).toBe(false);
113 it('should test close method2',()=>{
114 component.showDialog=false;
116 expect(component.showDialog).toBe(true);
117 expect(component.closable).toBe(false);
120 it('should test loseValidateModal method1',()=>{
121 component.showDialog1=true;
122 component.closeValidateModal();
123 expect(component.showDialog1).toBe(false);
124 expect(component.showVerifySpinner).toBe(false);
127 it('should test loseValidateModal method2',()=>{
128 component.showDialog1=false;
129 component.closeValidateModal();
130 expect(component.showDialog1).toBe(true);
131 expect(component.showVerifySpinner).toBe(false);
134 it('should test addToList method',()=>{
135 component.addToList("attrib")
137 expect(component.predefinedValueList.pop()).toEqual({id:'attrib', name:'attrib',selected:false});
141 it('should test deleteFromList method',()=>{
142 component.deleteFromList("attrib");
145 it('should test save method1',()=>{
147 component.visible="YES";
148 component.defaultValue=false;
150 expect(component.showSpinner).toBe(true);
151 expect(component.showDialog).toBe(false);
152 expect(component.finalPOSTObj["validationType"]).toEqual(component.validationType);
153 expect(component.finalPOSTObj["visible"]).toBe(true);
154 expect(component.finalPOSTObj["orderSeq"]).toEqual(component.orderSeq);
155 expect(component.finalPOSTObj["message"]).toEqual(component.message);
156 expect(component.finalPOSTObj["groupFormField"]).toEqual(component.groupFormField);
157 expect(component.finalPOSTObj["fieldType"]).toEqual(component.fieldType);
158 expect(component.finalPOSTObj["fieldSQL"]).toEqual(component.fieldSQL);
159 expect(component.finalPOSTObj["fieldName"]).toEqual(component.fieldName);
160 expect(component.finalPOSTObj["fieldId"]).toEqual(component.fieldId);
161 expect(component.finalPOSTObj["errorStackTrace"]).toEqual(component.errorStackTrace);
162 expect(component.finalPOSTObj["errorMessage"]).toEqual(component.errorMessage);
163 expect(component.finalPOSTObj["defaultValue"]).toEqual(component.defaultValue);
164 expect(component.finalPOSTObj["fieldDefaultSQL"]).toBe(fieldDefaultSQL);
165 expect(component.finalPOSTObj["predefinedValueList"]).toEqual(component.predefinedValueList);
169 it('should test save method for else part',()=>{
170 component.visible!="YES";
171 component.defaultValue!=false;
173 expect(component.finalPOSTObj["visible"]).toBe(false)
174 expect(component.finalPOSTObj["fieldDefalultSQL"]).toEqual(component.fieldDefaultSQL);
177 it('should test saveFormFieldGroups method',()=>{
178 component.saveFormFieldGroups();
181 it('should test openSnackBar method',()=>{
182 component.openSnackBar('message','action');
185 it('should test deleteGroup method',()=>{
186 component.deleteGroup("string");
189 it('should test deleteFormGroup method',()=>{
190 component.deleteFromGroup("formgroup");
193 it('should test delete method',()=>{
194 component.delete("delete");
197 it('should test verify method',()=>{
198 component.verify("Default");
199 component.verify("value");
203 // it('should test createGroup method',()=>{
204 // component.openDialog()