From 3b8278a60b5420802a6c9852098251429c6d4782 Mon Sep 17 00:00:00 2001 From: Akash Pathak Date: Tue, 11 Aug 2026 13:41:39 +0200 Subject: [PATCH] test: expand query editor E2E coverage --- tests/QueryEditor.spec.ts | 29 ++++++++++++++++++++- tests/VariableQueryEditor.spec.ts | 38 +++++++++++++++++++++++++++ tests/mocks/github-response.ts | 43 +++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 tests/VariableQueryEditor.spec.ts diff --git a/tests/QueryEditor.spec.ts b/tests/QueryEditor.spec.ts index d5f69c88..95072dd1 100644 --- a/tests/QueryEditor.spec.ts +++ b/tests/QueryEditor.spec.ts @@ -1,6 +1,6 @@ import { test, expect } from '@grafana/plugin-e2e'; import { components } from '../src/components/selectors'; -import { githubResponse } from './mocks/github-response'; +import { githubBranchesResponse, githubResponse } from './mocks/github-response'; const type = 'grafana-github-datasource'; let datasourceName = ''; @@ -28,3 +28,30 @@ test('QueryEditor smoke test', async ({ panelEditPage, page }) => { await expect(page.getByRole('cell', { name: 'grafana-github-datasource v1.5.7' })).toBeVisible(); } }); + +test('Branches query sends its filter and renders the response', async ({ panelEditPage, page }) => { + await panelEditPage.mockQueryDataResponse(githubBranchesResponse); + await panelEditPage.setVisualization('Table'); + await panelEditPage.datasource.set(datasourceName); + + const queryTypeContainer = panelEditPage.getByGrafanaSelector(components.QueryEditor.QueryType.container.ariaLabel); + await queryTypeContainer.getByRole('combobox').click(); + await page.getByRole('listbox').getByRole('option', { name: 'Branches' }).click(); + await panelEditPage.getByGrafanaSelector(components.QueryEditor.Owner.input).fill('grafana'); + await panelEditPage.getByGrafanaSelector(components.QueryEditor.Repository.input).fill('github-datasource'); + await page.getByRole('textbox', { name: 'Branch filter' }).fill('release/'); + await page.getByRole('textbox', { name: 'Branch filter' }).blur(); + + const queryDataRequest = panelEditPage.waitForQueryDataRequest(); + await expect(panelEditPage.refreshPanel()).toBeOK(); + const request = await queryDataRequest; + expect(request.postDataJSON().queries[0]).toMatchObject({ + queryType: 'Branches', + owner: 'grafana', + repository: 'github-datasource', + options: { query: 'release/' }, + }); + await expect( + page.getByRole('gridcell', { name: 'release/2.9' }).or(page.getByRole('cell', { name: 'release/2.9' })) + ).toBeVisible(); +}); diff --git a/tests/VariableQueryEditor.spec.ts b/tests/VariableQueryEditor.spec.ts new file mode 100644 index 00000000..0b0b453a --- /dev/null +++ b/tests/VariableQueryEditor.spec.ts @@ -0,0 +1,38 @@ +import { test, expect } from '@grafana/plugin-e2e'; +import { components } from '../src/components/selectors'; +import { githubVariableResponse } from './mocks/github-response'; + +const type = 'grafana-github-datasource'; +let datasourceName = ''; + +test.beforeAll(async ({ createDataSource }) => { + const datasource = await createDataSource({ type }); + datasourceName = datasource.name; +}); + +test('Variable query editor renders values from a GitHub query', async ({ variableEditPage, page }) => { + await variableEditPage.mockQueryDataResponse(githubVariableResponse); + await variableEditPage.setVariableType('Query'); + await variableEditPage.datasource.set(datasourceName); + + const queryTypeContainer = variableEditPage.getByGrafanaSelector( + components.QueryEditor.QueryType.container.ariaLabel + ); + await queryTypeContainer.getByRole('combobox').click(); + await page.getByRole('listbox').getByRole('option', { name: 'Releases' }).click(); + await variableEditPage.getByGrafanaSelector(components.QueryEditor.Owner.input).fill('grafana'); + const repositoryInput = variableEditPage.getByGrafanaSelector(components.QueryEditor.Repository.input); + await repositoryInput.fill('github-datasource'); + await repositoryInput.blur(); + + const queryDataRequest = variableEditPage.waitForQueryDataRequest(); + await variableEditPage.runQuery(); + const request = await queryDataRequest; + expect(request.postDataJSON().queries[0]).toMatchObject({ + refId: 'metricFindQuery', + queryType: 'Releases', + owner: 'grafana', + repository: 'github-datasource', + }); + await expect(variableEditPage).toDisplayPreviews(['grafana-github-datasource v1.5.7']); +}); diff --git a/tests/mocks/github-response.ts b/tests/mocks/github-response.ts index d55c6e7c..4d5b2ccf 100644 --- a/tests/mocks/github-response.ts +++ b/tests/mocks/github-response.ts @@ -84,3 +84,46 @@ export const githubResponse = { }, }, }; + +export const githubVariableResponse = { + results: { + metricFindQuery: { + ...githubResponse.results.A, + frames: githubResponse.results.A.frames.map((frame) => ({ + ...frame, + schema: { + ...frame.schema, + refId: 'metricFindQuery', + }, + })), + }, + }, +}; + +export const githubBranchesResponse = { + results: { + A: { + status: 200, + frames: [ + { + schema: { + name: 'branches', + refId: 'A', + fields: [ + { + name: 'name', + type: 'string', + typeInfo: { + frame: 'string', + }, + }, + ], + }, + data: { + values: [['release/2.9']], + }, + }, + ], + }, + }, +};