Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin E2E: Make getQueryEditorRow method sync #699

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/plugin-e2e/src/models/ExplorePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ export class ExplorePage extends GrafanaPage {
/**
* Returns the locator for the query editor row with the given refId
*/
async getQueryEditorRow(refId: string): Promise<Locator> {
const locator = this.getByTestIdOrAriaLabel(this.ctx.selectors.components.QueryEditorRows.rows).filter({
getQueryEditorRow(refId: string): Locator {
return this.getByTestIdOrAriaLabel(this.ctx.selectors.components.QueryEditorRows.rows).filter({
has: this.getByTestIdOrAriaLabel(this.ctx.selectors.components.QueryEditorRow.title(refId)),
});
await expect(locator).toBeVisible();
return locator;
}

/**
Expand Down
8 changes: 3 additions & 5 deletions packages/plugin-e2e/src/models/PanelEditPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class PanelEditPage extends GrafanaPage implements PanelError {
/**
* Returns the name of the visualization currently selected in the panel editor
*/
getVisualizationName() {
getVisualizationName(): Locator {
return this.getByTestIdOrAriaLabel(this.ctx.selectors.components.PanelEditor.toggleVizPicker);
}

Expand All @@ -100,12 +100,10 @@ export class PanelEditPage extends GrafanaPage implements PanelError {
/**
* Returns the locator for the query editor row with the given refId
*/
async getQueryEditorRow(refId: string): Promise<Locator> {
const locator = this.getByTestIdOrAriaLabel(this.ctx.selectors.components.QueryEditorRows.rows).filter({
getQueryEditorRow(refId: string): Locator {
return this.getByTestIdOrAriaLabel(this.ctx.selectors.components.QueryEditorRows.rows).filter({
has: this.getByTestIdOrAriaLabel(this.ctx.selectors.components.QueryEditorRow.title(refId)),
});
await expect(locator).toBeVisible();
return locator;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ test('should return data and not display panel error when a valid query is provi
const provision = await readProvision<ProvisionFile>({ filePath: 'datasources/google-sheets-datasource-jwt.yaml' });
await explorePage.datasource.set(provision.datasources?.[0]!.name!);
await explorePage.timeRange.set({ from: '2019-01-11', to: '2019-12-15' });
const queryEditorRow = await explorePage.getQueryEditorRow('A');
await queryEditorRow.getByText('Enter SpreadsheetID').click();
await explorePage.getQueryEditorRow('A').getByText('Enter SpreadsheetID').click();
await page.keyboard.insertText('1TZlZX67Y0s4CvRro_3pCYqRCKuXer81oFp_xcsjPpe8');
const responsePromise = page.waitForResponse((resp) => resp.url().includes('/api/ds/query'));
await page.keyboard.press('Tab');
Expand All @@ -26,10 +25,9 @@ test('should return an error and display panel error when an invalid query is pr
const provision = await readProvision<ProvisionFile>({ filePath: 'datasources/google-sheets-datasource-jwt.yaml' });
await explorePage.datasource.set(provision.datasources?.[0]!.name!);
await explorePage.timeRange.set({ from: '2019-01-11', to: '2019-12-15' });
const queryEditorRow = await explorePage.getQueryEditorRow('A');
await page.getByPlaceholder('Class Data!A2:E').fill('invalid range');
await page.keyboard.press('Tab');
await queryEditorRow.getByText('Enter SpreadsheetID').click();
await explorePage.getQueryEditorRow('A').getByText('Enter SpreadsheetID').click();
await page.keyboard.insertText('1TZlZX67Y0s4CvRro_3pCYqRCKuXer81oFp_xcsjPpe8');
const responsePromise = page.waitForResponse((resp) => resp.url().includes('/api/ds/query'));
await page.keyboard.press('Tab');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('editor populates query from url', async ({ explorePage, readProvision }) =
`panes=%7B%22xlX%22:%7B%22datasource%22:%22undefined%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22datasource%22:%7B%22type%22:%22grafana-redshift-datasource%22,%22uid%22:%22P7DC3E4760CFAC4AH%22%7D,%22rawSQL%22:%22SELECT%20%2A%20FROM%20public.average_temperature%22,%22format%22:0%7D%5D,%22range%22:%7B%22from%22:%221579046400000%22,%22to%22:%221607990400000%22%7D%7D%7D&schemaVersion=1&orgId=1&left=%7B%22datasource%22:%22P7DC3E4760CFAC4AH%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22datasource%22:%7B%22type%22:%22grafana-redshift-datasource%22,%22uid%22:%22P7DC3E4760CFAC4AH%22%7D,%22rawSQL%22:%22SELECT%20%2A%20FROM%20public.average_temperature%22,%22format%22:0%7D%5D,%22range%22:%7B%22from%22:%22now-1h%22,%22to%22:%22now%22%7D%7D`
),
});
const queryEditorRowLocator = await explorePage.getQueryEditorRow('A');
const queryEditorRowLocator = explorePage.getQueryEditorRow('A');
await expect(queryEditorRowLocator).toContainText('SELECT * FROM public.average_temperature');
await expect(queryEditorRowLocator).toContainText('Time Series');
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ test('should return data and not display panel error when a valid query is provi
const provision = await readProvision<ProvisionFile>({ filePath: 'datasources/google-sheets-datasource-jwt.yaml' });
await panelEditPage.datasource.set(provision.datasources?.[0]!.name!);
await panelEditPage.timeRange.set({ from: '2019-01-11', to: '2019-12-15' });
const queryEditorRow = await panelEditPage.getQueryEditorRow('A');
await queryEditorRow.getByText('Enter SpreadsheetID').click();
await panelEditPage.getQueryEditorRow('A').getByText('Enter SpreadsheetID').click();
await page.keyboard.insertText('1TZlZX67Y0s4CvRro_3pCYqRCKuXer81oFp_xcsjPpe8');
await page.keyboard.press('Enter');
await expect(panelEditPage.refreshPanel()).toBeOK();
Expand All @@ -25,8 +24,7 @@ test('should return an error and display panel error when an invalid query is pr
const provision = await readProvision<ProvisionFile>({ filePath: 'datasources/google-sheets-datasource-jwt.yaml' });
await panelEditPage.datasource.set(provision.datasources?.[0]!.name!);
await panelEditPage.timeRange.set({ from: '2019-01-11', to: '2019-12-15' });
const queryEditorRow = await panelEditPage.getQueryEditorRow('A');
await queryEditorRow.getByText('Enter SpreadsheetID').click();
await panelEditPage.getQueryEditorRow('A').getByText('Enter SpreadsheetID').click();
await page.keyboard.insertText('1TZlZX67Y0s4CvRro_3pCYqRCKuXer81oFp_xcsjPpe8');
await page.keyboard.press('Enter');
await page.getByPlaceholder('Class Data!A2:E').fill('invalid range');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ test('should list spreadsheets when clicking on spreadsheet segment', async ({
filePath: 'datasources/google-sheets-datasource-jwt.yaml',
}).then((provision) => provision.datasources?.[0]!);
await panelEditPage.datasource.set(sheetsDataSource.name!);
const queryEditorRow = await panelEditPage.getQueryEditorRow('A');
await panelEditPage.mockResourceResponse('spreadsheets', GOOGLE_SHEETS_SPREADSHEETS);
await queryEditorRow.getByText('Enter SpreadsheetID').click();
await panelEditPage.getQueryEditorRow('A').getByText('Enter SpreadsheetID').click();
await expect(page.getByText(GOOGLE_SHEETS_SPREADSHEETS.spreadsheets.sheet1, { exact: true })).toHaveCount(1);
await expect(page.getByText(GOOGLE_SHEETS_SPREADSHEETS.spreadsheets.sheet2, { exact: true })).toHaveCount(1);
});

test('should set correct cache time on query passed to the backend', async ({ panelEditPage, page, readProvision }) => {
const provision = await readProvision<ProvisionFile>({ filePath: 'datasources/google-sheets-datasource-jwt.yaml' });
await panelEditPage.datasource.set(provision.datasources?.[0]!.name!);
const queryEditorRow = await panelEditPage.getQueryEditorRow('A');
await panelEditPage.mockResourceResponse('spreadsheets', GOOGLE_SHEETS_SPREADSHEETS);
await queryEditorRow.getByText('5m', { exact: true }).click();
await panelEditPage.getQueryEditorRow('A').getByText('5m', { exact: true }).click();
await page.keyboard.insertText('1h');
await page.keyboard.press('Enter');

Expand Down
Loading