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';
11 describe('FormFieldsComponent', () => {
12 let component: FormFieldsComponent;
13 let fixture: ComponentFixture<FormFieldsComponent>;
15 beforeEach(async(() => {
16 TestBed.configureTestingModule({
17 schemas:[CUSTOM_ELEMENTS_SCHEMA],
18 declarations: [ FormFieldsComponent ],
21 HttpClientTestingModule,
24 // BrowserAnimationsModule
31 fixture = TestBed.createComponent(FormFieldsComponent);
32 component = fixture.componentInstance;
33 fixture.detectChanges();
36 it('should create', () => {
37 expect(component).toBeTruthy();
40 it('should test isFirst method',()=>{
41 expect(component.isFirst(0)).toBe(true);
42 expect(component.isFirst(2)).toBe(false);
45 it('should test isLast method', () =>{
46 component.formFieldsListObj.length = 12;
47 expect(component.isLast(15)).toEqual(false);
50 it('should test ngDoCheck method',()=>{
51 component.sqlAsDefaultValue=true;
52 if(component.sqlAsDefaultValue==true){
53 expect(component.showDefaultSQLOption).toBe(false);
56 expect(component.showDefaultSQLOption).toBe(true);
60 it('should test setDisplayMode method',()=>{
61 component.setDisplayMode("setDisplayMode");
64 it('should test edit method',()=>{
69 it('should test add method',()=>{
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");
91 it('should test close method1',()=>{
92 component.showDialog=true;
94 expect(component.showDialog).toBe(false);
95 expect(component.closable).toBe(false);
98 it('should test close method2',()=>{
99 component.showDialog=false;
101 expect(component.showDialog).toBe(true);
102 expect(component.closable).toBe(false);
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);
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);
119 it('should test addToList method',()=>{
120 component.addToList("attrib")
122 expect(component.predefinedValueList.pop()).toEqual({id:'attrib', name:'attrib',selected:false});
126 it('should test deleteFromList method',()=>{
127 component.deleteFromList("attrib");
130 it('should test save method',()=>{
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);
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);
152 expect(component.finalPOSTObj["fieldDefalultSQL"]).toEqual(component.fieldDefaultSQL);
153 expect(component.finalPOSTObj["predefinedValueList"]).toEqual(component.predefinedValueList);