Skip to content

Commit deeda5a

Browse files
jcorrea97alinelariguet
authored andcommitted
fix(tree-view): corrige funcionamento inadequado
corrige funcionamento inadequado ao selecionar um item e expandir outra arvore do componente fixes DTHFUI-6307
1 parent d95d795 commit deeda5a

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

projects/ui/src/lib/components/po-tree-view/po-tree-view-base.component.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ describe('PoTreeViewBaseComponent:', () => {
183183
expect(spyExpandParentItem).not.toHaveBeenCalled();
184184
});
185185

186-
it('addItem: should add parentItem in items and call expandParentItem, addChildItemInParent and selectItemBySubItems', () => {
186+
it('addItem: should add parentItem in items and call addChildItemInParent and selectItemBySubItems', () => {
187187
const childItem = { label: 'Nível 02', value: 2 };
188188
const parentItem = { label: 'Nível 01', value: 1 };
189189
const items = [];
@@ -196,6 +196,26 @@ describe('PoTreeViewBaseComponent:', () => {
196196

197197
component['addItem'](items, childItem, parentItem);
198198

199+
expect(items.length).toBe(1);
200+
expect(items).toEqual(expectedValue);
201+
expect(spySelectItemBySubItems).toHaveBeenCalledWith(parentItem);
202+
expect(spyAddChildItemInParent).toHaveBeenCalledWith(childItem, parentItem);
203+
expect(spyExpandParentItem).not.toHaveBeenCalledWith(childItem, parentItem);
204+
});
205+
206+
it('addItem: should add parentItem in items and call expandParentItem, addChildItemInParent and selectItemBySubItems', () => {
207+
const childItem = { label: 'Nível 02', value: 2 };
208+
const parentItem = { label: 'Nível 01', value: 1 };
209+
const items = [];
210+
211+
const expectedValue = [parentItem];
212+
213+
const spyExpandParentItem = spyOn(component, <any>'expandParentItem');
214+
const spyAddChildItemInParent = spyOn(component, <any>'addChildItemInParent');
215+
const spySelectItemBySubItems = spyOn(component, <any>'selectItemBySubItems');
216+
217+
component['addItem'](items, childItem, parentItem, true);
218+
199219
expect(items.length).toBe(1);
200220
expect(items).toEqual(expectedValue);
201221
expect(spySelectItemBySubItems).toHaveBeenCalledWith(parentItem);

projects/ui/src/lib/components/po-tree-view/po-tree-view-base.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ export class PoTreeViewBaseComponent {
123123
// - adiciona o childItem no parentItem;
124124
// - marca o parentItem caso conter subItems marcodos ou nulos;
125125
// Se não conter parentItem, adiciona o childItem no items.
126-
private addItem(items: Array<PoTreeViewItem>, childItem: PoTreeViewItem, parentItem?: PoTreeViewItem) {
126+
private addItem(items: Array<PoTreeViewItem>, childItem: PoTreeViewItem, parentItem?: PoTreeViewItem, isNewItem?) {
127127
if (parentItem) {
128-
this.expandParentItem(childItem, parentItem);
128+
if (isNewItem) {
129+
this.expandParentItem(childItem, parentItem);
130+
}
129131
this.addChildItemInParent(childItem, parentItem);
130132
this.selectItemBySubItems(parentItem);
131133

@@ -201,7 +203,7 @@ export class PoTreeViewBaseComponent {
201203
--level;
202204
}
203205

204-
this.addItem(newItems, currentItem, parentItem);
206+
this.addItem(newItems, currentItem, parentItem, true);
205207
});
206208

207209
return newItems;

0 commit comments

Comments
 (0)