From 3a721943acc7e67b53d3513d325ee52df27a113e Mon Sep 17 00:00:00 2001 From: bykov Date: Tue, 17 Jan 2017 12:44:26 +0300 Subject: [PATCH] Fix #339 --- src/core/nested-option.ts | 6 ++-- tests/src/ui/toolbar.spec.ts | 63 ++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 tests/src/ui/toolbar.spec.ts diff --git a/src/core/nested-option.ts b/src/core/nested-option.ts index 7006c55bb..aa8d92def 100644 --- a/src/core/nested-option.ts +++ b/src/core/nested-option.ts @@ -67,13 +67,13 @@ export class CollectionNestedOptionContainerImpl implements ICollectionNestedOpt constructor(private _setOption: Function, private _filterItems?: Function) {} setChildren(propertyName: string, items: QueryList) { + if (this._filterItems) { + items = this._filterItems(items); + } if (items.length) { this._activatedQueries[propertyName] = true; } if (this._activatedQueries[propertyName]) { - if (this._filterItems) { - items = this._filterItems(items); - } let widgetItems = items.map((item, index) => { item._index = index; return item._value; diff --git a/tests/src/ui/toolbar.spec.ts b/tests/src/ui/toolbar.spec.ts new file mode 100644 index 000000000..adcc8dcc9 --- /dev/null +++ b/tests/src/ui/toolbar.spec.ts @@ -0,0 +1,63 @@ +/* tslint:disable:component-selector */ + +import { + Component, + ViewChildren, + QueryList +} from '@angular/core'; + +import { + TestBed, + async +} from '@angular/core/testing'; + +import DxToolbar from 'devextreme/ui/toolbar'; + +import { + DxToolbarModule, + DxToolbarComponent +} from '../../../dist'; + +@Component({ + selector: 'test-container-component', + template: '' +}) +class TestContainerComponent { + @ViewChildren(DxToolbarComponent) innerWidgets: QueryList; +} + +describe('DxToolbar', () => { + + beforeEach(() => { + TestBed.configureTestingModule( + { + declarations: [TestContainerComponent], + imports: [DxToolbarModule] + }); + }); + + function getWidget(fixture) { + let widgetElement = fixture.nativeElement.querySelector('.dx-toolbar') || fixture.nativeElement; + return DxToolbar['getInstance'](widgetElement); + } + + // spec + it('should not initialize the "items" property of an item if no children are declared inside the item (T472434)', async(() => { + TestBed.overrideComponent(TestContainerComponent, { + set: { + template: ` + + Item1 + + ` + } + }); + let fixture = TestBed.createComponent(TestContainerComponent); + fixture.detectChanges(); + + let instance = getWidget(fixture); + expect(instance.option('items')[0].items).toBe(undefined); + expect(instance.element().find('.dx-toolbar-item').text()).toBe('Item1'); + })); + +});