Skip to content

Commit

Permalink
Plugin E2e: Support scenes powered dashboard UI (#1155)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunker authored Oct 2, 2024
1 parent bb55bd3 commit dbffb7a
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/plugin-e2e/src/e2e-selectors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ export type Components = {
Alert: {
alertV2: (severity: string) => string;
};
NavToolbar: {
editDashboard: {
backToDashboardButton: string;
editButton: string;
};
};
PageToolbar: {
item: (tooltip: string) => string;
showMoreItems: string;
Expand Down
10 changes: 10 additions & 0 deletions packages/plugin-e2e/src/e2e-selectors/versioned/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ export const versionedComponents = {
[MIN_GRAFANA_VERSION]: (severity: string) => `Alert ${severity}`,
},
},
NavToolbar: {
editDashboard: {
editButton: {
'11.1.0': 'data-testid Edit dashboard button',
},
backToDashboardButton: {
'11.1.0': 'data-testid Back to dashboard button',
},
},
},
PageToolbar: {
item: {
[MIN_GRAFANA_VERSION]: (tooltip: string) => `${tooltip}`,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-e2e/src/e2e-selectors/versioned/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const versionedPages = {
'9.5.0': (title: string) => `data-testid ${title}`,
},
addNewPanel: {
'11.1.0': 'data-testid Add new panel',
[MIN_GRAFANA_VERSION]: 'Add new panel',
},
itemButtonAddViz: {
Expand Down Expand Up @@ -70,8 +71,7 @@ export const versionedPages = {
url: {
[MIN_GRAFANA_VERSION]: (variableIndex: string) =>
`/dashboard/new?orgId=1&editview=templating&editIndex=${variableIndex}`,
'11.3.0': (variableIndex: string) =>
`/dashboard/new?orgId=1&editview=variables&editIndex=${variableIndex}`,
'11.3.0': (variableIndex: string) => `/dashboard/new?orgId=1&editview=variables&editIndex=${variableIndex}`,
},
},
},
Expand Down
9 changes: 9 additions & 0 deletions packages/plugin-e2e/src/models/pages/DashboardPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,21 @@ export class DashboardPage extends GrafanaPage {
*/
async addPanel(): Promise<PanelEditPage> {
const { components, pages } = this.ctx.selectors;

// From Grafana 11.3.0, one needs to click the edit button before adding a new panel in already existing dashboards
if (semver.gte(this.ctx.grafanaVersion, '11.3.0') && this.dashboard?.uid) {
await this.getByGrafanaSelector(components.NavToolbar.editDashboard.editButton).click();
}

if (semver.gte(this.ctx.grafanaVersion, '10.0.0')) {
await this.getByGrafanaSelector(
components.PageToolbar.itemButton(components.PageToolbar.itemButtonTitle)
).click();
await this.getByGrafanaSelector(pages.AddDashboard.itemButton(pages.AddDashboard.itemButtonAddViz)).click();
} else {
if (this.dashboard?.uid) {
await this.getByGrafanaSelector(components.PageToolbar.item('Add panel')).click();
}
await this.getByGrafanaSelector(pages.AddDashboard.addNewPanel).click();
}

Expand Down
23 changes: 22 additions & 1 deletion packages/plugin-e2e/src/models/pages/PanelEditPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { GrafanaPage } from './GrafanaPage';
import { TimeRange } from '../components/TimeRange';
import { Panel } from '../components/Panel';
import { radioButtonSetChecked } from '../utils';
import { DashboardPage } from './DashboardPage';

export class PanelEditPage extends GrafanaPage {
datasource: DataSourcePicker;
Expand Down Expand Up @@ -116,11 +117,31 @@ export class PanelEditPage extends GrafanaPage {
return this.getByGrafanaSelector(this.ctx.selectors.components.PanelEditor.toggleVizPicker);
}

/**
* Clicks the "Back to dashboard" button in the panel editor
* In versions prior to 11.3.0, this method clicks the "Apply" button instead
*/
async backToDashboard() {
if (semver.gte(this.ctx.grafanaVersion, '11.3.0')) {
await this.getByGrafanaSelector(
this.ctx.selectors.components.NavToolbar.editDashboard.backToDashboardButton
).click();
} else if (semver.gte(this.ctx.grafanaVersion, '9.0.0')) {
await this.ctx.page.getByTestId(this.ctx.selectors.components.PanelEditor.applyButton).click();
} else {
await this.ctx.page.getByLabel('panel editor apply').click();
}

return new DashboardPage(this.ctx, this.args);
}

/**
* Clicks the "Apply" button in the panel editor
*
* @deprecated use {@link PanelEditPage.backToDashboard} method instead.
*/
async apply() {
await this.ctx.page.getByTestId(this.ctx.selectors.components.PanelEditor.applyButton).click();
return this.backToDashboard();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect, test } from '../../../../src';

test('add panel in already existing dashboard', async ({ gotoDashboardPage, readProvisionedDashboard, page }) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const dashboardPage = await gotoDashboardPage(dashboard);
await dashboardPage.addPanel();
await expect(page.url()).toContain('editPanel');
});

test('add panel in new dashboard', async ({ dashboardPage, page }) => {
const panelEditPage = await dashboardPage.addPanel();
await expect(panelEditPage.panel.locator).toBeVisible();
await expect(page.url()).toContain('editPanel');
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,14 @@ test('should set correct cache time on query passed to the backend', async ({
await panelEditPage.refreshPanel();
await expect(await queryReq).toBeTruthy();
});

test('backToDashboard method should be backwards compatible and navigate to dashboard page', async ({
gotoPanelEditPage,
readProvisionedDashboard,
page,
}) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const panelEditPage = await gotoPanelEditPage({ dashboard, id: '3' });
await panelEditPage.backToDashboard();
await expect(page.url()).not.toContain('editPanel');
});

0 comments on commit dbffb7a

Please sign in to comment.