Skip to content

Commit

Permalink
testing: standardize inline vs context menu command visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Feb 22, 2022
1 parent 9861f7a commit 872e671
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
39 changes: 20 additions & 19 deletions src/vs/workbench/contrib/testing/browser/testExplorerActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { localize } from 'vs/nls';
import { Action2, IAction2Options, MenuId } from 'vs/platform/actions/common/actions';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { ContextKeyExpr, ContextKeyGreaterExpr } from 'vs/platform/contextkey/common/contextkey';
import { ContextKeyExpr, ContextKeyExpression, ContextKeyGreaterExpr } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { INotificationService } from 'vs/platform/notification/common/notification';
Expand Down Expand Up @@ -72,6 +72,7 @@ export class HideTestAction extends Action2 {
title: localize('hideTest', 'Hide Test'),
menu: {
id: MenuId.TestItem,
group: 'builtin@2',
when: TestingContextKeys.testItemIsHidden.isEqualTo(false)
},
});
Expand Down Expand Up @@ -113,19 +114,28 @@ export class UnhideTestAction extends Action2 {
}
}

const testItemInlineAndInContext = (order: ActionOrder, when?: ContextKeyExpression) => [
{
id: MenuId.TestItem,
group: 'inline',
order,
when,
}, {
id: MenuId.TestItem,
group: 'builtin@1',
order,
when,
}
];

export class DebugAction extends Action2 {
public static readonly ID = 'testing.debug';
constructor() {
super({
id: DebugAction.ID,
title: localize('debug test', 'Debug Test'),
icon: icons.testingDebugIcon,
menu: {
id: MenuId.TestItem,
group: 'inline',
order: ActionOrder.Debug,
when: TestingContextKeys.hasDebuggableTests.isEqualTo(true),
},
menu: testItemInlineAndInContext(ActionOrder.Debug, TestingContextKeys.hasDebuggableTests.isEqualTo(true)),
});
}

Expand All @@ -147,6 +157,7 @@ export class RunUsingProfileAction extends Action2 {
menu: {
id: MenuId.TestItem,
order: ActionOrder.RunUsing,
group: 'builtin@2',
when: TestingContextKeys.hasNonDefaultProfile.isEqualTo(true),
},
});
Expand Down Expand Up @@ -185,12 +196,7 @@ export class RunAction extends Action2 {
id: RunAction.ID,
title: localize('run test', 'Run Test'),
icon: icons.testingRunIcon,
menu: {
id: MenuId.TestItem,
group: 'inline',
order: ActionOrder.Run,
when: TestingContextKeys.hasRunnableTests.isEqualTo(true),
},
menu: testItemInlineAndInContext(ActionOrder.Run, TestingContextKeys.hasRunnableTests.isEqualTo(true)),
});
}

Expand Down Expand Up @@ -649,12 +655,7 @@ export class GoToTest extends Action2 {
id: GoToTest.ID,
title: localize('testing.editFocusedTest', "Go to Test"),
icon: Codicon.goToFile,
menu: {
id: MenuId.TestItem,
when: TestingContextKeys.testItemHasUri.isEqualTo(true),
order: ActionOrder.GoToTest,
group: 'inline',
},
menu: testItemInlineAndInContext(ActionOrder.GoToTest, TestingContextKeys.testItemHasUri.isEqualTo(true)),
keybinding: {
weight: KeybindingWeight.EditorContrib - 10,
when: FocusedViewContext.isEqualTo(Testing.ExplorerViewId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,7 @@ export class TestingExplorerViewModel extends Disposable {
const actions = getActionableElementActions(this.contextKeyService, this.menuService, this.testService, this.testProfileService, element);
this.contextMenuService.showContextMenu({
getAnchor: () => evt.anchor,
getActions: () => [
...actions.value.primary,
new Separator(),
...actions.value.secondary,
],
getActions: () => actions.value.secondary,
getActionsContext: () => element,
onHide: () => actions.dispose(),
actionRunner: this.actionRunner,
Expand Down

0 comments on commit 872e671

Please sign in to comment.