Skip to content

Commit 7fb686d

Browse files
testing: adding tests count badge for the testing explorer (microsoft#182399)
* feat: adding count badge for the testing explorer Signed-off-by: Fawzi Abdulfattah <iifawzie@gmail.com> * register the change listener Signed-off-by: Fawzi Abdulfattah <iifawzie@gmail.com> * adding badgeTooltip to handle all tests case Signed-off-by: Fawzi Abdulfattah <iifawzie@gmail.com> * Update src/vs/workbench/contrib/testing/common/configuration.ts Co-authored-by: John Murray <johnm@georgejames.com> * get the config value by the enum key Signed-off-by: Fawzi Abdulfattah <iifawzie@gmail.com> * Adding getLocalizedBadgeString method Signed-off-by: Fawzi Abdulfattah <iifawzie@gmail.com> * removing the all option Signed-off-by: Fawzi Abdulfattah <iifawzie@gmail.com> * changing the type of countSummary and add a guard check Signed-off-by: Fawzi Abdulfattah <iifawzie@gmail.com> --------- Signed-off-by: Fawzi Abdulfattah <iifawzie@gmail.com> Co-authored-by: John Murray <johnm@georgejames.com>
1 parent 4f9aef9 commit 7fb686d

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

src/vs/workbench/contrib/testing/browser/testingExplorerView.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ import { TestingObjectTree } from 'vs/workbench/contrib/testing/browser/explorer
5454
import { ISerializedTestTreeCollapseState } from 'vs/workbench/contrib/testing/browser/explorerProjections/testingViewState';
5555
import * as icons from 'vs/workbench/contrib/testing/browser/icons';
5656
import { TestingExplorerFilter } from 'vs/workbench/contrib/testing/browser/testingExplorerFilter';
57-
import { ITestingProgressUiService } from 'vs/workbench/contrib/testing/browser/testingProgressUiService';
58-
import { TestingConfigKeys, getTestingConfiguration } from 'vs/workbench/contrib/testing/common/configuration';
57+
import { CountSummary, ITestingProgressUiService } from 'vs/workbench/contrib/testing/browser/testingProgressUiService';
58+
import { TestingConfigKeys, TestingCountBadge, getTestingConfiguration } from 'vs/workbench/contrib/testing/common/configuration';
5959
import { TestCommandId, TestExplorerViewMode, TestExplorerViewSorting, Testing, labelForTestInState } from 'vs/workbench/contrib/testing/common/constants';
6060
import { StoredValue } from 'vs/workbench/contrib/testing/common/storedValue';
6161
import { ITestExplorerFilterState, TestExplorerFilterState, TestFilterTerm } from 'vs/workbench/contrib/testing/common/testExplorerFilterState';
@@ -70,6 +70,7 @@ import { ITestingPeekOpener } from 'vs/workbench/contrib/testing/common/testingP
7070
import { cmpPriority, isFailedState, isStateWithResult } from 'vs/workbench/contrib/testing/common/testingStates';
7171
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
7272
import { ITestingContinuousRunService } from 'vs/workbench/contrib/testing/common/testingContinuousRunService';
73+
import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity';
7374

7475
const enum LastFocusState {
7576
Input,
@@ -81,8 +82,10 @@ export class TestingExplorerView extends ViewPane {
8182
private filterActionBar = this._register(new MutableDisposable());
8283
private container!: HTMLElement;
8384
private treeHeader!: HTMLElement;
85+
private countSummary: CountSummary | undefined;
8486
private discoveryProgress = this._register(new MutableDisposable<UnmanagedProgress>());
8587
private readonly filter = this._register(new MutableDisposable<TestingExplorerFilter>());
88+
private readonly badgeDisposable = this._register(new MutableDisposable<IDisposable>());
8689
private readonly filterFocusListener = this._register(new MutableDisposable());
8790
private readonly dimensions = { width: 0, height: 0 };
8891
private lastFocusState = LastFocusState.Input;
@@ -93,6 +96,7 @@ export class TestingExplorerView extends ViewPane {
9396

9497
constructor(
9598
options: IViewletViewOptions,
99+
@IActivityService private readonly activityService: IActivityService,
96100
@IContextMenuService contextMenuService: IContextMenuService,
97101
@IKeybindingService keybindingService: IKeybindingService,
98102
@IConfigurationService configurationService: IConfigurationService,
@@ -121,6 +125,8 @@ export class TestingExplorerView extends ViewPane {
121125
}));
122126

123127
this._register(testProfileService.onDidChange(() => this.updateActions()));
128+
const onDidChangeTestingCountBadge = Event.filter(configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('testing.countBadge'));
129+
this._register(onDidChangeTestingCountBadge(this.renderActivityCount, this));
124130
}
125131

126132
public override shouldShowWelcome() {
@@ -269,6 +275,10 @@ export class TestingExplorerView extends ViewPane {
269275
this.layoutBody();
270276
}
271277
}));
278+
this._register(this.testProgressService.onCountChange((text: CountSummary) => {
279+
this.countSummary = text;
280+
this.renderActivityCount();
281+
}));
272282

273283
const listContainer = dom.append(this.container, dom.$('.test-explorer-tree'));
274284
this.viewModel = this.instantiationService.createInstance(TestingExplorerViewModel, listContainer, this.onDidChangeBodyVisibility);
@@ -417,6 +427,27 @@ export class TestingExplorerView extends ViewPane {
417427
}
418428
}
419429

