2023-09-08 10:51:59 -05:00
|
|
|
import { e2e } from '../utils';
|
2023-01-31 11:16:28 -06:00
|
|
|
|
2023-09-29 10:14:00 -05:00
|
|
|
import datasetResponse from './fixtures/datasets-response.json';
|
|
|
|
import fieldsResponse from './fixtures/fields-response.json';
|
|
|
|
import tablesResponse from './fixtures/tables-response.json';
|
2023-01-31 11:16:28 -06:00
|
|
|
|
|
|
|
const tableNameWithSpecialCharacter = tablesResponse.results.tables.frames[0].data.values[0][1];
|
|
|
|
const normalTableName = tablesResponse.results.tables.frames[0].data.values[0][0];
|
|
|
|
|
|
|
|
describe('MySQL datasource', () => {
|
2023-09-13 07:24:20 -05:00
|
|
|
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
|
|
|
});
|
2023-01-31 11:16:28 -06:00
|
|
|
|
2023-09-13 07:24:20 -05:00
|
|
|
it('code editor autocomplete should handle table name escaping/quoting', () => {
|
2023-09-29 10:14:00 -05:00
|
|
|
cy.intercept('POST', '/api/ds/query', (req) => {
|
|
|
|
if (req.body.queries[0].refId === 'datasets') {
|
|
|
|
req.alias = 'datasets';
|
|
|
|
req.reply({
|
|
|
|
body: datasetResponse,
|
|
|
|
});
|
|
|
|
} else if (req.body.queries[0].refId === 'tables') {
|
|
|
|
req.alias = 'tables';
|
|
|
|
req.reply({
|
|
|
|
body: tablesResponse,
|
|
|
|
});
|
|
|
|
} else if (req.body.queries[0].refId === 'fields') {
|
|
|
|
req.alias = 'fields';
|
|
|
|
req.reply({
|
|
|
|
body: fieldsResponse,
|
|
|
|
});
|
2023-01-31 11:16:28 -06:00
|
|
|
}
|
2023-09-29 10:14:00 -05:00
|
|
|
});
|
2023-01-31 11:16:28 -06:00
|
|
|
|
|
|
|
e2e.pages.Explore.visit();
|
|
|
|
|
|
|
|
e2e.components.DataSourcePicker.container().should('be.visible').type('gdev-mysql{enter}');
|
|
|
|
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.get("label[for^='option-code']").should('be.visible').click();
|
|
|
|
cy.get('textarea').type('S{downArrow}{enter}');
|
|
|
|
cy.wait('@tables');
|
|
|
|
cy.get('.suggest-widget').contains(tableNameWithSpecialCharacter).should('be.visible');
|
|
|
|
cy.get('textarea').type('{enter}');
|
|
|
|
cy.get('textarea').should('have.value', `SELECT FROM grafana.\`${tableNameWithSpecialCharacter}\``);
|
2023-01-31 11:16:28 -06:00
|
|
|
|
|
|
|
const deleteTimes = new Array(tableNameWithSpecialCharacter.length + 2).fill(
|
|
|
|
'{backspace}',
|
|
|
|
0,
|
|
|
|
tableNameWithSpecialCharacter.length + 2
|
|
|
|
);
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.get('textarea').type(deleteTimes.join(''));
|
2023-01-31 11:16:28 -06:00
|
|
|
|
2023-09-29 10:14:00 -05:00
|
|
|
const commandKey = Cypress.platform === 'darwin' ? '{command}' : '{ctrl}';
|
|
|
|
|
|
|
|
cy.get('textarea').type(`${commandKey}i`);
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.get('.suggest-widget').contains(tableNameWithSpecialCharacter).should('be.visible');
|
|
|
|
cy.get('textarea').type('S{downArrow}{enter}');
|
|
|
|
cy.get('textarea').should('have.value', `SELECT FROM grafana.${normalTableName}`);
|
2023-01-31 11:16:28 -06:00
|
|
|
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.get('textarea').type('.');
|
|
|
|
cy.get('.suggest-widget').contains('No suggestions.').should('be.visible');
|
2023-01-31 11:16:28 -06:00
|
|
|
});
|
|
|
|
});
|