From 21bd94e3fd87868a35cef9de188cb0a6d75a341a Mon Sep 17 00:00:00 2001 From: MGJamJam Date: Tue, 23 Jul 2024 15:16:52 -0300 Subject: [PATCH] add test for config editor --- e2e/configurationEditor.spec.ts | 28 ++++++++++++++++++++++++++++ src/components/ConfigEditor.tsx | 2 ++ 2 files changed, 30 insertions(+) create mode 100644 e2e/configurationEditor.spec.ts diff --git a/e2e/configurationEditor.spec.ts b/e2e/configurationEditor.spec.ts new file mode 100644 index 0000000..2bb4647 --- /dev/null +++ b/e2e/configurationEditor.spec.ts @@ -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({ 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'); +}); diff --git a/src/components/ConfigEditor.tsx b/src/components/ConfigEditor.tsx index 8f12cca..2c1cdfc 100644 --- a/src/components/ConfigEditor.tsx +++ b/src/components/ConfigEditor.tsx @@ -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`} /> @@ -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`} />