8d9003fcebe43a0397b5ce249dadbc1146c4acb4
[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
11 describe('FormFieldsComponent', () => {
12   let component: FormFieldsComponent;
13   let fixture: ComponentFixture<FormFieldsComponent>;
14
15   beforeEach(async(() => {
16     TestBed.configureTestingModule({
17       schemas:[CUSTOM_ELEMENTS_SCHEMA],
18       declarations: [ FormFieldsComponent ],
19       imports:[
20         FormsModule,
21         HttpClientTestingModule,
22         MatDialogModule,
23         MatSnackBarModule,
24        // BrowserAnimationsModule
25       ]
26     })
27     .compileComponents();
28   }));
29
30   beforeEach(() => {
31     fixture = TestBed.createComponent(FormFieldsComponent);
32     component = fixture.componentInstance;
33     fixture.detectChanges();
34   });
35
36   it('should create', () => {
37     expect(component).toBeTruthy();
38   });
39
40   it('should test isFirst method',()=>{
41     expect(component.isFirst(0)).toBe(true);
42     expect(component.isFirst(2)).toBe(false);
43   });
44
45   it('should test isLast method', () =>{
46     component.formFieldsListObj.length = 12;
47     expect(component.isLast(15)).toEqual(false);
48   });
49
50   it('should test ngDoCheck method',()=>{
51     component.sqlAsDefaultValue=true;
52     if(component.sqlAsDefaultValue==true){
53       expect(component.showDefaultSQLOption).toBe(false);
54     }
55     else{
56       expect(component.showDefaultSQLOption).toBe(true);
57     }
58  });
59
60    it('should test setDisplayMode method',()=>{
61       component.setDisplayMode("setDisplayMode");
62   });
63
64   it('should test edit method',()=>{
65     component.edit("Id");
66     
67   })
68
69  it('should test add method',()=>{
70    component.add();
71    expect(component.showDialog).toBe(true);
72    expect(component.closable).toBe(true);
73    expect(component.validationType).toEqual("");
74    expect(component.visible).toEqual("YES");
75    expect(component.message).toBe("");
76    expect(component.groupFormField).toBe(false);
77    expect(component.fieldType).toBe("");
78    expect(component.fieldSQL).toBe("");
79    expect(component.fieldName).toBe("");
80    expect(component.fieldId).toBe("");
81    expect(component.fieldDefaultSQL).toBe('');
82    expect(component.errorStackTrace).toBe("");
83    expect(component.errorMessage).toBe("");
84    expect(component.defaultValue).toBe(false);
85    expect(component.predefinedValueList).toEqual([]);
86    expect(component.showDialog).toBe(true);
87    expect(component.closable).toBe(true);
88    expect(component.mode).toEqual("Add");
89  });
90
91  it('should test close method1',()=>{
92    component.showDialog=true;
93    component.close();
94    expect(component.showDialog).toBe(false);
95    expect(component.closable).toBe(false);
96  });
97
98  it('should test close method2',()=>{
99   component.showDialog=false;
100   component.close();
101   expect(component.showDialog).toBe(true);
102   expect(component.closable).toBe(false);
103 });
104
105  it('should test loseValidateModal method1',()=>{
106    component.showDialog1=true;
107     component.closeValidateModal();
108     expect(component.showDialog1).toBe(false);
109     expect(component.showVerifySpinner).toBe(false);
110  })
111
112  it('should test loseValidateModal method2',()=>{
113   component.showDialog1=false;
114    component.closeValidateModal();
115    expect(component.showDialog1).toBe(true);
116    expect(component.showVerifySpinner).toBe(false);
117 });
118
119 it('should test addToList method',()=>{
120   component.addToList("attrib")
121   {
122   expect(component.predefinedValueList.pop()).toEqual({id:'attrib', name:'attrib',selected:false});
123   }
124 });
125
126 it('should test deleteFromList method',()=>{
127 component.deleteFromList("attrib");
128 });
129
130 it('should test save method',()=>{
131   component.save();
132   expect(component.showSpinner).toBe(true);
133   expect(component.showDialog).toBe(false);
134   expect(component.finalPOSTObj["validationType"]).toEqual(component.validationType);
135   if(component.visible=="YES")
136   expect(component.finalPOSTObj["visible"]).toBe(true);
137   else
138   expect(component.finalPOSTObj["visible"]).toBe(false);
139   expect(component.finalPOSTObj["orderSeq"]).toEqual(component.orderSeq);
140   expect(component.finalPOSTObj["message"]).toEqual(component.message);
141   expect(component.finalPOSTObj["groupFormField"]).toEqual(component.groupFormField);
142   expect(component.finalPOSTObj["fieldType"]).toEqual(component.fieldType);
143   expect(component.finalPOSTObj["fieldSQL"]).toEqual(component.fieldSQL);
144   expect(component.finalPOSTObj["fieldName"]).toEqual(component.fieldName);
145   expect(component.finalPOSTObj["fieldId"]).toEqual(component.fieldId);
146   expect(component.finalPOSTObj["errorStackTrace"]).toEqual(component.errorStackTrace);
147   expect(component.finalPOSTObj["errorMessage"]).toEqual(component.errorMessage);
148   expect(component.finalPOSTObj["defaultValue"]).toEqual(component.defaultValue);
149   if(component.defaultValue===false)
150     expect(component.finalPOSTObj["fieldDefaultSQL"]).toBe(null);
151   else
152   expect(component.finalPOSTObj["fieldDefalultSQL"]).toEqual(component.fieldDefaultSQL);
153   expect(component.finalPOSTObj["predefinedValueList"]).toEqual(component.predefinedValueList);
154   
155 });
156
157
158 });