Skip to content

Commit

Permalink
fix: cannot getActions for a view section when some button is disabled (
Browse files Browse the repository at this point in the history
  • Loading branch information
djelinek authored Jul 18, 2024
1 parent 4213331 commit 64a93e4
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class ViewPanelAction extends AbstractElement {
}

async wait(timeout: number = 1000): Promise<this> {
await this.getDriver().wait(until.elementIsEnabled(this), timeout);
await this.getDriver().wait(until.elementLocated(ViewSection.locators.ViewSection.actions), timeout);
return this;
}
}
18 changes: 18 additions & 0 deletions tests/test-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@
{
"command": "extension.treeItemAction",
"title": "Tree Item Action"
},
{
"command": "testView.refresh",
"title": "Refresh",
"icon": {
"light": "resources/icons/light/refresh.svg",
"dark": "resources/icons/dark/refresh.svg"
}
}
],
"viewsContainers": {
Expand All @@ -116,6 +124,10 @@
"id": "testView",
"name": "Test View"
},
{
"id": "testView2",
"name": "Test View 2"
},
{
"id": "emptyView",
"name": "Empty View"
Expand Down Expand Up @@ -186,6 +198,12 @@
"when": "viewItem =~ /ExtensionTreeItem/",
"group": "inline"
}
],
"view/title": [
{
"command": "testView.refresh",
"group": "navigation"
}
]
}
},
Expand Down
1 change: 1 addition & 0 deletions tests/test-project/resources/icons/dark/refresh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/test-project/resources/icons/light/refresh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions tests/test-project/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'path';
import * as vscode from 'vscode';
import { CatScratchEditorProvider } from './catScratchEditor';
import { CodelensProvider } from './codelensProvider';
import { TreeView } from './treeView';
import { TreeView, TreeView2 } from './treeView';

export const ERROR_MESSAGE_COMMAND = 'extension.errorMsg';

Expand Down Expand Up @@ -57,7 +57,14 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand(ERROR_MESSAGE_COMMAND, () => vscode.window.showErrorMessage('This is an error!')));
context.subscriptions.push(CatScratchEditorProvider.register(context));

new TreeView(context);
new TreeView(context, 'testView');
new TreeView2(context, 'testView2');

context.subscriptions.push(
vscode.commands.registerCommand('testView.refresh', async () => {
await vscode.window.showInformationMessage('Refresh View button clicked!');
}),
);

context.subscriptions.push(
vscode.window.createTreeView('emptyView', {
Expand Down
14 changes: 14 additions & 0 deletions tests/test-project/src/test/xsideBar/customView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {

describe('CustomTreeSection', () => {
let section: CustomTreeSection;
let emptySection: CustomTreeSection;
let emptyViewSection: CustomTreeSection;
let content: ViewContent;

Expand All @@ -44,6 +45,8 @@ describe('CustomTreeSection', () => {
});
content = view.getContent();
section = await content.getSection('Test View');
emptySection = await content.getSection('Test View 2');
await emptySection.expand();
emptyViewSection = await content.getSection('Empty View');
await emptyViewSection.expand();
});
Expand Down Expand Up @@ -104,11 +107,22 @@ describe('CustomTreeSection', () => {
expect(actions).not.empty;
});

it('getActions of EMPTY works', async () => {
const actions = await emptySection.getActions();
expect(actions).not.empty;
});

it('getAction works', async () => {
const action = await section.getAction('Collapse All');
expect(await action?.getLabel()).equals('Collapse All');
});

it('getAction of EMPTY works', async () => {
const action = await emptySection.getAction('Refresh');
expect(await action?.getLabel()).equals('Refresh');
await emptySection.collapse();
});

it('findWelcomeContent returns undefined if no WelcomeContent is present', async () => {
expect(await section.findWelcomeContent()).to.equal(undefined);
expect(await emptyViewSection.findWelcomeContent()).to.not.equal(undefined);
Expand Down
23 changes: 20 additions & 3 deletions tests/test-project/src/treeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,36 @@ import * as vscode from 'vscode';
import { ERROR_MESSAGE_COMMAND } from './extension';

/**
* Test tree view as shown in treeview sample extension available at
* Test tree view as shown in TreeView sample extension available at
* https://github.com/microsoft/vscode-extension-samples/tree/master/tree-view-sample
*/
export class TreeView {
constructor(context: vscode.ExtensionContext) {
const view = vscode.window.createTreeView('testView', {
constructor(context: vscode.ExtensionContext, viewID: string) {
const view = vscode.window.createTreeView(viewID, {
treeDataProvider: dataProvider(),
showCollapseAll: true,
});
context.subscriptions.push(view);
}
}

export class TreeView2 {
constructor(context: vscode.ExtensionContext, viewID: string) {
const view = vscode.window.createTreeView(viewID, {
treeDataProvider: {
getTreeItem: function (): vscode.TreeItem | Thenable<vscode.TreeItem> {
return {};
},
getChildren: function (): vscode.ProviderResult<unknown[]> {
return [];
},
},
showCollapseAll: true,
});
context.subscriptions.push(view);
}
}

type Tree = { [key: string]: Tree | undefined | null };

// structure of the test tree:
Expand Down

0 comments on commit 64a93e4

Please sign in to comment.