Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/test/view/treeNodes/repositoryChangesNode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { default as assert } from 'assert';
import * as vscode from 'vscode';
import { BaseTreeNode, TreeNode } from '../../../view/treeNodes/treeNode';
import { RepositoryChangesNode } from '../../../view/treeNodes/repositoryChangesNode';

function disposable(): vscode.Disposable {
return { dispose: () => { } };
}

describe('RepositoryChangesNode', function () {
// Verifies that VS Code can resolve the visible category nodes through their rendered parent chain.
it('parents the category nodes to the repository changes node', async function () {
const parent: BaseTreeNode = {
reveal: async () => { },
refresh: () => { },
children: undefined,
view: {
visible: true,
onDidChangeVisibility: () => disposable(),
} as unknown as vscode.TreeView<TreeNode>,
};
const pullRequestModel = {
title: 'Pull request title',
number: 1,
author: { avatarUrl: '' },
remote: { owner: 'owner', repositoryName: 'repository' },
item: { isRemoteHeadDeleted: false },
hasChangesSinceLastReview: false,
showChangesSinceReview: false,
onDidChange: () => disposable(),
onDidChangeReviewThreads: () => disposable(),
onDidChangeFileViewedState: () => disposable(),
equals: () => true,
};
const folderRepositoryManager = {
repository: {},
context: {},
activePullRequest: pullRequestModel,
isPullRequestAssociatedWithOpenRepository: () => true,
};
const reviewModel = {
onDidChangeLocalFileChanges: () => disposable(),
};
const node = new RepositoryChangesNode(
parent,
pullRequestModel as any,
folderRepositoryManager as any,
reviewModel as any,
{ progress: Promise.resolve() } as any,
);
let children: TreeNode[] = [];

try {
children = await node.getChildren();
const [filesNode, commitsNode] = children;
assert.strictEqual(filesNode.getParent(), node);
assert.strictEqual(commitsNode.getParent(), node);
} finally {
children.forEach(child => child.dispose());
node.dispose();
}
});
});
4 changes: 2 additions & 2 deletions src/view/treeNodes/repositoryChangesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ export class RepositoryChangesNode extends TreeNode implements vscode.TreeItem {
await this._progress.progress;
if (!this._filesCategoryNode || !this._commitsCategoryNode) {
Logger.appendLine(`Creating file and commit nodes for PR #${this.pullRequestModel.number}`, PR_TREE);
this._filesCategoryNode = new FilesCategoryNode(this.parent, this._reviewModel, this.pullRequestModel);
this._filesCategoryNode = new FilesCategoryNode(this, this._reviewModel, this.pullRequestModel);
this._commitsCategoryNode = new CommitsNode(
this.parent,
this,
this._pullRequestManager,
this.pullRequestModel,
);
Expand Down