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