grafana/e2e/various-suite/helpers/prometheus-helpers.ts
Brendan O'Handley 639bf3036d
Prometheus: Add e2e tests for decoupling (#80333)
* update selectors for prom

* add selector to switch component, needs id instead of testid

* add testid and ids to Prom settings

* add e2e tests for prom config

* add config to editor test

* export select function

* start query editor spec

* clean up describe

* add selectors for general query editor

* add selectors to components in options in best locations

* wrap header switch in id because component doesn't accept testid nor id

* add id to wrap legend components in one selector

* update selector in shared folder component, note to change in shared library

* update selector in shared folder component, note to change in shared library

* add notes for selectors in shared folder

* add tests and file for query editor

* add selectors for metrics browser in code editor

* add selector to component to open metrics browser

* add selectors to components within the metrics browser

* add tests for metrics browser and stub resource calls

* add selectors to query builder components

* add e2e tests for query builder

* generic query builder test with hints

* add selectors for more code editor parts

* add test for code and update selector

* fix tests with selector

* remove shared folder changes and use data-testid where possible

* remove unused import

* share getResources

* create variable query editor selectors

* add selectors to the variable query editor

* add e2e tests for the Prometheus variable query editor

* fix test function

* refactor add data source method

* add annotation selectors

* add selectors to annotation components

* add annotation e2e tests

* commit for yarn i18n:extract error in drone
2024-01-22 08:42:24 -06:00

63 lines
1.3 KiB
TypeScript

import { e2e } from '../../utils';
/**
* Create a Prom data source
*/
export function createPromDS(dataSourceID: string, name: string): void {
// login
e2e.flows.login(Cypress.env('USERNAME'), Cypress.env('PASSWORD'), true);
// select the prometheus DS
e2e.pages.AddDataSource.visit();
e2e.pages.AddDataSource.dataSourcePluginsV2(dataSourceID)
.scrollIntoView()
.should('be.visible') // prevents flakiness
.click();
// add url for DS to save without error
e2e.components.DataSource.Prometheus.configPage.connectionSettings().type('http://prom-url:9090');
// name the DS
e2e.pages.DataSource.name().clear();
e2e.pages.DataSource.name().type(name);
e2e.pages.DataSource.saveAndTest().click();
}
export function getResources() {
cy.intercept(/__name__/g, metricResponse);
cy.intercept(/metadata/g, metadataResponse);
cy.intercept(/labels/g, labelsResponse);
}
const metricResponse = {
status: 'success',
data: ['metric1', 'metric2'],
};
const metadataResponse = {
status: 'success',
data: {
metric1: [
{
type: 'counter',
help: 'metric1 help',
unit: '',
},
],
metric2: [
{
type: 'counter',
help: 'metric2 help',
unit: '',
},
],
},
};
const labelsResponse = {
status: 'success',
data: ['__name__', 'action', 'active', 'backend'],
};