Skip to content

Commit

Permalink
fix #7399: ensure that on expansion nodes are refreshed
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Mar 23, 2020
1 parent 868061f commit cc9453d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
40 changes: 38 additions & 2 deletions packages/core/src/browser/tree/tree-expansion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { expect } from 'chai';
import { expect, assert } from 'chai';
import { MockTreeModel } from './test/mock-tree-model';
import { TreeModel } from './tree-model';
import { TreeNode, CompositeTreeNode } from './tree';
import { TreeNode, CompositeTreeNode, Tree, TreeImpl } from './tree';
import { ExpandableTreeNode } from './tree-expansion';
import { createTreeTestContainer } from './test/tree-test-container';
import { timeout } from '../../common/promise-util';

/* eslint-disable no-unused-expressions */
describe('TreeExpansionService', () => {
Expand Down Expand Up @@ -127,6 +128,41 @@ describe('TreeExpansionService', () => {
});
});

it('node should be refreshed on expansion', async () => {
const container = createTreeTestContainer();
container.rebind(Tree).to(class extends TreeImpl {

protected async resolveChildren(parent: CompositeTreeNode): Promise<TreeNode[]> {
await timeout(200);
return [{
id: 'child',
parent
}];
}

});
const root: ExpandableTreeNode = {
id: 'parent',
parent: undefined,
children: [],
expanded: false
};

const treeModel = container.get<TreeModel>(TreeModel);
treeModel.root = root;

assert.isFalse(root.expanded, 'before');
assert.equal(root.children.length, 0, 'before');

const expanding = treeModel.expandNode(root);
assert.isFalse(root.expanded, 'between');
assert.equal(root.children.length, 0, 'between');

await expanding;
assert.isTrue(root.expanded, 'after');
assert.equal(root.children.length, 1, 'after');
});

function createTreeModel(): TreeModel {
const container = createTreeTestContainer();
return container.get(TreeModel);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/browser/tree/tree-expansion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ export class TreeExpansionServiceImpl implements TreeExpansionService {
}

protected async doExpandNode(node: ExpandableTreeNode): Promise<ExpandableTreeNode | undefined> {
node.expanded = true;
const refreshed = await this.tree.refresh(node);
if (ExpandableTreeNode.isExpanded(refreshed)) {
if (ExpandableTreeNode.is(refreshed)) {
refreshed.expanded = true;
this.fireExpansionChanged(refreshed);
return refreshed;
}
Expand Down

0 comments on commit cc9453d

Please sign in to comment.