Skip to content

Commit d7401c4

Browse files
andreamahfiliptronicek
authored andcommitted
improve search smoke test (microsoft#161652)
* improve search smoke test * prevent text to show when clearing results
1 parent 87ce8a4 commit d7401c4

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

src/vs/workbench/contrib/search/browser/searchView.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ export class SearchView extends ViewPane {
532532

533533
private refreshAndUpdateCount(event?: IChangeEvent): void {
534534
this.searchWidget.setReplaceAllActionState(!this.viewModel.searchResult.isEmpty());
535-
this.updateSearchResultCount(this.viewModel.searchResult.query!.userDisabledExcludesAndIgnoreFiles, this.viewModel.searchResult.query?.onlyOpenEditors);
535+
this.updateSearchResultCount(this.viewModel.searchResult.query!.userDisabledExcludesAndIgnoreFiles, this.viewModel.searchResult.query?.onlyOpenEditors, event?.clearingAll);
536536
return this.refreshTree(event);
537537
}
538538

@@ -1655,14 +1655,14 @@ export class SearchView extends ViewPane {
16551655
this.inputPatternIncludes.setOnlySearchInOpenEditors(false);
16561656
}
16571657

1658-
private updateSearchResultCount(disregardExcludesAndIgnores?: boolean, onlyOpenEditors?: boolean): void {
1658+
private updateSearchResultCount(disregardExcludesAndIgnores?: boolean, onlyOpenEditors?: boolean, clear: boolean = false): void {
16591659
const fileCount = this.viewModel.searchResult.fileCount();
16601660
this.hasSearchResultsKey.set(fileCount > 0);
16611661

16621662
const msgWasHidden = this.messagesElement.style.display === 'none';
16631663

16641664
const messageEl = this.clearMessage();
1665-
const resultMsg = this.buildResultCountMessage(this.viewModel.searchResult.count(), fileCount);
1665+
const resultMsg = clear ? '' : this.buildResultCountMessage(this.viewModel.searchResult.count(), fileCount);
16661666
this.tree.ariaLabel = resultMsg + nls.localize('forTerm', " - Search: {0}", this.searchResult.query?.contentPattern.pattern ?? '');
16671667
dom.append(messageEl, resultMsg);
16681668

src/vs/workbench/contrib/search/common/searchModel.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ export interface IChangeEvent {
476476
elements: FileMatch[];
477477
added?: boolean;
478478
removed?: boolean;
479+
clearingAll?: boolean;
479480
}
480481

481482
export class FolderMatch extends Disposable {
@@ -578,10 +579,10 @@ export class FolderMatch extends Disposable {
578579
folderMatch.onDispose(() => disposable.dispose());
579580
}
580581

581-
clear(): void {
582+
clear(clearingAll = false): void {
582583
const changed: FileMatch[] = this.downstreamFileMatches();
583584
this.disposeMatches();
584-
this._onChange.fire({ elements: changed, removed: true, added: false });
585+
this._onChange.fire({ elements: changed, removed: true, added: false, clearingAll });
585586
}
586587

587588
remove(matches: FileMatch | FolderMatchWithResource | (FileMatch | FolderMatchWithResource)[]): void {
@@ -1191,7 +1192,7 @@ export class SearchResult extends Disposable {
11911192
}
11921193

11931194
clear(): void {
1194-
this.folderMatches().forEach((folderMatch) => folderMatch.clear());
1195+
this.folderMatches().forEach((folderMatch) => folderMatch.clear(true));
11951196
this.disposeMatches();
11961197
this._folderMatches = [];
11971198
this._otherFilesMatch = null;

src/vs/workbench/contrib/search/test/common/searchResult.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ suite('SearchResult', () => {
449449
testObject.onChange(target);
450450
testObject.remove(folderMatch);
451451
assert.ok(target.calledOnce);
452-
assert.deepStrictEqual([{ elements: expectedArrayResult, removed: true, added: false }], target.args[0]);
452+
assert.deepStrictEqual([{ elements: expectedArrayResult, removed: true, added: false, clearingAll: false }], target.args[0]);
453453
});
454454

455455
test('Replacing an intermediate folder should remove all downstream folders and file matches', async function () {

test/smoke/src/areas/search/search.test.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ export function setup(logger: Logger) {
2929

3030
it('searches only for *.js files & checks for correct result number', async function () {
3131
const app = this.app as Application;
32-
await app.workbench.search.searchFor('body');
33-
await app.workbench.search.showQueryDetails();
34-
await app.workbench.search.setFilesToIncludeText('*.js');
35-
await app.workbench.search.submitSearch();
36-
37-
await app.workbench.search.waitForResultText('4 results in 1 file');
38-
await app.workbench.search.setFilesToIncludeText('');
39-
await app.workbench.search.hideQueryDetails();
32+
try {
33+
await app.workbench.search.setFilesToIncludeText('*.js');
34+
await app.workbench.search.searchFor('body');
35+
await app.workbench.search.showQueryDetails();
36+
37+
await app.workbench.search.waitForResultText('4 results in 1 file');
38+
} finally {
39+
await app.workbench.search.setFilesToIncludeText('');
40+
await app.workbench.search.hideQueryDetails();
41+
}
4042
});
4143

4244
it('dismisses result & checks for correct result number', async function () {

0 commit comments

Comments
 (0)