summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/form-fields/form-fields.component.spec.ts
blob: 8d9003fcebe43a0397b5ce249dadbc1146c4acb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { FormFieldsComponent } from './form-fields.component';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { MatDialogModule, MatSnackBarModule } from '@angular/material';
import { CommonModule } from '@angular/common';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

describe('FormFieldsComponent', () => {
  let component: FormFieldsComponent;
  let fixture: ComponentFixture<FormFieldsComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      schemas:[CUSTOM_ELEMENTS_SCHEMA],
      declarations: [ FormFieldsComponent ],
      imports:[
        FormsModule,
        HttpClientTestingModule,
        MatDialogModule,
        MatSnackBarModule,
       // BrowserAnimationsModule
      ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(FormFieldsComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should test isFirst method',()=>{
    expect(component.isFirst(0)).toBe(true);
    expect(component.isFirst(2)).toBe(false);
  });

  it('should test isLast method', () =>{
    component.formFieldsListObj.length = 12;
    expect(component.isLast(15)).toEqual(false);
  });

  it('should test ngDoCheck method',()=>{
    component.sqlAsDefaultValue=true;
    if(component.sqlAsDefaultValue==true){
      expect(component.showDefaultSQLOption).toBe(false);
    }
    else{
      expect(component.showDefaultSQLOption).toBe(true);
    }
 });

   it('should test setDisplayMode method',()=>{
      component.setDisplayMode("setDisplayMode");
  });

  it('should test edit method',()=>{
    component.edit("Id");
    
  })

 it('should test add method',()=>{
   component.add();
   expect(component.showDialog).toBe(true);
   expect(component.closable).toBe(true);
   expect(component.validationType).toEqual("");
   expect(component.visible).toEqual("YES");
   expect(component.message).toBe("");
   expect(component.groupFormField).toBe(false);
   expect(component.fieldType).toBe("");
   expect(component.fieldSQL).toBe("");
   expect(component.fieldName).toBe("");
   expect(component.fieldId).toBe("");
   expect(component.fieldDefaultSQL).toBe('');
   expect(component.errorStackTrace).toBe("");
   expect(component.errorMessage).toBe("");
   expect(component.defaultValue).toBe(false);
   expect(component.predefinedValueList).toEqual([]);
   expect(component.showDialog).toBe(true);
   expect(component.closable).toBe(true);
   expect(component.mode).toEqual("Add");
 });

 it('should test close method1',()=>{
   component.showDialog=true;
   component.close();
   expect(component.showDialog).toBe(false);
   expect(component.closable).toBe(false);
 });

 it('should test close method2',()=>{
  component.showDialog=false;
  component.close();
  expect(component.showDialog).toBe(true);
  expect(component.closable).toBe(false);
});

 it('should test loseValidateModal method1',()=>{
   component.showDialog1=true;
    component.closeValidateModal();
    expect(component.showDialog1).toBe(false);
    expect(component.showVerifySpinner).toBe(false);
 })

 it('should test loseValidateModal method2',()=>{
  component.showDialog1=false;
   component.closeValidateModal();
   expect(component.showDialog1).toBe(true);
   expect(component.showVerifySpinner).toBe(false);
});

it('should test addToList method',()=>{
  component.addToList("attrib")
  {
  expect(component.predefinedValueList.pop()).toEqual({id:'attrib', name:'attrib',selected:false});
  }
});

it('should test deleteFromList method',()=>{
component.deleteFromList("attrib");
});

it('should test save method',()=>{
  component.save();
  expect(component.showSpinner).toBe(true);
  expect(component.showDialog).toBe(false);
  expect(component.finalPOSTObj["validationType"]).toEqual(component.validationType);
  if(component.visible=="YES")
  expect(component.finalPOSTObj["visible"]).toBe(true);
  else
  expect(component.finalPOSTObj["visible"]).toBe(false);
  expect(component.finalPOSTObj["orderSeq"]).toEqual(component.orderSeq);
  expect(component.finalPOSTObj["message"]).toEqual(component.message);
  expect(component.finalPOSTObj["groupFormField"]).toEqual(component.groupFormField);
  expect(component.finalPOSTObj["fieldType"]).toEqual(component.fieldType);
  expect(component.finalPOSTObj["fieldSQL"]).toEqual(component.fieldSQL);
  expect(component.finalPOSTObj["fieldName"]).toEqual(component.fieldName);
  expect(component.finalPOSTObj["fieldId"]).toEqual(component.fieldId);
  expect(component.finalPOSTObj["errorStackTrace"]).toEqual(component.errorStackTrace);
  expect(component.finalPOSTObj["errorMessage"]).toEqual(component.errorMessage);
  expect(component.finalPOSTObj["defaultValue"]).toEqual(component.defaultValue);
  if(component.defaultValue===false)
    expect(component.finalPOSTObj["fieldDefaultSQL"]).toBe(null);
  else
  expect(component.finalPOSTObj["fieldDefalultSQL"]).toEqual(component.fieldDefaultSQL);
  expect(component.finalPOSTObj["predefinedValueList"]).toEqual(component.predefinedValueList);
  
});


});