430+
private renderActivityCount() {
431+
const countBadgeType = this.configurationService.getValue<TestingCountBadge>(TestingConfigKeys.CountBadge);
432+
if (!this.countSummary || countBadgeType === TestingCountBadge.Off || this.countSummary[countBadgeType] === 0) {
433+
this.badgeDisposable.value = undefined;
434+
} else {
435+
const badge = new NumberBadge(this.countSummary[countBadgeType], num => this.getLocalizedBadgeString(countBadgeType, num));
436+
this.badgeDisposable.value = this.activityService.showViewActivity(Testing.ExplorerViewId, { badge });
437+
}
438+
}
439+
440+
private getLocalizedBadgeString(countBadgeType: TestingCountBadge, count: number): string {
441+
switch (countBadgeType) {
442+
case TestingCountBadge.Passed:
443+
return localize('testingCountBadgePassed', '{0} passed tests', count);
444+
case TestingCountBadge.Skipped:
445+
return localize('testingCountBadgeSkipped', '{0} skipped tests', count);
446+
default:
447+
return localize('testingCountBadgeFailed', '{0} failed tests', count);
448+
}
449+
}
450+
420451
/**
421452
* @override
422453
*/

src/vs/workbench/contrib/testing/browser/testingProgressUiService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class TestingProgressUiService extends Disposable implements ITestingProg
100100

101101
constructor(
102102
@ITestResultService private readonly resultService: ITestResultService,
103-
@IInstantiationService private readonly instantiaionService: IInstantiationService,
103+
@IInstantiationService private readonly instantiationService: IInstantiationService,
104104
) {
105105
super();
106106
}
@@ -126,11 +126,11 @@ export class TestingProgressUiService extends Disposable implements ITestingProg
126126
}
127127

128128
if (!this.windowProg.value) {
129-
this.windowProg.value = this.instantiaionService.createInstance(UnmanagedProgress, {
129+
this.windowProg.value = this.instantiationService.createInstance(UnmanagedProgress, {
130130
location: ProgressLocation.Window,
131131
type: 'loading'
132132
});
133-
this.testViewProg.value = this.instantiaionService.createInstance(UnmanagedProgress, {
133+
this.testViewProg.value = this.instantiationService.createInstance(UnmanagedProgress, {
134134
location: Testing.ViewletId,
135135
total: 1000,
136136
});
@@ -148,7 +148,7 @@ export class TestingProgressUiService extends Disposable implements ITestingProg
148148
}
149149
}
150150

151-
type CountSummary = ReturnType<typeof collectTestStateCounts>;
151+
export type CountSummary = ReturnType<typeof collectTestStateCounts>;
152152

153153

154154
const collectTestStateCounts = (isRunning: boolean, ...counts: ReadonlyArray<TestStateCount>) => {

src/vs/workbench/contrib/testing/common/configuration.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export const enum TestingConfigKeys {
1616
DefaultGutterClickAction = 'testing.defaultGutterClickAction',
1717
GutterEnabled = 'testing.gutterEnabled',
1818
SaveBeforeTest = 'testing.saveBeforeTest',
19-
AlwaysRevealTestOnStateChange = 'testing.alwaysRevealTestOnStateChange'
19+
AlwaysRevealTestOnStateChange = 'testing.alwaysRevealTestOnStateChange',
20+
CountBadge = 'testing.countBadge'
2021
}
2122

2223
export const enum AutoOpenTesting {
@@ -37,6 +38,13 @@ export const enum DefaultGutterClickAction {
3738
ContextMenu = 'contextMenu',
3839
}
3940

41+
export const enum TestingCountBadge {
42+
Failed = 'failed',
43+
Off = 'off',
44+
Passed = 'passed',
45+
Skipped = 'skipped',
46+
}
47+
4048
export const testingConfiguration: IConfigurationNode = {
4149
id: 'testing',
4250
order: 21,
@@ -68,6 +76,22 @@ export const testingConfiguration: IConfigurationNode = {
6876
type: 'boolean',
6977
default: false,
7078
},
79+
[TestingConfigKeys.CountBadge]: {
80+
description: localize('testing.countBadge', 'Controls the count badge on the Testing icon on the Activity Bar.'),
81+
enum: [
82+
TestingCountBadge.Failed,
83+
TestingCountBadge.Off,
84+
TestingCountBadge.Passed,
85+
TestingCountBadge.Skipped,
86+
],
87+
enumDescriptions: [
88+
localize('testing.countBadge.failed', 'Show the number of failed tests'),
89+
localize('testing.countBadge.off', 'Disable the testing count badge'),
90+
localize('testing.countBadge.passed', 'Show the number of passed tests'),
91+
localize('testing.countBadge.skipped', 'Show the number of skipped tests'),
92+
],
93+
default: TestingCountBadge.Failed,
94+
},
7195
[TestingConfigKeys.FollowRunningTest]: {
7296
description: localize('testing.followRunningTest', 'Controls whether the running test should be followed in the Test Explorer view.'),
7397
type: 'boolean',
@@ -123,6 +147,7 @@ export interface ITestingConfiguration {
123147
[TestingConfigKeys.AutoRunDelay]: number;
124148
[TestingConfigKeys.AutoOpenPeekView]: AutoOpenPeekViewWhen;
125149
[TestingConfigKeys.AutoOpenPeekViewDuringContinuousRun]: boolean;
150+
[TestingConfigKeys.CountBadge]: TestingCountBadge;
126151
[TestingConfigKeys.FollowRunningTest]: boolean;
127152
[TestingConfigKeys.DefaultGutterClickAction]: DefaultGutterClickAction;
128153
[TestingConfigKeys.GutterEnabled]: boolean;

0 commit comments

Comments
 (0)