From ed4ef0862dd9e185cd732b5550ff2e69d681463b Mon Sep 17 00:00:00 2001 From: Steven Vachon Date: Tue, 15 Sep 2020 15:10:56 -0400 Subject: [PATCH] @grafana/e2e: annotation improvements (#27582) * Removed Datadog-specific fields from config for annotation creation * Added a custom form config option for annotation creation * Added regex support to `selectOption` --- .../grafana-e2e/src/flows/addDashboard.ts | 21 ++++--------------- .../grafana-e2e/src/flows/selectOption.ts | 12 +++++++++-- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/packages/grafana-e2e/src/flows/addDashboard.ts b/packages/grafana-e2e/src/flows/addDashboard.ts index f0c3093259e..aa2c1edcaf1 100644 --- a/packages/grafana-e2e/src/flows/addDashboard.ts +++ b/packages/grafana-e2e/src/flows/addDashboard.ts @@ -6,9 +6,8 @@ import { v4 as uuidv4 } from 'uuid'; export interface AddAnnotationConfig { dataSource: string; + dataSourceForm?: () => void; name: string; - sources?: string; - tags?: string; } export interface AddDashboardConfig { @@ -111,7 +110,7 @@ const addAnnotation = (config: AddAnnotationConfig, isFirst: boolean) => { .click(); } - const { dataSource, name, sources, tags } = config; + const { dataSource, dataSourceForm, name } = config; // @todo add to e2e-selectors and `aria-label` e2e() @@ -125,20 +124,8 @@ const addAnnotation = (config: AddAnnotationConfig, isFirst: boolean) => { .find('input') .type(name); - if (sources) { - // @todo add to e2e-selectors and `aria-label` - e2e() - .contains('.gf-form', 'Sources') - .find('input') - .type(sources); - } - - if (tags) { - // @todo add to e2e-selectors and `aria-label` - e2e() - .contains('.gf-form', 'Tags') - .find('input') - .type(tags); + if (dataSourceForm) { + dataSourceForm(); } // @todo add to e2e-selectors and `aria-label` diff --git a/packages/grafana-e2e/src/flows/selectOption.ts b/packages/grafana-e2e/src/flows/selectOption.ts index 6db8ea84929..9949915d68c 100644 --- a/packages/grafana-e2e/src/flows/selectOption.ts +++ b/packages/grafana-e2e/src/flows/selectOption.ts @@ -1,7 +1,7 @@ import { e2e } from '../index'; // @todo this actually returns type `Cypress.Chainable` -export const selectOption = (select: any, optionText: string, clickToOpen = true): any => +export const selectOption = (select: any, optionText: string | RegExp, clickToOpen = true): any => select.within(() => { if (clickToOpen) { e2e() @@ -10,7 +10,15 @@ export const selectOption = (select: any, optionText: string, clickToOpen = true } e2e.components.Select.option() - .filter(`:contains("${optionText}")`) + .filter((_, { textContent }) => { + if (textContent === null) { + return false; + } else if (typeof optionText === 'string') { + return textContent.includes(optionText); + } else { + return optionText.test(textContent); + } + }) .scrollIntoView() .click(); e2e()