@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`
This commit is contained in:
Steven Vachon
2020-09-15 15:10:56 -04:00
committed by GitHub
parent 54b677bda4
commit ed4ef0862d
2 changed files with 14 additions and 19 deletions
+4 -17
View File
@@ -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`
+10 -2
View File
@@ -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()