mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 02:10:45 -06:00
639bf3036d
* 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
123 lines
4.3 KiB
TypeScript
123 lines
4.3 KiB
TypeScript
import { e2e } from '../utils';
|
|
import { addDashboard } from '../utils/flows';
|
|
|
|
import { createPromDS, getResources } from './helpers/prometheus-helpers';
|
|
|
|
const DATASOURCE_ID = 'Prometheus';
|
|
|
|
const DATASOURCE_NAME = 'prometheusVariableDS';
|
|
|
|
/**
|
|
* Click dashboard settings and then the variables tab
|
|
*/
|
|
function navigateToVariables() {
|
|
e2e.components.PageToolbar.item('Dashboard settings').click();
|
|
e2e.components.Tab.title('Variables').click();
|
|
}
|
|
|
|
/**
|
|
* Begin the process of adding a query type variable for a Prometheus data source
|
|
*
|
|
* @param variableName the name of the variable as a label of the variable dropdown
|
|
*/
|
|
function addPrometheusQueryVariable(variableName: string) {
|
|
e2e.pages.Dashboard.Settings.Variables.List.addVariableCTAV2().click();
|
|
|
|
e2e.pages.Dashboard.Settings.Variables.Edit.General.generalNameInputV2().clear().type(variableName);
|
|
e2e.components.DataSourcePicker.container().should('be.visible').click();
|
|
cy.contains(DATASOURCE_NAME).scrollIntoView().should('be.visible').click();
|
|
|
|
getResources();
|
|
}
|
|
|
|
/**
|
|
* Create a Prometheus variable and navigate to the query editor to check that it is available to use.
|
|
*
|
|
* @param variableName name the variable
|
|
* @param queryType query type of 'Label names', 'Label values', 'Metrics', 'Query result', 'Series query' or 'Classic query'. These types should be imported from the Prometheus library eventually but not now because we are in the process of decoupling the DS from core grafana.
|
|
*/
|
|
function variableFlowToQueryEditor(variableName: string, queryType: string) {
|
|
addDashboard();
|
|
navigateToVariables();
|
|
addPrometheusQueryVariable(variableName);
|
|
|
|
// select query type
|
|
e2e.components.DataSource.Prometheus.variableQueryEditor.queryType().click();
|
|
selectOption(queryType);
|
|
|
|
// apply the variable
|
|
e2e.pages.Dashboard.Settings.Variables.Edit.General.applyButton().click();
|
|
|
|
// close to return to dashboard
|
|
e2e.pages.Dashboard.Settings.Actions.close().click();
|
|
|
|
// add visualization
|
|
e2e.pages.AddDashboard.itemButton('Create new panel button').should('be.visible').click();
|
|
|
|
// close the data source picker modal
|
|
cy.get('[aria-label="Close"]').click();
|
|
|
|
// select prom data source from the data source list with the useful data-testid
|
|
e2e.components.DataSourcePicker.inputV2().click({ force: true }).type(`${DATASOURCE_NAME}{enter}`);
|
|
|
|
// confirm the variable exists in the correct input
|
|
// use the variable query type from the library in the future
|
|
switch (queryType) {
|
|
case 'Label names':
|
|
e2e.components.QueryBuilder.labelSelect().should('exist').click({ force: true });
|
|
selectOption(`${variableName}`);
|
|
case 'Label values':
|
|
e2e.components.QueryBuilder.valueSelect().should('exist').click({ force: true });
|
|
selectOption(`${variableName}`);
|
|
case 'Metrics':
|
|
e2e.components.DataSource.Prometheus.queryEditor.builder.metricSelect().should('exist').click({ force: true });
|
|
selectOption(`${variableName}`);
|
|
default:
|
|
// do nothing
|
|
}
|
|
}
|
|
|
|
describe('Prometheus variable query editor', () => {
|
|
beforeEach(() => {
|
|
createPromDS(DATASOURCE_ID, DATASOURCE_NAME);
|
|
});
|
|
|
|
it('should navigate to variable query editor', () => {
|
|
addDashboard();
|
|
navigateToVariables();
|
|
});
|
|
|
|
it('should select a query type for a Prometheus variable query', () => {
|
|
addDashboard();
|
|
navigateToVariables();
|
|
addPrometheusQueryVariable('labelsVariable');
|
|
|
|
// select query type
|
|
e2e.components.DataSource.Prometheus.variableQueryEditor.queryType().click();
|
|
|
|
selectOption('Label names');
|
|
});
|
|
|
|
it('should create a label names variable that is selectable in the label select in query builder', () => {
|
|
addDashboard();
|
|
navigateToVariables();
|
|
variableFlowToQueryEditor('labelnames', 'Label names');
|
|
});
|
|
|
|
it('should create a label values variable that is selectable in the label values select in query builder', () => {
|
|
addDashboard();
|
|
navigateToVariables();
|
|
variableFlowToQueryEditor('labelvalues', 'Label values');
|
|
});
|
|
|
|
it('should create a metric names variable that is selectable in the metric select in query builder', () => {
|
|
addDashboard();
|
|
navigateToVariables();
|
|
variableFlowToQueryEditor('metrics', 'Metrics');
|
|
});
|
|
});
|
|
|
|
function selectOption(option: string) {
|
|
cy.get("[aria-label='Select option']").contains(option).should('be.visible').click();
|
|
}
|