From 57baaebb30d73fe377b7c05c76d61c2bdd560af4 Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Thu, 20 Oct 2016 14:06:44 +0100 Subject: [PATCH 1/4] Fix typehead visibility --- .../widgets/typeahead/typeahead.widget.html | 3 +- .../typeahead/typeahead.widget.spec.ts | 61 ++++++++++++++----- .../widgets/typeahead/typeahead.widget.ts | 2 + 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.html b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.html index f2416b77001..77dfc9e853d 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.html +++ b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.html @@ -1,11 +1,10 @@
+ [class.typeahead-widget__invalid]="!field.isValid" id="typehead-div"> diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts index 5cb375a4978..94d4a3637e1 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts @@ -21,6 +21,10 @@ import { FormService } from '../../../services/form.service'; import { FormModel } from '../core/form.model'; import { FormFieldModel } from '../core/form-field.model'; import { FormFieldOption } from '../core/form-field-option'; +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { FakeFormService } from './assets/formService.service.mock'; +import { CoreModule } from 'ng2-alfresco-core'; +// import { fakeFormJson } from '../../../services/assets/widget-visibility.service.mock'; describe('TypeaheadWidget', () => { @@ -152,8 +156,8 @@ describe('TypeaheadWidget', () => { it('should setup initial value', () => { spyOn(formService, 'getRestFieldValues').and.returnValue(Observable.create(observer => { observer.next([ - { id: '1', name: 'One' }, - { id: '2', name: 'Two' } + {id: '1', name: 'One'}, + {id: '2', name: 'Two'} ]); observer.complete(); })); @@ -168,8 +172,8 @@ describe('TypeaheadWidget', () => { it('should not setup initial value due to missing option', () => { spyOn(formService, 'getRestFieldValues').and.returnValue(Observable.create(observer => { observer.next([ - { id: '1', name: 'One' }, - { id: '2', name: 'Two' } + {id: '1', name: 'One'}, + {id: '2', name: 'Two'} ]); observer.complete(); })); @@ -183,8 +187,8 @@ describe('TypeaheadWidget', () => { it('should setup field options on load', () => { let options: FormFieldOption[] = [ - { id: '1', name: 'One' }, - { id: '2', name: 'Two' } + {id: '1', name: 'One'}, + {id: '2', name: 'Two'} ]; spyOn(formService, 'getRestFieldValues').and.returnValue(Observable.create(observer => { @@ -209,8 +213,8 @@ describe('TypeaheadWidget', () => { it('should get filtered options', () => { let options: FormFieldOption[] = [ - { id: '1', name: 'Item one' }, - { id: '2', name: 'Item two'} + {id: '1', name: 'Item one'}, + {id: '2', name: 'Item two'} ]; widget.field.options = options; widget.value = 'tw'; @@ -222,8 +226,8 @@ describe('TypeaheadWidget', () => { it('should be case insensitive when filtering options', () => { let options: FormFieldOption[] = [ - { id: '1', name: 'Item one' }, - { id: '2', name: 'iTEM TWo' } + {id: '1', name: 'Item one'}, + {id: '2', name: 'iTEM TWo'} ]; widget.field.options = options; widget.value = 'tW'; @@ -247,8 +251,8 @@ describe('TypeaheadWidget', () => { it('should flush selected value', () => { let options: FormFieldOption[] = [ - { id: '1', name: 'Item one' }, - { id: '2', name: 'Item Two' } + {id: '1', name: 'Item one'}, + {id: '2', name: 'Item Two'} ]; widget.field.options = options; @@ -261,8 +265,8 @@ describe('TypeaheadWidget', () => { it('should be case insensitive when flushing value', () => { let options: FormFieldOption[] = [ - { id: '1', name: 'Item one' }, - { id: '2', name: 'iTEM TWo' } + {id: '1', name: 'Item one'}, + {id: '2', name: 'iTEM TWo'} ]; widget.field.options = options; @@ -308,4 +312,33 @@ describe('TypeaheadWidget', () => { expect(widget.field.value).toBeNull(); }); + it('should emit field change event on item click', () => { + let event = jasmine.createSpyObj('event', ['preventDefault']); + let fakeField = new FormFieldModel(new FormModel(), {id: 'fakeField', value: 'fakeValue'}); + widget.field = fakeField; + let item = {id: 'fake-id-opt', name: 'fake-name-opt'}; + widget.onItemClick(item, event); + + widget.fieldChanged.subscribe((field) => { + expect(field).toBeDefined(); + expect(field.id).toEqual('fakeField'); + expect(field.value).toEqual('fake-id-opt'); + }); + }); + + it('should emit field change event on blur', (done) => { + spyOn(widget, 'flushValue').and.stub(); + let fakeField = new FormFieldModel(new FormModel(), {id: 'fakeField', value: 'fakeValue'}); + widget.field = fakeField; + widget.onBlur(); + + setTimeout(() => { + widget.fieldChanged.subscribe((field) => { + expect(field).toBeDefined(); + expect(field.id).toEqual('field-id'); + expect(field.value).toEqual('field-value'); + }); + done(); + }, 200); + }); }); diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.ts index 8bdbca48b9c..8b7cc360483 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.ts @@ -81,6 +81,7 @@ export class TypeaheadWidget extends WidgetComponent implements OnInit { onBlur() { setTimeout(() => { this.flushValue(); + this.checkVisibility(this.field); }, 200); } @@ -108,6 +109,7 @@ export class TypeaheadWidget extends WidgetComponent implements OnInit { if (item) { this.field.value = item.id; this.value = item.name; + this.checkVisibility(this.field); } if (event) { event.preventDefault(); From 632009f4681b0eed03843756a45239cbb096b67b Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Thu, 20 Oct 2016 15:08:52 +0100 Subject: [PATCH 2/4] Removed unused imports --- .../src/components/widgets/typeahead/typeahead.widget.spec.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts index 94d4a3637e1..648bc7a68b8 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts @@ -21,10 +21,6 @@ import { FormService } from '../../../services/form.service'; import { FormModel } from '../core/form.model'; import { FormFieldModel } from '../core/form-field.model'; import { FormFieldOption } from '../core/form-field-option'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; -import { FakeFormService } from './assets/formService.service.mock'; -import { CoreModule } from 'ng2-alfresco-core'; -// import { fakeFormJson } from '../../../services/assets/widget-visibility.service.mock'; describe('TypeaheadWidget', () => { From c994adf22b08a8e99de26d3614a3d6fbf56603ef Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Thu, 20 Oct 2016 15:12:26 +0100 Subject: [PATCH 3/4] Readded wrongly removed spaces --- .../typeahead/typeahead.widget.spec.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts index 648bc7a68b8..abd38148299 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts @@ -152,8 +152,8 @@ describe('TypeaheadWidget', () => { it('should setup initial value', () => { spyOn(formService, 'getRestFieldValues').and.returnValue(Observable.create(observer => { observer.next([ - {id: '1', name: 'One'}, - {id: '2', name: 'Two'} + { id: '1', name: 'One' }, + { id: '2', name: 'Two' } ]); observer.complete(); })); @@ -168,8 +168,8 @@ describe('TypeaheadWidget', () => { it('should not setup initial value due to missing option', () => { spyOn(formService, 'getRestFieldValues').and.returnValue(Observable.create(observer => { observer.next([ - {id: '1', name: 'One'}, - {id: '2', name: 'Two'} + { id: '1', name: 'One' }, + { id: '2', name: 'Two' } ]); observer.complete(); })); @@ -183,8 +183,8 @@ describe('TypeaheadWidget', () => { it('should setup field options on load', () => { let options: FormFieldOption[] = [ - {id: '1', name: 'One'}, - {id: '2', name: 'Two'} + { id: '1', name: 'One' }, + { id: '2', name: 'Two' } ]; spyOn(formService, 'getRestFieldValues').and.returnValue(Observable.create(observer => { @@ -209,8 +209,8 @@ describe('TypeaheadWidget', () => { it('should get filtered options', () => { let options: FormFieldOption[] = [ - {id: '1', name: 'Item one'}, - {id: '2', name: 'Item two'} + { id: '1', name: 'Item one' }, + { id: '2', name: 'Item two' } ]; widget.field.options = options; widget.value = 'tw'; @@ -222,8 +222,8 @@ describe('TypeaheadWidget', () => { it('should be case insensitive when filtering options', () => { let options: FormFieldOption[] = [ - {id: '1', name: 'Item one'}, - {id: '2', name: 'iTEM TWo'} + { id: '1', name: 'Item one' }, + { id: '2', name: 'iTEM TWo' } ]; widget.field.options = options; widget.value = 'tW'; From d14ee88a2f6e6726178bdcf99575111306579274 Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Thu, 20 Oct 2016 15:15:10 +0100 Subject: [PATCH 4/4] Readded some more spaced for graph --- .../widgets/typeahead/typeahead.widget.spec.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts index abd38148299..03e0b906d2e 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts @@ -247,8 +247,8 @@ describe('TypeaheadWidget', () => { it('should flush selected value', () => { let options: FormFieldOption[] = [ - {id: '1', name: 'Item one'}, - {id: '2', name: 'Item Two'} + { id: '1', name: 'Item one' }, + { id: '2', name: 'Item Two' } ]; widget.field.options = options; @@ -261,8 +261,8 @@ describe('TypeaheadWidget', () => { it('should be case insensitive when flushing value', () => { let options: FormFieldOption[] = [ - {id: '1', name: 'Item one'}, - {id: '2', name: 'iTEM TWo'} + { id: '1', name: 'Item one' }, + { id: '2', name: 'iTEM TWo' } ]; widget.field.options = options; @@ -275,8 +275,8 @@ describe('TypeaheadWidget', () => { it('should reset fields when flushing missing option value', () => { widget.field.options = [ - {id: '1', name: 'Item one'}, - {id: '2', name: 'Item two'} + { id: '1', name: 'Item one' }, + { id: '2', name: 'Item two' } ]; widget.value = 'Missing item'; widget.flushValue(); @@ -287,8 +287,8 @@ describe('TypeaheadWidget', () => { it('should reset fields when flushing incorrect value', () => { widget.field.options = [ - {id: '1', name: 'Item one'}, - {id: '2', name: 'Item two'} + { id: '1', name: 'Item one' }, + { id: '2', name: 'Item two' } ]; widget.field.value = 'Item two'; widget.value = 'Item two!';