Skip to content

Commit

Permalink
add test for config editor
Browse files Browse the repository at this point in the history
  • Loading branch information
MGJamJam committed Jul 23, 2024
1 parent 9e47d6b commit 21bd94e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions e2e/configurationEditor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { test, expect } from '@grafana/plugin-e2e';
import { BitmovinDataSourceOptions } from '../src/types/grafanaTypes';

test('"Save & test" should be successful when configuration is valid', async ({
createDataSourceConfigPage,
readProvisionedDataSource,
page,
selectors,
}) => {
await page.route('*/**/analytics/licenses', async (route) => {
await route.fulfill({ status: 200, body: 'OK' });
});
const ds = await readProvisionedDataSource<BitmovinDataSourceOptions>({ fileName: 'datasources.yml' });
const configPage = await createDataSourceConfigPage({ type: ds.type });

await page.locator(`#config-editor-${configPage.datasource.name}_api-key-input`).fill('test-api-key');
await page.locator(`#config-editor-${configPage.datasource.name}_tenant-org-id-input`).fill('test-tenant-org-id');

const queryPromise = page.waitForRequest('*/**/analytics/licenses');
await configPage.getByGrafanaSelector(selectors.pages.DataSource.saveAndTest).click();
const queryRequest = await queryPromise;

expect(queryRequest.headers()['x-api-client']).toBe('analytics-grafana-datasource');
expect(queryRequest.headers()['x-api-key']).toBe('test-api-key');
expect(queryRequest.headers()['x-tenant-org-id']).toBe('test-tenant-org-id');

expect(configPage).toHaveAlert('success');
});
2 changes: 2 additions & 0 deletions src/components/ConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function ConfigEditor(props: Props) {
value={jsonData.apiKey || ''}
placeholder="Analytics API Key"
width={40}
id={`config-editor-${props.options.name}_api-key-input`}
/>
</InlineField>
<InlineField label="Tenant Org Id" labelWidth={26}>
Expand All @@ -67,6 +68,7 @@ export function ConfigEditor(props: Props) {
value={jsonData.tenantOrgId || ''}
placeholder="Tenant Org Id"
width={40}
id={`config-editor-${props.options.name}_tenant-org-id-input`}
/>
</InlineField>
<InlineField label="Ad Analytics" tooltip={'Check if you want to query ads data'} labelWidth={26}>
Expand Down

0 comments on commit 21bd94e

Please sign in to comment.