mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[ftr] migrate "toasts" service to FtrService class (#100613)
Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
parent
b189d05bc3
commit
dbd0ce761a
2 changed files with 62 additions and 66 deletions
|
@ -36,7 +36,7 @@ import { ManagementMenuService } from './management';
|
|||
import { QueryBarProvider } from './query_bar';
|
||||
import { RemoteProvider } from './remote';
|
||||
import { RenderableProvider } from './renderable';
|
||||
import { ToastsProvider } from './toasts';
|
||||
import { ToastsService } from './toasts';
|
||||
import { DataGridService } from './data_grid';
|
||||
import {
|
||||
PieChartService,
|
||||
|
@ -79,7 +79,7 @@ export const services = {
|
|||
vegaDebugInspector: VegaDebugInspectorViewService,
|
||||
appsMenu: AppsMenuProvider,
|
||||
globalNav: GlobalNavService,
|
||||
toasts: ToastsProvider,
|
||||
toasts: ToastsService,
|
||||
savedQueryManagementComponent: SavedQueryManagementComponentProvider,
|
||||
elasticChart: ElasticChartService,
|
||||
supertest: KibanaSupertestProvider,
|
||||
|
|
|
@ -6,78 +6,74 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { FtrProviderContext } from '../ftr_provider_context';
|
||||
import { FtrService } from '../ftr_provider_context';
|
||||
|
||||
export function ToastsProvider({ getService }: FtrProviderContext) {
|
||||
const testSubjects = getService('testSubjects');
|
||||
export class ToastsService extends FtrService {
|
||||
private readonly testSubjects = this.ctx.getService('testSubjects');
|
||||
|
||||
class Toasts {
|
||||
/**
|
||||
* Returns the title and message of a specific error toast.
|
||||
* This method is specific to toasts created via `.addError` since they contain
|
||||
* an additional button, that should not be part of the message.
|
||||
*
|
||||
* @param index The index of the toast (1-based, NOT 0-based!) of the toast. Use first by default.
|
||||
* @returns The title and message of the specified error toast.https://github.com/elastic/kibana/issues/17087
|
||||
*/
|
||||
public async getErrorToast(index: number = 1) {
|
||||
const toast = await this.getToastElement(index);
|
||||
const titleElement = await testSubjects.findDescendant('euiToastHeader', toast);
|
||||
const title: string = await titleElement.getVisibleText();
|
||||
const messageElement = await testSubjects.findDescendant('errorToastMessage', toast);
|
||||
const message: string = await messageElement.getVisibleText();
|
||||
return { title, message };
|
||||
}
|
||||
/**
|
||||
* Returns the title and message of a specific error toast.
|
||||
* This method is specific to toasts created via `.addError` since they contain
|
||||
* an additional button, that should not be part of the message.
|
||||
*
|
||||
* @param index The index of the toast (1-based, NOT 0-based!) of the toast. Use first by default.
|
||||
* @returns The title and message of the specified error toast.https://github.com/elastic/kibana/issues/17087
|
||||
*/
|
||||
public async getErrorToast(index: number = 1) {
|
||||
const toast = await this.getToastElement(index);
|
||||
const titleElement = await this.testSubjects.findDescendant('euiToastHeader', toast);
|
||||
const title: string = await titleElement.getVisibleText();
|
||||
const messageElement = await this.testSubjects.findDescendant('errorToastMessage', toast);
|
||||
const message: string = await messageElement.getVisibleText();
|
||||
return { title, message };
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismiss a specific toast from the toast list. Since toasts usually should time out themselves,
|
||||
* you only need to call this for permanent toasts (e.g. error toasts).
|
||||
*
|
||||
* @param index The 1-based index of the toast to dismiss. Use first by default.
|
||||
*/
|
||||
public async dismissToast(index: number = 1) {
|
||||
const toast = await this.getToastElement(index);
|
||||
/**
|
||||
* Dismiss a specific toast from the toast list. Since toasts usually should time out themselves,
|
||||
* you only need to call this for permanent toasts (e.g. error toasts).
|
||||
*
|
||||
* @param index The 1-based index of the toast to dismiss. Use first by default.
|
||||
*/
|
||||
public async dismissToast(index: number = 1) {
|
||||
const toast = await this.getToastElement(index);
|
||||
await toast.moveMouseTo();
|
||||
const dismissButton = await this.testSubjects.findDescendant('toastCloseButton', toast);
|
||||
await dismissButton.click();
|
||||
}
|
||||
|
||||
public async dismissAllToasts() {
|
||||
const list = await this.getGlobalToastList();
|
||||
const toasts = await list.findAllByCssSelector(`.euiToast`);
|
||||
|
||||
if (toasts.length === 0) return;
|
||||
|
||||
for (const toast of toasts) {
|
||||
await toast.moveMouseTo();
|
||||
const dismissButton = await testSubjects.findDescendant('toastCloseButton', toast);
|
||||
await dismissButton.click();
|
||||
}
|
||||
|
||||
public async dismissAllToasts() {
|
||||
const list = await this.getGlobalToastList();
|
||||
const toasts = await list.findAllByCssSelector(`.euiToast`);
|
||||
|
||||
if (toasts.length === 0) return;
|
||||
|
||||
for (const toast of toasts) {
|
||||
await toast.moveMouseTo();
|
||||
|
||||
if (await testSubjects.descendantExists('toastCloseButton', toast)) {
|
||||
try {
|
||||
const dismissButton = await testSubjects.findDescendant('toastCloseButton', toast);
|
||||
await dismissButton.click();
|
||||
} catch (err) {
|
||||
// ignore errors
|
||||
// toasts are finnicky because they can dismiss themselves right before you close them
|
||||
}
|
||||
if (await this.testSubjects.descendantExists('toastCloseButton', toast)) {
|
||||
try {
|
||||
const dismissButton = await this.testSubjects.findDescendant('toastCloseButton', toast);
|
||||
await dismissButton.click();
|
||||
} catch (err) {
|
||||
// ignore errors
|
||||
// toasts are finnicky because they can dismiss themselves right before you close them
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async getToastElement(index: number) {
|
||||
const list = await this.getGlobalToastList();
|
||||
return await list.findByCssSelector(`.euiToast:nth-child(${index})`);
|
||||
}
|
||||
|
||||
private async getGlobalToastList() {
|
||||
return await testSubjects.find('globalToastList');
|
||||
}
|
||||
|
||||
public async getToastCount() {
|
||||
const list = await this.getGlobalToastList();
|
||||
const toasts = await list.findAllByCssSelector(`.euiToast`);
|
||||
return toasts.length;
|
||||
}
|
||||
}
|
||||
|
||||
return new Toasts();
|
||||
public async getToastElement(index: number) {
|
||||
const list = await this.getGlobalToastList();
|
||||
return await list.findByCssSelector(`.euiToast:nth-child(${index})`);
|
||||
}
|
||||
|
||||
private async getGlobalToastList() {
|
||||
return await this.testSubjects.find('globalToastList');
|
||||
}
|
||||
|
||||
public async getToastCount() {
|
||||
const list = await this.getGlobalToastList();
|
||||
const toasts = await list.findAllByCssSelector(`.euiToast`);
|
||||
return toasts.length;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue