mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Feat: timeGroup macro handling in VQB * Add tests * Add functions to SQL ds * Fix lint errors * Add feature toggle * Add rendering based on object * Fix lint * Fix CI failures * Fix tests * Address review comments * Add docs * Fix JSX runtime warnings * Remove docs part that mentions suggest more macros * Update docs/sources/shared/datasources/sql-query-builder-macros.md Co-authored-by: Jack Baldry <jack.baldry@grafana.com> * Add smoke test for this feature * lint * Add supported macros to influx * Add setupTests.ts to include in tsconfig.json * Import jest-dom instead of setupTests.ts --------- Co-authored-by: Jack Baldry <jack.baldry@grafana.com>
48 lines
2.0 KiB
TypeScript
48 lines
2.0 KiB
TypeScript
import { selectors } from '@grafana/e2e-selectors';
|
|
import { test, expect } from '@grafana/plugin-e2e';
|
|
|
|
import { normalTableName } from './mocks/mysql.mocks';
|
|
import { mockDataSourceRequest } from './utils';
|
|
|
|
test.beforeEach(mockDataSourceRequest);
|
|
|
|
test.use({ featureToggles: { sqlQuerybuilderFunctionParameters: true } });
|
|
|
|
test('visual query builder should handle macros', async ({ explorePage, page }) => {
|
|
await explorePage.getByGrafanaSelector(selectors.components.SQLQueryEditor.headerTableSelector).click();
|
|
await page.getByText(normalTableName, { exact: true }).click();
|
|
|
|
// Open Data operations
|
|
await explorePage.getByGrafanaSelector(selectors.components.SQLQueryEditor.selectAggregation).click();
|
|
const select = page.getByLabel('Select options menu');
|
|
await select.locator(page.getByText('$__timeGroupAlias')).click();
|
|
|
|
// Open column selector
|
|
await explorePage.getByGrafanaSelector(selectors.components.SQLQueryEditor.selectFunctionParameter('Column')).click();
|
|
await select.locator(page.getByText('createdAt')).click();
|
|
|
|
// Open Interval selector
|
|
await explorePage
|
|
.getByGrafanaSelector(selectors.components.SQLQueryEditor.selectFunctionParameter('Interval'))
|
|
.click();
|
|
await select.locator(page.getByText('$__interval')).click();
|
|
|
|
await page.getByRole('button', { name: 'Add column' }).click();
|
|
|
|
await explorePage.getByGrafanaSelector(selectors.components.SQLQueryEditor.selectAggregation).nth(1).click();
|
|
await select.locator(page.getByText('AVG')).click();
|
|
|
|
await explorePage
|
|
.getByGrafanaSelector(selectors.components.SQLQueryEditor.selectFunctionParameter('Column'))
|
|
.nth(1)
|
|
.click();
|
|
await select.locator(page.getByText('bigint')).click();
|
|
|
|
// Validate the query
|
|
await expect(
|
|
explorePage.getByGrafanaSelector(selectors.components.CodeEditor.container).getByRole('textbox')
|
|
).toHaveValue(
|
|
`SELECT\n $__timeGroupAlias(createdAt, $__interval),\n AVG(\`bigint\`)\nFROM\n DataMaker.normalTable\nLIMIT\n 50`
|
|
);
|
|
});
|