diff options
author | 2018-08-29 17:01:32 +0300 | |
---|---|---|
committer | 2019-02-18 18:35:30 +0200 | |
commit | 6f900cc45d7dd7f97430812b86b5c1d1693c8ae3 (patch) | |
tree | 936005c364dc5a7264d6304d4777c3d83494db22 /vid-webpack-master/src/app/shared/components/dynamic-inputs/dynamic-inputs.component.spec.ts | |
parent | 67d99f816cc583643c35193197594cf78d8ce60a (diff) |
merge from ecomp a88f0072 - Modern UI
Issue-ID: VID-378
Change-Id: Ibcb23dd27f550cf32ce2fe0239f0f496ae014ff6
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-webpack-master/src/app/shared/components/dynamic-inputs/dynamic-inputs.component.spec.ts')
-rw-r--r-- | vid-webpack-master/src/app/shared/components/dynamic-inputs/dynamic-inputs.component.spec.ts | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/components/dynamic-inputs/dynamic-inputs.component.spec.ts b/vid-webpack-master/src/app/shared/components/dynamic-inputs/dynamic-inputs.component.spec.ts new file mode 100644 index 000000000..6194aad5e --- /dev/null +++ b/vid-webpack-master/src/app/shared/components/dynamic-inputs/dynamic-inputs.component.spec.ts @@ -0,0 +1,157 @@ +import {HttpClientTestingModule, HttpTestingController} from "@angular/common/http/testing"; +import {DynamicInputsComponent} from "./dynamic-inputs.component"; +import {async, ComponentFixture, getTestBed, TestBed} from "@angular/core/testing"; +import {CUSTOM_ELEMENTS_SCHEMA} from "@angular/core"; +import {FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, ValidatorFn} from "@angular/forms"; +import {BrowserModule} from "@angular/platform-browser"; +import {CommonModule} from "@angular/common"; +import {RouterTestingModule} from "@angular/router/testing"; +import {DynamicInputLabelPipe} from "../../pipes/dynamicInputLabel/dynamic-input-label.pipe"; +import {DynamicNumber} from "../../models/dynamicInput"; + + +describe('DynamicInputs Component', () => { + let component: DynamicInputsComponent; + let fixture: ComponentFixture<DynamicInputsComponent>; + + beforeAll(done => (async () => { + TestBed.configureTestingModule({ + imports: [BrowserModule, CommonModule, FormsModule, HttpClientTestingModule, RouterTestingModule, ReactiveFormsModule], + declarations: [DynamicInputsComponent, DynamicInputLabelPipe], + providers : [FormBuilder], + schemas: [ CUSTOM_ELEMENTS_SCHEMA ] + }); + await TestBed.compileComponents(); + + fixture = TestBed.createComponent(DynamicInputsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + })().then(done).catch(done.fail)); + + test('should be defined', () => { + expect(component).toBeDefined(); + }); + + test('isDynamicNumber should return item', () => { + let options = { + minLength : 10, + maxLength : 10 + }; + + let dynamicNumber : DynamicNumber = new DynamicNumber(<any>options); + expect(component.isDynamicNumber(dynamicNumber)).toBeDefined(); + }); + + test('buildValidators should return validator', () => { + let options = { + minLength : 10, + maxLength : 10, + max : 10, + min : 1 + }; + + let dynamicNumber : DynamicNumber = new DynamicNumber(<any>options); + let validator : ValidatorFn = component.buildValidators(dynamicNumber); + expect(validator).toBeDefined(); + }); + + + test('ngOnInit', ()=>{ + component.group = new FormGroup({ + + }); + component.list = [ + { + type : 'select', + value : 'optionName', + name : 'multiSelectControl', + optionList : [{ + isDataLoading : true, + name : 'optionName', + id : 'id' + }] + }, + { + type : 'select', + value : 'optionName', + name : 'multiSelectControl', + optionList : [{ + isDataLoading : true, + name : 'optionName', + id : 'id' + }] + }, + { + type : 'multi_select', + value : 'optionName', + name : 'selectControl', + optionList : [{ + isDataLoading : true, + name : 'optionName', + id : 'id' + }] + }, + { + type : 'multi_select', + value : 'optionName', + name : 'selectControl', + optionList : [{ + isDataLoading : true, + name : 'optionName' + }] + }, + { + type : 'boolean', + value : true, + name : 'booleanControl' + }, + { + type : 'boolean', + name : 'booleanControl2' + }, + { + type : 'number', + value : 100, + name : 'numberControl' + }, + { + type : 'file', + value : 'someValue', + name : 'fileControl' + }, + { + type : 'checkbox', + value : true, + name : 'checkboxControl' + }, + { + type : 'map', + value : true, + name : 'mapControl' + }, + { + type : 'list', + value : true, + name : 'listControl' + }, + { + type : 'default', + value : true, + name : 'defaultControl' + } + ]; + + component.ngOnInit(); + expect(component.group.controls['multiSelectControl'].value).toEqual('id'); + expect(component.group.controls['selectControl'].value).toEqual('optionName'); + expect(component.group.controls['booleanControl'].value).toEqual(true); + expect(component.group.controls['booleanControl2'].value).toEqual(false); + expect(component.group.controls['numberControl'].value).toEqual(100); + expect(component.group.controls['fileControl'].value).toEqual('someValue'); + expect(component.group.controls['checkboxControl'].value).toEqual(true); + expect(component.group.controls['mapControl'].value).toEqual(true); + expect(component.group.controls['listControl'].value).toEqual(true); + expect(component.group.controls['defaultControl'].value).toEqual(true); + }) + +}); |