Skip to content

Commit

Permalink
simplified the params
Browse files Browse the repository at this point in the history
  • Loading branch information
yesoreyeram committed Jan 18, 2024
1 parent 5f954f4 commit 5db0d7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
26 changes: 13 additions & 13 deletions e2e/query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ import { runQuery } from './query';
test('test type:json source:url', async ({ page, panelEditPage }) => {
await panelEditPage.datasource.set('Infinity');
await panelEditPage.setVisualization('Table');
const queryEditorRow = await panelEditPage.getQueryEditorRow('A');
const options = { page, panelEditPage };

let frames = await runQuery(page, panelEditPage, queryEditorRow, {});
let frames = await runQuery({}, options);
expect(frames.results['A'].frames[0].schema.name).toBe('A');
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe(''); // Ensure the parser type passed correctly
expect(frames.results['A'].frames[0].schema.meta.custom.data[0].country).toBe('USA'); // Ensure schema meta have actual data to be passed to the frontend
await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered

frames = await runQuery(page, panelEditPage, queryEditorRow, { parser: 'backend' });
frames = await runQuery({ parser: 'backend' }, options);
expect(frames.results['A'].frames[0].schema.name).toBe('A');
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('backend'); // Ensure the parser type passed correctly
expect(frames.results['A'].frames[0].data.values[1][0]).toBe('USA'); // Ensure actual data frames being returned
await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered

frames = await runQuery(page, panelEditPage, queryEditorRow, { parser: 'uql' });
frames = await runQuery({ parser: 'uql' }, options);
expect(frames.results['A'].frames[0].schema.name).toBe('A');
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('uql'); // Ensure the parser type passed correctly
expect(frames.results['A'].frames[0].schema.meta.custom.data[0].country).toBe('USA'); // Ensure schema meta have actual data to be passed to the frontend
await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered

frames = await runQuery(page, panelEditPage, queryEditorRow, { parser: 'groq' });
frames = await runQuery({ parser: 'groq' }, options);
expect(frames.results['A'].frames[0].schema.name).toBe('A');
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('groq'); // Ensure the parser type passed correctly
expect(frames.results['A'].frames[0].schema.meta.custom.data[0].country).toBe('USA'); // Ensure schema meta have actual data to be passed to the frontend
Expand All @@ -34,21 +34,21 @@ test('test type:json source:url', async ({ page, panelEditPage }) => {
test('test type:csv source:url', async ({ page, panelEditPage }) => {
await panelEditPage.datasource.set('Infinity');
await panelEditPage.setVisualization('Table');
const queryEditorRow = await panelEditPage.getQueryEditorRow('A');
const options = { page, panelEditPage };

let frames = await runQuery(page, panelEditPage, queryEditorRow, { type: 'csv', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.csv' });
let frames = await runQuery({ type: 'csv', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.csv' }, options);
expect(frames.results['A'].frames[0].schema.name).toBe('A');
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe(''); // Ensure the parser type passed correctly
expect((frames.results['A'].frames[0].schema.meta.custom.data || '').startsWith('name,age,country,occupation,salary')).toBeTruthy(); // Ensure schema meta have actual data to be passed to the frontend
await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered

frames = await runQuery(page, panelEditPage, queryEditorRow, { type: 'csv', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.csv', parser: 'backend' });
frames = await runQuery({ type: 'csv', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.csv', parser: 'backend' }, options);
expect(frames.results['A'].frames[0].schema.name).toBe('A');
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('backend'); // Ensure the parser type passed correctly
expect(frames.results['A'].frames[0].data.values[1][0]).toBe('USA'); // Ensure actual data frames being returned
await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered

frames = await runQuery(page, panelEditPage, queryEditorRow, { type: 'csv', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.csv', parser: 'uql' });
frames = await runQuery({ type: 'csv', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.csv', parser: 'uql' }, options);
expect(frames.results['A'].frames[0].schema.name).toBe('A');
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('uql'); // Ensure the parser type passed correctly
expect((frames.results['A'].frames[0].schema.meta.custom.data || '').startsWith('name,age,country,occupation,salary')).toBeTruthy(); // Ensure schema meta have actual data to be passed to the frontend
Expand All @@ -58,21 +58,21 @@ test('test type:csv source:url', async ({ page, panelEditPage }) => {
test('test type:xml source:url', async ({ page, panelEditPage }) => {
await panelEditPage.datasource.set('Infinity');
await panelEditPage.setVisualization('Table');
const queryEditorRow = await panelEditPage.getQueryEditorRow('A');
const options = { page, panelEditPage };

let frames = await runQuery(page, panelEditPage, queryEditorRow, { type: 'xml', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.xml' });
let frames = await runQuery({ type: 'xml', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.xml' }, options);
expect(frames.results['A'].frames[0].schema.name).toBe('A');
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe(''); // Ensure the parser type passed correctly
expect((frames.results['A'].frames[0].schema.meta.custom.data || '').includes('<name>Leanne Graham</name')).toBeTruthy(); // Ensure schema meta have actual data to be passed to the frontend
// await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered

frames = await runQuery(page, panelEditPage, queryEditorRow, { type: 'xml', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.xml', parser: 'backend' });
frames = await runQuery({ type: 'xml', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.xml', parser: 'backend' }, options);
expect(frames.results['A'].frames[0].schema.name).toBe('A');
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('backend'); // Ensure the parser type passed correctly
expect(frames.results['A'].frames[0].data.values[0][0].includes('Leanne Graham')).toBeTruthy(); // Ensure actual data frames being returned
// await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered

frames = await runQuery(page, panelEditPage, queryEditorRow, { type: 'xml', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.xml', parser: 'uql' });
frames = await runQuery({ type: 'xml', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.xml', parser: 'uql' }, options);
expect(frames.results['A'].frames[0].schema.name).toBe('A');
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('uql'); // Ensure the parser type passed correctly
expect((frames.results['A'].frames[0].schema.meta.custom.data || '').includes('<name>Leanne Graham</name')).toBeTruthy(); // Ensure schema meta have actual data to be passed to the frontend
Expand Down
4 changes: 3 additions & 1 deletion e2e/query.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Page, Locator } from '@playwright/test';
import { PanelEditPage, expect } from '@grafana/plugin-e2e';

export const runQuery = async (page: Page, panelEditPage: PanelEditPage, locator: Locator, query: Record<string, any>) => {
export const runQuery = async (query: Record<string, any>, options: { page: Page; panelEditPage: PanelEditPage }) => {
const { page, panelEditPage } = options;
const locator = await panelEditPage.getQueryEditorRow('A');
if (query.type) {
const typeDropdown = await locator.locator(`[data-testid='infinity-query-field-wrapper-type'] input`);
await typeDropdown.clear();
Expand Down

0 comments on commit 5db0d7a

Please sign in to comment.