mirror of https://github.com/grafana/grafana
Loki: enable Monaco Query Editor by default (#58080)
* feat(loki-monaco-editor): update tests * chore(loki): use unified datasource mock function in tests * chore: enable monaco feature flag in tests * feat(loki-monaco-editor): add test case for disabled feature * feat(loki-monaco-editor): enable by default * Revert "feat(loki-monaco-editor): enable by default" This reverts commit 08904f94a707a4fa32aa1e7f3f0de377575a7636. * feat(loki-monaco-editor): enable from registry * feat(loki-monaco-editor): make feature flag frontend onlypull/58442/head
parent
29fcc46333
commit
25f79ef2b9
@ -0,0 +1,56 @@ |
||||
import { e2e } from '@grafana/e2e'; |
||||
|
||||
const dataSourceName = 'LokiEditor'; |
||||
const addDataSource = () => { |
||||
e2e.flows.addDataSource({ |
||||
type: 'Loki', |
||||
expectedAlertMessage: |
||||
'Unable to fetch labels from Loki (Failed to call resource), please check the server logs for more details', |
||||
name: dataSourceName, |
||||
form: () => { |
||||
e2e.components.DataSource.DataSourceHttpSettings.urlInput().type('http://loki-url:3100'); |
||||
}, |
||||
}); |
||||
}; |
||||
|
||||
e2e.scenario({ |
||||
describeName: 'Loki Query Editor', |
||||
itName: 'Autocomplete features should work as expected.', |
||||
addScenarioDataSource: false, |
||||
addScenarioDashBoard: false, |
||||
skipScenario: false, |
||||
scenario: () => { |
||||
addDataSource(); |
||||
|
||||
e2e().intercept(/labels?/, (req) => { |
||||
req.reply({ status: 'success', data: ['instance', 'job', 'source'] }); |
||||
}); |
||||
|
||||
e2e().intercept(/series?/, (req) => { |
||||
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(); |
||||
e2e().contains(dataSourceName).scrollIntoView().should('be.visible').click(); |
||||
|
||||
cy.contains('label', 'Code').click(); |
||||
|
||||
// we need to wait for the query-field being lazy-loaded, in two steps:
|
||||
// it is a two-step process:
|
||||
// 1. first we wait for the text 'Loading...' to appear
|
||||
// 1. then we wait for the text 'Loading...' to disappear
|
||||
const monacoLoadingText = 'Loading...'; |
||||
const queryText = `rate(http_requests_total{job="grafana"}[5m])`; |
||||
e2e.components.QueryField.container().should('be.visible').should('have.text', monacoLoadingText); |
||||
e2e.components.QueryField.container().should('be.visible').should('not.have.text', monacoLoadingText); |
||||
e2e.components.QueryField.container().type(queryText, { parseSpecialCharSequences: false }).type('{backspace}'); |
||||
|
||||
cy.contains(queryText.slice(0, -1)).should('be.visible'); |
||||
|
||||
e2e.components.QueryField.container().type(e2e.typings.undo()); |
||||
|
||||
cy.contains(queryText).should('be.visible'); |
||||
}, |
||||
}); |
||||
@ -1,113 +0,0 @@ |
||||
import { e2e } from '@grafana/e2e'; |
||||
|
||||
const dataSourceName = 'LokiSlate'; |
||||
const addDataSource = () => { |
||||
e2e.flows.addDataSource({ |
||||
type: 'Loki', |
||||
expectedAlertMessage: |
||||
'Unable to fetch labels from Loki (Failed to call resource), please check the server logs for more details', |
||||
name: dataSourceName, |
||||
form: () => { |
||||
e2e.components.DataSource.DataSourceHttpSettings.urlInput().type('http://loki-url:3100'); |
||||
}, |
||||
}); |
||||
}; |
||||
|
||||
describe('Loki slate editor', () => { |
||||
beforeEach(() => { |
||||
e2e.flows.login('admin', 'admin'); |
||||
|
||||
e2e() |
||||
.request({ url: `${e2e.env('BASE_URL')}/api/datasources/name/${dataSourceName}`, failOnStatusCode: false }) |
||||
.then((response) => { |
||||
if (response.isOkStatusCode) { |
||||
return; |
||||
} |
||||
addDataSource(); |
||||
}); |
||||
}); |
||||
|
||||
it('Braces plugin should insert closing brace', () => { |
||||
e2e().intercept(/labels?/, (req) => { |
||||
req.reply({ status: 'success', data: ['instance', 'job', 'source'] }); |
||||
}); |
||||
|
||||
e2e().intercept(/series?/, (req) => { |
||||
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(); |
||||
e2e().contains(dataSourceName).scrollIntoView().should('be.visible').click(); |
||||
|
||||
// adds closing braces around empty value
|
||||
e2e().contains('Code').click(); |
||||
const queryField = e2e().get('.slate-query-field'); |
||||
queryField.type('time('); |
||||
queryField.should(($el) => { |
||||
expect($el.text().replace(/\uFEFF/g, '')).to.eq('time()'); |
||||
}); |
||||
|
||||
// removes closing brace when opening brace is removed
|
||||
queryField.type('{backspace}'); |
||||
queryField.should(($el) => { |
||||
expect($el.text().replace(/\uFEFF/g, '')).to.eq('time'); |
||||
}); |
||||
|
||||
// keeps closing brace when opening brace is removed and inner values exist
|
||||
queryField.clear(); |
||||
queryField.type('time(test{leftArrow}{leftArrow}{leftArrow}{leftArrow}{backspace}'); |
||||
queryField.should(($el) => { |
||||
expect($el.text().replace(/\uFEFF/g, '')).to.eq('timetest)'); |
||||
}); |
||||
|
||||
// overrides an automatically inserted brace
|
||||
queryField.clear(); |
||||
queryField.type('time()'); |
||||
queryField.should(($el) => { |
||||
expect($el.text().replace(/\uFEFF/g, '')).to.eq('time()'); |
||||
}); |
||||
|
||||
// does not override manually inserted braces
|
||||
queryField.clear(); |
||||
queryField.type('))'); |
||||
queryField.should(($el) => { |
||||
expect($el.text().replace(/\uFEFF/g, '')).to.eq('))'); |
||||
}); |
||||
|
||||
/** Clear Plugin */ |
||||
|
||||
//does not change the empty value
|
||||
queryField.clear(); |
||||
queryField.type('{ctrl+k}'); |
||||
queryField.should(($el) => { |
||||
expect($el.text().replace(/\uFEFF/g, '')).to.match(/Enter a Loki query/); |
||||
}); |
||||
|
||||
// clears to the end of the line
|
||||
queryField.clear(); |
||||
queryField.type('foo{leftArrow}{leftArrow}{leftArrow}{ctrl+k}'); |
||||
queryField.should(($el) => { |
||||
expect($el.text().replace(/\uFEFF/g, '')).to.match(/Enter a Loki query/); |
||||
}); |
||||
|
||||
// clears from the middle to the end of the line
|
||||
queryField.clear(); |
||||
queryField.type('foo bar{leftArrow}{leftArrow}{leftArrow}{leftArrow}{ctrl+k}'); |
||||
queryField.should(($el) => { |
||||
expect($el.text().replace(/\uFEFF/g, '')).to.eq('foo'); |
||||
}); |
||||
|
||||
/** Runner plugin */ |
||||
|
||||
//should execute query when enter with shift is pressed
|
||||
queryField.clear(); |
||||
queryField.type('{shift+enter}'); |
||||
e2e().get('[data-testid="explore-no-data"]').should('be.visible'); |
||||
|
||||
/** Suggestions plugin */ |
||||
e2e().get('.slate-query-field').type(`{selectall}av`); |
||||
e2e().get('.slate-typeahead').should('be.visible').contains('avg_over_time'); |
||||
}); |
||||
}); |
||||
Loading…
Reference in new issue