Skip to content

Commit

Permalink
update more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sunker committed Dec 20, 2024
1 parent a5573be commit 56a8163
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from '../../../../src';

test('add panel in already existing dashboard', async ({ gotoDashboardPage, readProvisionedDashboard, page }) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const dashboard = await readProvisionedDashboard({ fileName: 'testdatasource.json' });
const dashboardPage = await gotoDashboardPage(dashboard);
await dashboardPage.addPanel();
await expect(page.url()).toContain('editPanel');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,49 @@
import * as semver from 'semver';
import { test, expect } from '../../../../src';

test.describe(
'panel edit page',
{
tag: '@integration',
},
() => {
test('table panel data assertions', async ({ gotoPanelEditPage, readProvisionedDashboard }, testInfo) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const panelEditPage = await gotoPanelEditPage({ dashboard, id: '3' });
await panelEditPage.setVisualization('Table');
await expect(panelEditPage.panel.locator).toBeVisible();
await expect(panelEditPage.panel.data).toContainText(['staging']);
await expect(panelEditPage.panel.fieldNames).toContainText(['time', 'temperature']);
});
test.describe('panel edit page', () => {
test('table panel data assertions', async ({ gotoPanelEditPage, readProvisionedDashboard }, testInfo) => {
const dashboard = await readProvisionedDashboard({ fileName: 'testdatasource.json' });
const panelEditPage = await gotoPanelEditPage({ dashboard, id: '2' });
await expect(panelEditPage.panel.locator).toBeVisible();
await expect(panelEditPage.panel.data).toContainText(['22.2', '70', 'Staging']);
await expect(panelEditPage.panel.fieldNames).toContainText(['time', 'temperature', 'humidity', 'environment']);
});

test('timeseries panel - table view assertions', async ({ readProvisionedDashboard, gotoPanelEditPage }) => {
const dashboard = await readProvisionedDashboard({ fileName: 'google-sheets.json' });
const panelEditPage = await gotoPanelEditPage({ dashboard, id: '1' });
await panelEditPage.setVisualization('Time series');
await panelEditPage.toggleTableView();
await expect(panelEditPage.panel.fieldNames).toContainText(['Stockholm', 'Berlin']);
await expect(panelEditPage.panel.data).toContainText(['-1', '2.90']);
});
}
);
test('timeseries panel - table view assertions', async ({ readProvisionedDashboard, gotoPanelEditPage }) => {
const dashboard = await readProvisionedDashboard({ fileName: 'testdatasource.json' });
const panelEditPage = await gotoPanelEditPage({ dashboard, id: '4' });
await panelEditPage.toggleTableView();
await expect(panelEditPage.panel.fieldNames).toContainText(['time', 'temperature', 'humidity', 'environment']);
await expect(panelEditPage.panel.data).toContainText(['22.2', '70', 'Staging']);
});
});

test.describe('dashboard page', { tag: '@integration' }, () => {
test.describe('dashboard page', () => {
test('getting panel by title', async ({ readProvisionedDashboard, gotoDashboardPage }) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const dashboard = await readProvisionedDashboard({ fileName: 'testdatasource.json' });
const dashboardPage = await gotoDashboardPage(dashboard);
const panel = await dashboardPage.getPanelByTitle('Basic table example');
const panel = await dashboardPage.getPanelByTitle('Single row');
await expect(panel.data).toContainText(['22.2', '70', 'Staging']);
await expect(panel.fieldNames).toContainText(['time', 'temperature', 'humidity', 'environment']);
await expect(panel.data).toContainText(['25', '32', 'staging']);
});

test('getting panel by id', async ({ gotoDashboardPage, readProvisionedDashboard }) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const dashboard = await readProvisionedDashboard({ fileName: 'testdatasource.json' });
const dashboardPage = await gotoDashboardPage(dashboard);
const panel = await dashboardPage.getPanelById('3');
const panel = await dashboardPage.getPanelById('2');
await expect(panel.data).toContainText(['22.2', '70', 'Staging']);
await expect(panel.fieldNames).toContainText(['time', 'temperature', 'humidity', 'environment']);
await expect(panel.data).toContainText(['25', '32', 'staging']);
});
});

