search.ts 4.0 KB
Newer Older
S
Sandeep Somavarapu 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { SpectronApplication } from '../../spectron/application';
7
import { Viewlet } from '../workbench/viewlet';
S
Sandeep Somavarapu 已提交
8

I
isidor 已提交
9
const VIEWLET = 'div[id="workbench.view.search"] .search-view';
10
const INPUT = `${VIEWLET} .search-widget .search-container .monaco-inputbox input`;
11
const INCLUDE_INPUT = `${VIEWLET} .query-details .monaco-inputbox input[aria-label="Search Include/Exclude Patterns"]`;
S
Sandeep Somavarapu 已提交
12

13
export class Search extends Viewlet {
S
Sandeep Somavarapu 已提交
14

15 16
	constructor(spectron: SpectronApplication) {
		super(spectron);
S
Sandeep Somavarapu 已提交
17 18
	}

19 20 21
	async openSearchViewlet(): Promise<any> {
		await this.spectron.runCommand('workbench.view.search');
		await this.spectron.client.waitForActiveElement(INPUT);
S
Sandeep Somavarapu 已提交
22 23
	}

24
	async searchFor(text: string): Promise<void> {
J
Joao Moreno 已提交
25
		await this.spectron.client.waitAndClick(INPUT);
26 27
		await this.spectron.client.waitForActiveElement(INPUT);
		await this.spectron.client.setValue(INPUT, text);
S
Sandeep Somavarapu 已提交
28 29 30
		await this.submitSearch();
	}

31
	async submitSearch(): Promise<void> {
J
Joao Moreno 已提交
32
		await this.spectron.client.waitAndClick(INPUT);
33
		await this.spectron.client.waitForActiveElement(INPUT);
S
Sandeep Somavarapu 已提交
34

35
		await this.spectron.client.keys(['Enter', 'NULL']);
J
Joao Moreno 已提交
36
		await this.spectron.client.waitForElement(`${VIEWLET} .messages[aria-hidden="false"]`);
37
	}
S
Sandeep Somavarapu 已提交
38

39
	async setFilesToIncludeText(text: string): Promise<void> {
J
Joao Moreno 已提交
40
		await this.spectron.client.waitAndClick(INCLUDE_INPUT);
41 42
		await this.spectron.client.waitForActiveElement(INCLUDE_INPUT);
		await this.spectron.client.setValue(INCLUDE_INPUT, text || '');
S
Sandeep Somavarapu 已提交
43
	}
S
Sandeep Somavarapu 已提交
44

45
	async showQueryDetails(): Promise<void> {
S
Sandeep Somavarapu 已提交
46
		if (!await this.areDetailsVisible()) {
47
			await this.spectron.client.waitAndClick(`${VIEWLET} .query-details .more`);
S
Sandeep Somavarapu 已提交
48 49 50
		}
	}

51
	async hideQueryDetails(): Promise<void> {
S
Sandeep Somavarapu 已提交
52
		if (await this.areDetailsVisible()) {
53
			await this.spectron.client.waitAndClick(`${VIEWLET} .query-details.more .more`);
S
Sandeep Somavarapu 已提交
54 55 56
		}
	}

J
Joao Moreno 已提交
57 58
	areDetailsVisible(): Promise<boolean> {
		return this.spectron.client.doesElementExist(`${VIEWLET} .query-details.more`);
S
Sandeep Somavarapu 已提交
59 60
	}

61 62 63 64 65
	async removeFileMatch(index: number): Promise<void> {
		await this.spectron.client.waitAndMoveToObject(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch`);
		const file = await this.spectron.client.waitForText(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch a.label-name`);
		await this.spectron.client.waitAndClick(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch .action-label.icon.action-remove`);
		await this.spectron.client.waitForText(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch a.label-name`, void 0, result => result !== file);
S
Sandeep Somavarapu 已提交
66 67
	}

J
Joao Moreno 已提交
68
	async expandReplace(): Promise<void> {
69
		await this.spectron.client.waitAndClick(`${VIEWLET} .search-widget .monaco-button.toggle-replace-button.collapse`);
J
Joao Moreno 已提交
70 71 72
	}

	async setReplaceText(text: string): Promise<void> {
73
		await this.spectron.client.waitAndClick(`${VIEWLET} .search-widget .replace-container .monaco-inputbox input[title="Replace"]`);
J
Joao Moreno 已提交
74
		await this.spectron.client.waitForElement(`${VIEWLET} .search-widget .replace-container .monaco-inputbox.synthetic-focus input[title="Replace"]`);
75
		await this.spectron.client.setValue(`${VIEWLET} .search-widget .replace-container .monaco-inputbox.synthetic-focus input[title="Replace"]`, text);
S
Sandeep Somavarapu 已提交
76 77
	}

78 79
	async replaceFileMatch(index: number): Promise<void> {
		await this.spectron.client.waitAndMoveToObject(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch`);
J
Joao Moreno 已提交
80
		await this.spectron.client.waitAndClick(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch .action-label.icon.action-replace-all`);
S
Sandeep Somavarapu 已提交
81 82
	}

83 84
	async waitForResultText(text: string): Promise<void> {
		await this.spectron.client.waitForText(`${VIEWLET} .messages[aria-hidden="false"] .message>p`, text);
S
Sandeep Somavarapu 已提交
85
	}
I
isidor 已提交
86
}