2023-09-08 10:51:59 -05:00
|
|
|
import { e2e } from '../utils';
|
2022-11-08 09:22:40 -06:00
|
|
|
|
|
|
|
const dataSourceName = 'LokiEditor';
|
|
|
|
const addDataSource = () => {
|
|
|
|
e2e.flows.addDataSource({
|
|
|
|
type: 'Loki',
|
2023-09-05 01:59:13 -05:00
|
|
|
expectedAlertMessage: 'Unable to connect with Loki. Please check the server logs for more details.',
|
2022-11-08 09:22:40 -06:00
|
|
|
name: dataSourceName,
|
|
|
|
form: () => {
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.get('#connection-url').type('http://loki-url:3100');
|
2022-11-08 09:22:40 -06:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-09-13 07:24:20 -05:00
|
|
|
describe('Loki Query Editor', () => {
|
|
|
|
beforeEach(() => {
|
2023-09-27 05:33:00 -05:00
|
|
|
e2e.flows.login(Cypress.env('USERNAME'), Cypress.env('PASSWORD'));
|
2023-09-13 07:24:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
e2e.flows.revertAllChanges();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Autocomplete features should work as expected.', () => {
|
2022-11-08 09:22:40 -06:00
|
|
|
addDataSource();
|
|
|
|
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.intercept(/labels?/, (req) => {
|
2022-11-08 09:22:40 -06:00
|
|
|
req.reply({ status: 'success', data: ['instance', 'job', 'source'] });
|
|
|
|
});
|
|
|
|
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.intercept(/series?/, (req) => {
|
2022-11-08 09:22:40 -06:00
|
|
|
req.reply({ status: 'success', data: [{ instance: 'instance1' }] });
|
|
|
|
});
|
|
|
|
|
|
|
|
// Go to Explore and choose Loki data source
|
|
|
|
e2e.pages.Explore.visit();
|
|
|
|
e2e.components.DataSourcePicker.container().should('be.visible').click();
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.contains(dataSourceName).scrollIntoView().should('be.visible').click();
|
2022-11-08 09:22:40 -06:00
|
|
|
|
2023-11-27 06:54:07 -06:00
|
|
|
e2e.components.RadioButton.container().filter(':contains("Code")').click();
|
2022-11-08 09:22:40 -06:00
|
|
|
|
2022-11-09 06:37:00 -06:00
|
|
|
// Wait for lazy loading
|
2022-11-08 09:22:40 -06:00
|
|
|
const monacoLoadingText = 'Loading...';
|
2022-11-09 06:37:00 -06:00
|
|
|
|
2022-11-08 09:22:40 -06:00
|
|
|
e2e.components.QueryField.container().should('be.visible').should('have.text', monacoLoadingText);
|
|
|
|
e2e.components.QueryField.container().should('be.visible').should('not.have.text', monacoLoadingText);
|
|
|
|
|
2022-11-09 06:37:00 -06:00
|
|
|
// adds closing braces around empty value
|
|
|
|
e2e.components.QueryField.container().type('time(');
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.get('.monaco-editor textarea:first').should(($el) => {
|
|
|
|
expect($el.val()).to.eq('time()');
|
|
|
|
});
|
2022-11-09 06:37:00 -06:00
|
|
|
|
|
|
|
// removes closing brace when opening brace is removed
|
|
|
|
e2e.components.QueryField.container().type('{selectall}{backspace}avg_over_time({backspace}');
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.get('.monaco-editor textarea:first').should(($el) => {
|
|
|
|
expect($el.val()).to.eq('avg_over_time');
|
|
|
|
});
|
2022-11-09 06:37:00 -06:00
|
|
|
|
|
|
|
// keeps closing brace when opening brace is removed and inner values exist
|
|
|
|
e2e.components.QueryField.container().type(
|
|
|
|
'{selectall}{backspace}time(test{leftArrow}{leftArrow}{leftArrow}{leftArrow}{backspace}'
|
|
|
|
);
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.get('.monaco-editor textarea:first').should(($el) => {
|
|
|
|
expect($el.val()).to.eq('timetest)');
|
|
|
|
});
|
2022-11-09 06:37:00 -06:00
|
|
|
|
|
|
|
// overrides an automatically inserted brace
|
|
|
|
e2e.components.QueryField.container().type('{selectall}{backspace}time()');
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.get('.monaco-editor textarea:first').should(($el) => {
|
|
|
|
expect($el.val()).to.eq('time()');
|
|
|
|
});
|
2022-11-09 06:37:00 -06:00
|
|
|
|
|
|
|
// does not override manually inserted braces
|
|
|
|
e2e.components.QueryField.container().type('{selectall}{backspace}))');
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.get('.monaco-editor textarea:first').should(($el) => {
|
|
|
|
expect($el.val()).to.eq('))');
|
|
|
|
});
|
2022-11-09 06:37:00 -06:00
|
|
|
|
|
|
|
/** Runner plugin */
|
2022-11-08 09:22:40 -06:00
|
|
|
|
2022-11-09 06:37:00 -06:00
|
|
|
// Should execute the query when enter with shift is pressed
|
|
|
|
e2e.components.QueryField.container().type('{selectall}{backspace}{shift+enter}');
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.get('[data-testid="explore-no-data"]').should('be.visible');
|
2022-11-08 09:22:40 -06:00
|
|
|
|
2022-11-09 06:37:00 -06:00
|
|
|
/** Suggestions plugin */
|
|
|
|
e2e.components.QueryField.container().type('{selectall}av');
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.contains('avg').should('be.visible');
|
|
|
|
cy.contains('avg_over_time').should('be.visible');
|
2023-09-13 07:24:20 -05:00
|
|
|
});
|
2022-11-08 09:22:40 -06:00
|
|
|
});
|