Skip to content

Commit

Permalink
ensure that playwright tests pass
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
  • Loading branch information
abhizer committed Jan 24, 2025
1 parent 951cd0d commit 3df64f7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 62 deletions.
3 changes: 1 addition & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ services:
GF_DATAPROXY_LOGGING: 1
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS: feldera-feldera-datasource

network_mode: "host"

network_mode: 'host'
# networks:
# default:
# name: opentelemetry-demo
Expand Down
5 changes: 3 additions & 2 deletions provisioning/datasources/datasources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ datasources:
version: 1
editable: true
jsonData:
path: '/resources'
baseUrl: 'http://localhost:8080'
pipeline: 'blah'
secureJsonData:
apiKey: 'api-key'
apiKey: ''
22 changes: 11 additions & 11 deletions src/components/QueryEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React from 'react';
import { CodeEditor } from '@grafana/ui';
import { QueryEditorProps } from '@grafana/data';
import { DataSource } from '../datasource';
Expand All @@ -13,15 +13,15 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
};

return (
<CodeEditor
width=""
height="100px"
language="sql"
value={query.queryText ?? ''}
onSave={onQueryTextChange}
onBlur={onQueryTextChange}
showMiniMap={false}
showLineNumbers={true}
/>
<CodeEditor
width=""
height="100px"
language="sql"
value={query.queryText ?? ''}
onSave={onQueryTextChange}
onBlur={onQueryTextChange}
showMiniMap={false}
showLineNumbers={true}
/>
);
}
28 changes: 3 additions & 25 deletions tests/configEditor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
import { test, expect } from '@grafana/plugin-e2e';
import { MyDataSourceOptions, MySecureJsonData } from '../src/types';

test('smoke: should render config editor', async ({ createDataSourceConfigPage, readProvisionedDataSource, page }) => {
const ds = await readProvisionedDataSource({ fileName: 'datasources.yml' });
await createDataSourceConfigPage({ type: ds.type });
await expect(page.getByLabel('Path')).toBeVisible();
});
test('"Save & test" should be successful when configuration is valid', async ({
createDataSourceConfigPage,
readProvisionedDataSource,
page,
}) => {
const ds = await readProvisionedDataSource<MyDataSourceOptions, MySecureJsonData>({ fileName: 'datasources.yml' });
const configPage = await createDataSourceConfigPage({ type: ds.type });
await page.getByRole('textbox', { name: 'Path' }).fill(ds.jsonData.path ?? '');
await page.getByRole('textbox', { name: 'API Key' }).fill(ds.secureJsonData?.apiKey ?? '');
await expect(configPage.saveAndTest()).toBeOK();
});

test('"Save & test" should fail when configuration is invalid', async ({
createDataSourceConfigPage,
readProvisionedDataSource,
page,
}) => {
const ds = await readProvisionedDataSource<MyDataSourceOptions, MySecureJsonData>({ fileName: 'datasources.yml' });
const configPage = await createDataSourceConfigPage({ type: ds.type });
await page.getByRole('textbox', { name: 'Path' }).fill(ds.jsonData.path ?? '');
await expect(configPage.saveAndTest()).not.toBeOK();
await expect(configPage).toHaveAlert('error', { hasText: 'API key is missing' });
await expect(page.getByLabel('Base Url')).toBeVisible();
await expect(page.getByLabel('Pipeline')).toBeVisible();
await expect(page.getByLabel('API Key')).toBeVisible();
});
23 changes: 1 addition & 22 deletions tests/queryEditor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,5 @@ import { test, expect } from '@grafana/plugin-e2e';
test('smoke: should render query editor', async ({ panelEditPage, readProvisionedDataSource }) => {
const ds = await readProvisionedDataSource({ fileName: 'datasources.yml' });
await panelEditPage.datasource.set(ds.name);
await expect(panelEditPage.getQueryEditorRow('A').getByRole('textbox', { name: 'Query Text' })).toBeVisible();
});

test('should trigger new query when Constant field is changed', async ({
panelEditPage,
readProvisionedDataSource,
}) => {
const ds = await readProvisionedDataSource({ fileName: 'datasources.yml' });
await panelEditPage.datasource.set(ds.name);
await panelEditPage.getQueryEditorRow('A').getByRole('textbox', { name: 'Query Text' }).fill('test query');
const queryReq = panelEditPage.waitForQueryDataRequest();
await panelEditPage.getQueryEditorRow('A').getByRole('spinbutton').fill('10');
await expect(await queryReq).toBeTruthy();
});

test('data query should return values 10 and 20', async ({ panelEditPage, readProvisionedDataSource }) => {
const ds = await readProvisionedDataSource({ fileName: 'datasources.yml' });
await panelEditPage.datasource.set(ds.name);
await panelEditPage.getQueryEditorRow('A').getByRole('textbox', { name: 'Query Text' }).fill('test query');
await panelEditPage.setVisualization('Table');
await expect(panelEditPage.refreshPanel()).toBeOK();
await expect(panelEditPage.panel.data).toContainText(['10', '20']);
await expect(panelEditPage.getQueryEditorRow('A').getByRole('code', { name: '' })).toBeVisible();
});

0 comments on commit 3df64f7

Please sign in to comment.