/*--------------------------------------------------------------------------------------------- * 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'; import { Viewlet } from '../workbench/viewlet'; const VIEWLET = 'div[id="workbench.view.search"] .search-view'; const INPUT = `${VIEWLET} .search-widget .search-container .monaco-inputbox input`; const INCLUDE_INPUT = `${VIEWLET} .query-details .monaco-inputbox input[aria-label="Search Include/Exclude Patterns"]`; export class Search extends Viewlet { constructor(spectron: SpectronApplication) { super(spectron); } async openSearchViewlet(): Promise { await this.spectron.runCommand('workbench.view.search'); await this.spectron.client.waitForActiveElement(INPUT); } async searchFor(text: string): Promise { await this.spectron.client.waitAndClick(INPUT); await this.spectron.client.waitForActiveElement(INPUT); await this.spectron.client.setValue(INPUT, text); await this.submitSearch(); } async submitSearch(): Promise { await this.spectron.client.waitAndClick(INPUT); await this.spectron.client.waitForActiveElement(INPUT); await this.spectron.client.keys(['Enter', 'NULL']); await this.spectron.client.waitForElement(`${VIEWLET} .messages[aria-hidden="false"]`); } async setFilesToIncludeText(text: string): Promise { await this.spectron.client.waitAndClick(INCLUDE_INPUT); await this.spectron.client.waitForActiveElement(INCLUDE_INPUT); await this.spectron.client.setValue(INCLUDE_INPUT, text || ''); } async showQueryDetails(): Promise { if (!await this.areDetailsVisible()) { await this.spectron.client.waitAndClick(`${VIEWLET} .query-details .more`); } } async hideQueryDetails(): Promise { if (await this.areDetailsVisible()) { await this.spectron.client.waitAndClick(`${VIEWLET} .query-details.more .more`); } } areDetailsVisible(): Promise { return this.spectron.client.doesElementExist(`${VIEWLET} .query-details.more`); } async removeFileMatch(index: number): Promise { 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); } async expandReplace(): Promise { await this.spectron.client.waitAndClick(`${VIEWLET} .search-widget .monaco-button.toggle-replace-button.collapse`); } async setReplaceText(text: string): Promise { await this.spectron.client.waitAndClick(`${VIEWLET} .search-widget .replace-container .monaco-inputbox input[title="Replace"]`); await this.spectron.client.waitForElement(`${VIEWLET} .search-widget .replace-container .monaco-inputbox.synthetic-focus input[title="Replace"]`); await this.spectron.client.setValue(`${VIEWLET} .search-widget .replace-container .monaco-inputbox.synthetic-focus input[title="Replace"]`, text); } async replaceFileMatch(index: number): Promise { await this.spectron.client.waitAndMoveToObject(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch`); await this.spectron.client.waitAndClick(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch .action-label.icon.action-replace-all`); } async waitForResultText(text: string): Promise { await this.spectron.client.waitForText(`${VIEWLET} .messages[aria-hidden="false"] .message>p`, text); } }