grafana/e2e/various-suite/prometheus-editor.spec.ts

181 lines
7.0 KiB
TypeScript
Raw Normal View History

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
import { e2e } from '../utils';
import { getResources } from './helpers/prometheus-helpers';
const DATASOURCE_ID = 'Prometheus';
type editorType = 'Code' | 'Builder';
/**
* Login, create and save a Prometheus data source, navigate to code or builder
*
* @param editorType 'Code' or 'Builder'
*/
function navigateToEditor(editorType: editorType, 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(DATASOURCE_ID)
.scrollIntoView()
.should('be.visible') // prevents flakiness
.click();
// choose default editor
e2e.components.DataSource.Prometheus.configPage.defaultEditor().scrollIntoView().should('exist').click();
selectOption(editorType);
// 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();
// visit explore
e2e.pages.Explore.visit();
// choose the right DS
e2e.components.DataSourcePicker.container().should('be.visible').click();
cy.contains(name).scrollIntoView().should('be.visible').click();
}
// Skipping due to flakiness/race conditions with same old arch test e2e/various-suite/prometheus-editor.spec.ts
describe.skip('Prometheus query editor', () => {
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
it('should have a kickstart component', () => {
navigateToEditor('Code', 'prometheus');
e2e.components.QueryBuilder.queryPatterns().scrollIntoView().should('exist');
});
it('should have an explain component', () => {
navigateToEditor('Code', 'prometheus');
e2e.components.DataSource.Prometheus.queryEditor.explain().scrollIntoView().should('exist');
});
it('should have an editor toggle component', () => {
navigateToEditor('Code', 'prometheus');
e2e.components.DataSource.Prometheus.queryEditor.editorToggle().scrollIntoView().should('exist');
});
it('should have an options component with legend, format, step, type and exemplars', () => {
navigateToEditor('Code', 'prometheus');
// open options
e2e.components.DataSource.Prometheus.queryEditor.options().scrollIntoView().should('exist').click();
// check options
e2e.components.DataSource.Prometheus.queryEditor.legend().scrollIntoView().should('exist');
e2e.components.DataSource.Prometheus.queryEditor.format().scrollIntoView().should('exist');
cy.get(`[data-test-id="prometheus-step"]`).scrollIntoView().should('exist');
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
e2e.components.DataSource.Prometheus.queryEditor.type().scrollIntoView().should('exist');
cy.get(`[data-test-id="prometheus-exemplars"]`).scrollIntoView().should('exist');
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
});
describe('Code editor', () => {
it('navigates to the code editor with editor type as code', () => {
navigateToEditor('Code', 'prometheusCode');
});
it('navigates to the code editor and opens the metrics browser with metric search, labels, label values, and all components', () => {
navigateToEditor('Code', 'prometheusCode');
getResources();
e2e.components.DataSource.Prometheus.queryEditor.code.queryField().should('exist');
e2e.components.DataSource.Prometheus.queryEditor.code.metricsBrowser
.openButton()
.contains('Metrics browser')
.click();
e2e.components.DataSource.Prometheus.queryEditor.code.metricsBrowser.selectMetric().should('exist');
e2e.components.DataSource.Prometheus.queryEditor.code.metricsBrowser.labelNamesFilter().should('exist');
e2e.components.DataSource.Prometheus.queryEditor.code.metricsBrowser.labelValuesFilter().should('exist');
e2e.components.DataSource.Prometheus.queryEditor.code.metricsBrowser.useQuery().should('exist');
e2e.components.DataSource.Prometheus.queryEditor.code.metricsBrowser.useAsRateQuery().should('exist');
e2e.components.DataSource.Prometheus.queryEditor.code.metricsBrowser.validateSelector().should('exist');
e2e.components.DataSource.Prometheus.queryEditor.code.metricsBrowser.clear().should('exist');
});
it('selects a metric in the metrics browser and uses the query', () => {
navigateToEditor('Code', 'prometheusCode');
getResources();
e2e.components.DataSource.Prometheus.queryEditor.code.metricsBrowser
.openButton()
.contains('Metrics browser')
.click();
e2e.components.DataSource.Prometheus.queryEditor.code.metricsBrowser.selectMetric().should('exist').type('met');
e2e.components.DataSource.Prometheus.queryEditor.code.metricsBrowser
.metricList()
.should('exist')
.contains('metric1')
.click();
e2e.components.DataSource.Prometheus.queryEditor.code.metricsBrowser.useQuery().should('exist').click();
e2e.components.DataSource.Prometheus.queryEditor.code.queryField().should('exist').contains('metric1');
});
});
describe('Query builder', () => {
it('navigates to the query builder with editor type as code', () => {
navigateToEditor('Builder', 'prometheusBuilder');
});
it('the query builder contains metric select, label filters and operations', () => {
navigateToEditor('Builder', 'prometheusBuilder');
getResources();
e2e.components.DataSource.Prometheus.queryEditor.builder.metricSelect().should('exist');
e2e.components.QueryBuilder.labelSelect().should('exist');
e2e.components.QueryBuilder.matchOperatorSelect().should('exist');
e2e.components.QueryBuilder.valueSelect().should('exist');
});
it('can select a metric and provide a hint', () => {
navigateToEditor('Builder', 'prometheusBuilder');
getResources();
e2e.components.DataSource.Prometheus.queryEditor.builder.metricSelect().should('exist').click();
selectOption('metric1');
e2e.components.DataSource.Prometheus.queryEditor.builder.hints().contains('hint: add rate');
});
it('should have the metrics explorer opened via the metric select', () => {
navigateToEditor('Builder', 'prometheusBuilder');
getResources();
e2e.components.DataSource.Prometheus.queryEditor.builder.metricSelect().should('exist').click();
selectOption('Metrics explorer');
e2e.components.DataSource.Prometheus.queryEditor.builder.metricsExplorer().should('exist');
});
// NEED TO COMPLETE QUEY ADVISOR WORK OR FIGURE OUT HOW TO ENABLE EXPERIMENTAL FEATURE TOGGLES
// it('should have a query advisor when enabled with feature toggle', () => {
// cy.window().then((win) => {
// win.localStorage.setItem('grafana.featureToggles', 'prometheusPromQAIL=0');
// navigateToEditor('Builder', 'prometheusBuilder');
// getResources();
// e2e.components.DataSource.Prometheus.queryEditor.builder.queryAdvisor().should('exist');
// });
// });
});
});
function selectOption(option: string) {
e2e.components.Select.option().contains(option).should('be.visible').click();
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
}