Skip to content

Commit

Permalink
[ftr] migrate "savedObjectManagementComponent" service to FtrService …
Browse files Browse the repository at this point in the history
…class (#100614)

Co-authored-by: spalger <[email protected]>
  • Loading branch information
Spencer and spalger authored May 28, 2021
1 parent 9f5a61c commit fcaded7
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 178 deletions.
4 changes: 2 additions & 2 deletions test/functional/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
VegaDebugInspectorViewService,
} from './visualizations';
import { ListingTableService } from './listing_table';
import { SavedQueryManagementComponentProvider } from './saved_query_management_component';
import { SavedQueryManagementComponentService } from './saved_query_management_component';
import { KibanaSupertestProvider } from './supertest';
import { MenuToggleService } from './menu_toggle';
import { MonacoEditorProvider } from './monaco_editor';
Expand Down Expand Up @@ -80,7 +80,7 @@ export const services = {
appsMenu: AppsMenuService,
globalNav: GlobalNavService,
toasts: ToastsService,
savedQueryManagementComponent: SavedQueryManagementComponentProvider,
savedQueryManagementComponent: SavedQueryManagementComponentService,
elasticChart: ElasticChartService,
supertest: KibanaSupertestProvider,
managementMenu: ManagementMenuService,
Expand Down
347 changes: 171 additions & 176 deletions test/functional/services/saved_query_management_component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,210 +7,205 @@
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../ftr_provider_context';

export function SavedQueryManagementComponentProvider({
getService,
getPageObjects,
}: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const queryBar = getService('queryBar');
const retry = getService('retry');
const config = getService('config');
const PageObjects = getPageObjects(['common']);

class SavedQueryManagementComponent {
public async getCurrentlyLoadedQueryID() {
await this.openSavedQueryManagementComponent();
try {
return await testSubjects.getVisibleText('~saved-query-list-item-selected');
} catch {
return undefined;
}
}

public async saveNewQuery(
name: string,
description: string,
includeFilters: boolean,
includeTimeFilter: boolean
) {
await this.openSaveCurrentQueryModal();
await this.submitSaveQueryForm(name, description, includeFilters, includeTimeFilter);
import { FtrService } from '../ftr_provider_context';

export class SavedQueryManagementComponentService extends FtrService {
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly queryBar = this.ctx.getService('queryBar');
private readonly retry = this.ctx.getService('retry');
private readonly config = this.ctx.getService('config');
private readonly PageObjects = this.ctx.getPageObjects(['common']);

public async getCurrentlyLoadedQueryID() {
await this.openSavedQueryManagementComponent();
try {
return await this.testSubjects.getVisibleText('~saved-query-list-item-selected');
} catch {
return undefined;
}
}

public async saveNewQueryWithNameError(name?: string) {
await this.openSaveCurrentQueryModal();
if (name) {
await testSubjects.setValue('saveQueryFormTitle', name);
}

// Form input validation only happens onBlur. Clicking the save button should de-focus the
// input element and the validation should prevent a save from actually happening if there's
// an error.
await testSubjects.click('savedQueryFormSaveButton');

await retry.waitForWithTimeout('save button to be disabled', 1000, async () => {
const saveQueryFormSaveButtonStatus = await testSubjects.isEnabled(
'savedQueryFormSaveButton'
);
return saveQueryFormSaveButtonStatus === false;
});
public async saveNewQuery(
name: string,
description: string,
includeFilters: boolean,
includeTimeFilter: boolean
) {
await this.openSaveCurrentQueryModal();
await this.submitSaveQueryForm(name, description, includeFilters, includeTimeFilter);
}

await testSubjects.click('savedQueryFormCancelButton');
public async saveNewQueryWithNameError(name?: string) {
await this.openSaveCurrentQueryModal();
if (name) {
await this.testSubjects.setValue('saveQueryFormTitle', name);
}

public async saveCurrentlyLoadedAsNewQuery(
name: string,
description: string,
includeFilters: boolean,
includeTimeFilter: boolean
) {
await this.openSavedQueryManagementComponent();
await testSubjects.click('saved-query-management-save-as-new-button');
await this.submitSaveQueryForm(name, description, includeFilters, includeTimeFilter);
}
// Form input validation only happens onBlur. Clicking the save button should de-focus the
// input element and the validation should prevent a save from actually happening if there's
// an error.
await this.testSubjects.click('savedQueryFormSaveButton');

public async updateCurrentlyLoadedQuery(
description: string,
includeFilters: boolean,
includeTimeFilter: boolean
) {
await this.openSavedQueryManagementComponent();
await testSubjects.click('saved-query-management-save-changes-button');
await this.submitSaveQueryForm(null, description, includeFilters, includeTimeFilter);
}
await this.retry.waitForWithTimeout('save button to be disabled', 1000, async () => {
const saveQueryFormSaveButtonStatus = await this.testSubjects.isEnabled(
'savedQueryFormSaveButton'
);
return saveQueryFormSaveButtonStatus === false;
});

public async loadSavedQuery(title: string) {
await this.openSavedQueryManagementComponent();
await testSubjects.click(`~load-saved-query-${title}-button`);
await retry.try(async () => {
await this.openSavedQueryManagementComponent();
const selectedSavedQueryText = await testSubjects.getVisibleText(
'~saved-query-list-item-selected'
);
expect(selectedSavedQueryText).to.eql(title);
});
await this.closeSavedQueryManagementComponent();
}
await this.testSubjects.click('savedQueryFormCancelButton');
}

public async deleteSavedQuery(title: string) {
await this.openSavedQueryManagementComponent();
await testSubjects.click(`~delete-saved-query-${title}-button`);
await PageObjects.common.clickConfirmOnModal();
}
public async saveCurrentlyLoadedAsNewQuery(
name: string,
description: string,
includeFilters: boolean,
includeTimeFilter: boolean
) {
await this.openSavedQueryManagementComponent();
await this.testSubjects.click('saved-query-management-save-as-new-button');
await this.submitSaveQueryForm(name, description, includeFilters, includeTimeFilter);
}

async clearCurrentlyLoadedQuery() {
public async updateCurrentlyLoadedQuery(
description: string,
includeFilters: boolean,
includeTimeFilter: boolean
) {
await this.openSavedQueryManagementComponent();
await this.testSubjects.click('saved-query-management-save-changes-button');
await this.submitSaveQueryForm(null, description, includeFilters, includeTimeFilter);
}

public async loadSavedQuery(title: string) {
await this.openSavedQueryManagementComponent();
await this.testSubjects.click(`~load-saved-query-${title}-button`);
await this.retry.try(async () => {
await this.openSavedQueryManagementComponent();
await testSubjects.click('saved-query-management-clear-button');
await this.closeSavedQueryManagementComponent();
const queryString = await queryBar.getQueryString();
expect(queryString).to.be.empty();
}
const selectedSavedQueryText = await this.testSubjects.getVisibleText(
'~saved-query-list-item-selected'
);
expect(selectedSavedQueryText).to.eql(title);
});
await this.closeSavedQueryManagementComponent();
}

async submitSaveQueryForm(
title: string | null,
description: string,
includeFilters: boolean,
includeTimeFilter: boolean
) {
if (title) {
await testSubjects.setValue('saveQueryFormTitle', title);
}
await testSubjects.setValue('saveQueryFormDescription', description);

const currentIncludeFiltersValue =
(await testSubjects.getAttribute('saveQueryFormIncludeFiltersOption', 'aria-checked')) ===
'true';
if (currentIncludeFiltersValue !== includeFilters) {
await testSubjects.click('saveQueryFormIncludeFiltersOption');
}

const currentIncludeTimeFilterValue =
(await testSubjects.getAttribute(
'saveQueryFormIncludeTimeFilterOption',
'aria-checked'
)) === 'true';
if (currentIncludeTimeFilterValue !== includeTimeFilter) {
await testSubjects.click('saveQueryFormIncludeTimeFilterOption');
}

await testSubjects.click('savedQueryFormSaveButton');
}
public async deleteSavedQuery(title: string) {
await this.openSavedQueryManagementComponent();
await this.testSubjects.click(`~delete-saved-query-${title}-button`);
await this.PageObjects.common.clickConfirmOnModal();
}

async savedQueryExist(title: string) {
await this.openSavedQueryManagementComponent();
const exists = testSubjects.exists(`~load-saved-query-${title}-button`);
await this.closeSavedQueryManagementComponent();
return exists;
}
async clearCurrentlyLoadedQuery() {
await this.openSavedQueryManagementComponent();
await this.testSubjects.click('saved-query-management-clear-button');
await this.closeSavedQueryManagementComponent();
const queryString = await this.queryBar.getQueryString();
expect(queryString).to.be.empty();
}

async savedQueryExistOrFail(title: string) {
await this.openSavedQueryManagementComponent();
await testSubjects.existOrFail(`~load-saved-query-${title}-button`);
async submitSaveQueryForm(
title: string | null,
description: string,
includeFilters: boolean,
includeTimeFilter: boolean
) {
if (title) {
await this.testSubjects.setValue('saveQueryFormTitle', title);
}
await this.testSubjects.setValue('saveQueryFormDescription', description);

async savedQueryTextExist(text: string) {
await this.openSavedQueryManagementComponent();
const queryString = await queryBar.getQueryString();
expect(queryString).to.eql(text);
const currentIncludeFiltersValue =
(await this.testSubjects.getAttribute(
'saveQueryFormIncludeFiltersOption',
'aria-checked'
)) === 'true';
if (currentIncludeFiltersValue !== includeFilters) {
await this.testSubjects.click('saveQueryFormIncludeFiltersOption');
}

async savedQueryMissingOrFail(title: string) {
await retry.try(async () => {
await this.openSavedQueryManagementComponent();
await testSubjects.missingOrFail(`~load-saved-query-${title}-button`);
});
await this.closeSavedQueryManagementComponent();
const currentIncludeTimeFilterValue =
(await this.testSubjects.getAttribute(
'saveQueryFormIncludeTimeFilterOption',
'aria-checked'
)) === 'true';
if (currentIncludeTimeFilterValue !== includeTimeFilter) {
await this.testSubjects.click('saveQueryFormIncludeTimeFilterOption');
}

async openSavedQueryManagementComponent() {
const isOpenAlready = await testSubjects.exists('saved-query-management-popover');
if (isOpenAlready) return;
await this.testSubjects.click('savedQueryFormSaveButton');
}

await retry.waitFor('saved query management popover to have any text', async () => {
await testSubjects.click('saved-query-management-popover-button');
const queryText = await testSubjects.getVisibleText('saved-query-management-popover');
return queryText.length > 0;
});
}
async savedQueryExist(title: string) {
await this.openSavedQueryManagementComponent();
const exists = this.testSubjects.exists(`~load-saved-query-${title}-button`);
await this.closeSavedQueryManagementComponent();
return exists;
}

async closeSavedQueryManagementComponent() {
const isOpenAlready = await testSubjects.exists('saved-query-management-popover');
if (!isOpenAlready) return;
async savedQueryExistOrFail(title: string) {
await this.openSavedQueryManagementComponent();
await this.testSubjects.existOrFail(`~load-saved-query-${title}-button`);
}

await retry.try(async () => {
await testSubjects.click('saved-query-management-popover-button');
await testSubjects.missingOrFail('saved-query-management-popover');
});
}
async savedQueryTextExist(text: string) {
await this.openSavedQueryManagementComponent();
const queryString = await this.queryBar.getQueryString();
expect(queryString).to.eql(text);
}

async openSaveCurrentQueryModal() {
async savedQueryMissingOrFail(title: string) {
await this.retry.try(async () => {
await this.openSavedQueryManagementComponent();
await this.testSubjects.missingOrFail(`~load-saved-query-${title}-button`);
});
await this.closeSavedQueryManagementComponent();
}

await retry.try(async () => {
await testSubjects.click('saved-query-management-save-button');
await testSubjects.existOrFail('saveQueryForm', {
timeout: config.get('timeouts.waitForExists'),
});
});
}
async openSavedQueryManagementComponent() {
const isOpenAlready = await this.testSubjects.exists('saved-query-management-popover');
if (isOpenAlready) return;

async saveNewQueryMissingOrFail() {
await this.openSavedQueryManagementComponent();
await testSubjects.missingOrFail('saved-query-management-save-button');
}
await this.retry.waitFor('saved query management popover to have any text', async () => {
await this.testSubjects.click('saved-query-management-popover-button');
const queryText = await this.testSubjects.getVisibleText('saved-query-management-popover');
return queryText.length > 0;
});
}

async updateCurrentlyLoadedQueryMissingOrFail() {
await this.openSavedQueryManagementComponent();
await testSubjects.missingOrFail('saved-query-management-save-changes-button');
}
async closeSavedQueryManagementComponent() {
const isOpenAlready = await this.testSubjects.exists('saved-query-management-popover');
if (!isOpenAlready) return;

async deleteSavedQueryMissingOrFail(title: string) {
await this.openSavedQueryManagementComponent();
await testSubjects.missingOrFail(`delete-saved-query-${title}-button`);
}
await this.retry.try(async () => {
await this.testSubjects.click('saved-query-management-popover-button');
await this.testSubjects.missingOrFail('saved-query-management-popover');
});
}

async openSaveCurrentQueryModal() {
await this.openSavedQueryManagementComponent();

await this.retry.try(async () => {
await this.testSubjects.click('saved-query-management-save-button');
await this.testSubjects.existOrFail('saveQueryForm', {
timeout: this.config.get('timeouts.waitForExists'),
});
});
}

async saveNewQueryMissingOrFail() {
await this.openSavedQueryManagementComponent();
await this.testSubjects.missingOrFail('saved-query-management-save-button');
}

return new SavedQueryManagementComponent();
async updateCurrentlyLoadedQueryMissingOrFail() {
await this.openSavedQueryManagementComponent();
await this.testSubjects.missingOrFail('saved-query-management-save-changes-button');
}

async deleteSavedQueryMissingOrFail(title: string) {
await this.openSavedQueryManagementComponent();
await this.testSubjects.missingOrFail(`delete-saved-query-${title}-button`);
}
}

0 comments on commit fcaded7

Please sign in to comment.