test.describe('explore page', () => {
test('table panel', async ({ grafanaVersion, explorePage }) => {
const url = semver.lt('10.0.0', grafanaVersion)
? `panes=%7B"_t4":%7B"datasource":"grafana","queries":%5B%7B"queryType":"randomWalk","refId":"A","datasource":%7B"type":"datasource","uid":"grafana"%7D%7D%5D,"range":%7B"from":"now-6h","to":"now"%7D%7D%7D&orgId=1&left=%7B"datasource":"grafana","queries":%5B%7B"refId":"A","datasource":%7B"type":"datasource","uid":"grafana"%7D,"queryType":"randomWalk"%7D%5D,"range":%7B"from":"now-1h","to":"now"%7D%7D`
: 'left=%7B"datasource":"grafana","queries":%5B%7B"queryType":"randomWalk","refId":"A","datasource":%7B"type":"datasource","uid":"grafana"%7D%7D%5D,"range":%7B"from":"1547161200000","to":"1576364400000"%7D%7D&orgId=1';
const params = semver.lt(grafanaVersion, '10.0.0')
? 'left=%7B"datasource":"grafana","queries":%5B%7B"queryType":"randomWalk","refId":"A","datasource":%7B"type":"datasource","uid":"grafana"%7D%7D%5D,"range":%7B"from":"1547161200000","to":"1576364400000"%7D%7D&orgId=1'
: `panes=%7B"_t4":%7B"datasource":"grafana","queries":%5B%7B"queryType":"randomWalk","refId":"A","datasource":%7B"type":"datasource","uid":"grafana"%7D%7D%5D,"range":%7B"from":"now-6h","to":"now"%7D%7D%7D&orgId=1&left=%7B"datasource":"grafana","queries":%5B%7B"refId":"A","datasource":%7B"type":"datasource","uid":"grafana"%7D,"queryType":"randomWalk"%7D%5D,"range":%7B"from":"now-1h","to":"now"%7D%7D`;

await explorePage.goto({
queryParams: new URLSearchParams(url),
});
await explorePage.goto({ queryParams: new URLSearchParams(params) });

await expect(explorePage.tablePanel.fieldNames).toContainText(['time', 'A-series']);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ test.describe('gotoDashboardPage', () => {
gotoDashboardPage,
readProvisionedDashboard,
}) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const dashboard = await readProvisionedDashboard({ fileName: 'testdatasource.json' });
const dashboardPage = await gotoDashboardPage({ ...dashboard, waitUntil: 'load' });
await expect(dashboardPage.getPanelByTitle('Basic table example').locator).toHaveCount(0);
await expect(dashboardPage.getPanelByTitle('Table data').locator).toHaveCount(0);
});

test('should not display elements when waitUntil `networkidle` (default) is used', async ({
gotoDashboardPage,
readProvisionedDashboard,
}) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const dashboard = await readProvisionedDashboard({ fileName: 'testdatasource.json' });
const dashboardPage = await gotoDashboardPage(dashboard);
await expect(dashboardPage.getPanelByTitle('Basic table example').locator).toBeVisible();
await expect(dashboardPage.getPanelByTitle('Table data').locator).toBeVisible();
});
});

Expand All @@ -26,7 +26,7 @@ test.describe('gotoPanelEditPage', () => {
gotoPanelEditPage,
readProvisionedDashboard,
}) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const dashboard = await readProvisionedDashboard({ fileName: 'testdatasource.json' });
const panelEditPage = await gotoPanelEditPage({ dashboard, id: '3', waitUntil: 'load' });
await expect(panelEditPage.panel.locator).toHaveCount(0);
});
Expand All @@ -35,7 +35,7 @@ test.describe('gotoPanelEditPage', () => {
gotoPanelEditPage,
readProvisionedDashboard,
}) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const dashboard = await readProvisionedDashboard({ fileName: 'testdatasource.json' });
const panelEditPage = await gotoPanelEditPage({ dashboard, id: '3' });
await expect(panelEditPage.panel.locator).toBeVisible();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { test, expect } from '../../../src';

test('click on menu item', async ({ readProvisionedDashboard, gotoDashboardPage, page }) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const dashboard = await readProvisionedDashboard({ fileName: 'testdatasource.json' });
const dashboardPage = await gotoDashboardPage(dashboard);
const panel = await dashboardPage.getPanelByTitle('Basic table example');
const panel = await dashboardPage.getPanelByTitle('Table data');
await panel.clickOnMenuItem('Edit');
await expect(page).toHaveURL(/.*editPanel=.*/);
});

test('click on sub menu item', async ({ readProvisionedDashboard, gotoDashboardPage, page, selectors }) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const dashboard = await readProvisionedDashboard({ fileName: 'testdatasource.json' });
const dashboardPage = await gotoDashboardPage(dashboard);
const panel = await dashboardPage.getPanelByTitle('Basic table example');
const panel = await dashboardPage.getPanelByTitle('Table data');
await panel.clickOnMenuItem('Query', { parentItem: 'Inspect' });
await expect(
dashboardPage.getByGrafanaSelector(selectors.components.Drawer.General.title(''), { startsWith: true })
Expand Down

0 comments on commit 56a8163

Please sign in to comment.