Skip to content

Commit

Permalink
object tree model sorter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno authored and sandy081 committed Feb 22, 2019
1 parent c8973aa commit b410d91
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/vs/base/browser/ui/tree/objectTreeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export class ObjectTreeModel<T extends NonNullable<any>, TFilterData extends Non
const node = this.nodes.get(treeElement.element);

if (!node) {
return treeElement;
return {
...treeElement,
children: this.preserveCollapseState(treeElement.children)
};
}

const collapsible = typeof treeElement.collapsible === 'boolean' ? treeElement.collapsible : node.collapsible;
Expand Down
15 changes: 15 additions & 0 deletions src/vs/base/test/browser/ui/tree/objectTreeModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,19 @@ suite('ObjectTreeModel', function () {
model.setChildren(null, data);
assert.deepEqual(toArray(list), ['father']);
});

test('sorter', () => {
let compare: (a: string, b: string) => number = (a, b) => a < b ? -1 : 1;

const list: ITreeNode<string>[] = [];
const model = new ObjectTreeModel<string>(toSpliceable(list), { sorter: { compare(a, b) { return compare(a, b); } } });
const data = [
{ element: 'cars', children: [{ element: 'sedan' }, { element: 'convertible' }, { element: 'compact' }] },
{ element: 'airplanes', children: [{ element: 'passenger' }, { element: 'jet' }] },
{ element: 'bicycles', children: [{ element: 'dutch' }, { element: 'mountain' }, { element: 'electric' }] },
];

model.setChildren(null, data);
assert.deepEqual(toArray(list), ['airplanes', 'jet', 'passenger', 'bicycles', 'dutch', 'electric', 'mountain', 'cars', 'compact', 'convertible', 'sedan']);
});
});

0 comments on commit b410d91

Please sign in to comment.