88010f965f6ebfd1a969bea184a86c07703a322e
[portal/sdk.git] /
1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2
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';
13
14 describe('FormFieldsComponent', () => {
15   let component: FormFieldsComponent;
16   let fixture: ComponentFixture<FormFieldsComponent>;
17   let _formfieldservice: FormFieldsService;
18
19   beforeEach(async(() => {
20     TestBed.configureTestingModule({
21       schemas:[CUSTOM_ELEMENTS_SCHEMA],
22       declarations: [ FormFieldsComponent ],
23       imports:[
24         FormsModule,
25         HttpClientTestingModule,
26         MatDialogModule,
27         MatSnackBarModule,
28        BrowserAnimationsModule
29       ]
30     })
31     .compileComponents();
32   }));
33
34   beforeEach(() => {
35     fixture = TestBed.createComponent(FormFieldsComponent);
36     component = fixture.componentInstance;
37     fixture.detectChanges();
38     _formfieldservice=TestBed.get(FormFieldsService);
39   });
40
41   it('should create', () => {
42     expect(component).toBeTruthy();
43   });
44
45   it('should test isFirst method',()=>{
46     expect(component.isFirst(0)).toBe(true);
47     expect(component.isFirst(2)).toBe(false);
48   });
49
50   it('should test isLast method1 ', () =>{
51     component.formFieldsListObj.length = 12;
52     expect(component.isLast(15)).toEqual(false);
53   });
54
55   it('should test isLast method2 ', () =>{
56     component.formFieldsListObj.length = 12;
57     expect(component.isLast(11)).toEqual(true);
58   });
59
60   it('should test ngDoCheck method for if condition',()=>{
61     component.sqlAsDefaultValue=true;
62     component.ngDoCheck();
63     expect(component.showDefaultSQLOption).toBe(true);
64  });
65
66  it('should test ngDoCheck method for else condition',()=>{
67   component.sqlAsDefaultValue!=true;
68   component.ngDoCheck();
69   expect(component.showDefaultSQLOption).toBe(false);
70 });
71
72    it('should test setDisplayMode method',()=>{
73       component.setDisplayMode("setDisplayMode");
74   });
75
76   it('should test edit method',()=>{
77     component.fieldDefaultSQL!=null;
78     let spy=spyOn(_formfieldservice,'getFormFieldData').and.returnValue(Observable.of('you object'));
79     component.edit("Id");
80     expect(spy).toHaveBeenCalled();   
81   })
82
83  it('should test add method',()=>{
84    component.add();
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");
103  });
104
105  it('should test close method1',()=>{
106    component.showDialog=true;
107    component.close();
108    expect(component.showDialog).toBe(false);
109    expect(component.closable).toBe(false);
110  });
111
112  it('should test close method2',()=>{
113   component.showDialog=false;
114   component.close();
115   expect(component.showDialog).toBe(true);
116   expect(component.closable).toBe(false);
117 });
118
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);
124  })
125
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);
131 });
132
133 it('should test addToList method',()=>{
134   component.addToList("attrib")
135   {
136   expect(component.predefinedValueList.pop()).toEqual({id:'attrib', name:'attrib',selected:false});
137   }
138 });
139
140 it('should test deleteFromList method',()=>{
141 component.deleteFromList("attrib");
142 });
143
144 it('should test save method1',()=>{
145
146   component.visible="YES";
147   component.defaultValue=false;
148   component.save();
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);
165   
166 });
167
168 it('should test save method for else part',()=>{
169   component.visible!="YES";
170   component.defaultValue!=false;
171   component.save();
172   expect(component.finalPOSTObj["visible"]).toBe(false)
173   expect(component.finalPOSTObj["fieldDefalultSQL"]).toEqual(component.fieldDefaultSQL);
174 })
175
176 it('should test saveFormFieldGroups method',()=>{
177  component.saveFormFieldGroups();
178 })
179
180 it('should test openSnackBar method',()=>{
181   component.openSnackBar('message','action');
182 })
183
184 it('should test deleteGroup method',()=>{
185   component.deleteGroup("string");
186 })
187
188 it('should test deleteFormGroup method',()=>{
189   component.deleteFromGroup("formgroup");
190 })
191
192 it('should test delete method',()=>{
193   component.delete("delete");
194 })
195
196 it('should test verify method',()=>{
197 component.verify("Default");
198 component.verify("value");
199
200 })
201
202 // it('should test createGroup method',()=>{
203 //   component.openDialog()
204 // })
205
206 });