Commit ed4ef086 by Steven Vachon Committed by GitHub

@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`
parent 54b677bd
...@@ -6,9 +6,8 @@ import { v4 as uuidv4 } from 'uuid'; ...@@ -6,9 +6,8 @@ import { v4 as uuidv4 } from 'uuid';
export interface AddAnnotationConfig { export interface AddAnnotationConfig {
dataSource: string; dataSource: string;
dataSourceForm?: () => void;
name: string; name: string;
sources?: string;
tags?: string;
} }
export interface AddDashboardConfig { export interface AddDashboardConfig {
...@@ -111,7 +110,7 @@ const addAnnotation = (config: AddAnnotationConfig, isFirst: boolean) => { ...@@ -111,7 +110,7 @@ const addAnnotation = (config: AddAnnotationConfig, isFirst: boolean) => {
.click(); .click();
} }
const { dataSource, name, sources, tags } = config; const { dataSource, dataSourceForm, name } = config;
// @todo add to e2e-selectors and `aria-label` // @todo add to e2e-selectors and `aria-label`
e2e() e2e()
...@@ -125,20 +124,8 @@ const addAnnotation = (config: AddAnnotationConfig, isFirst: boolean) => { ...@@ -125,20 +124,8 @@ const addAnnotation = (config: AddAnnotationConfig, isFirst: boolean) => {
.find('input') .find('input')
.type(name); .type(name);
if (sources) { if (dataSourceForm) {
// @todo add to e2e-selectors and `aria-label` dataSourceForm();
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);
} }
// @todo add to e2e-selectors and `aria-label` // @todo add to e2e-selectors and `aria-label`
......
import { e2e } from '../index'; import { e2e } from '../index';
// @todo this actually returns type `Cypress.Chainable` // @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(() => { select.within(() => {
if (clickToOpen) { if (clickToOpen) {
e2e() e2e()
...@@ -10,7 +10,15 @@ export const selectOption = (select: any, optionText: string, clickToOpen = true ...@@ -10,7 +10,15 @@ export const selectOption = (select: any, optionText: string, clickToOpen = true
} }
e2e.components.Select.option() 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() .scrollIntoView()
.click(); .click();
e2e() e2e()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment