Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin E2E: Click on panel menu items #865

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/plugin-e2e/src/e2e-selectors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export type Components = {
status: (status: string) => string;
toggleTableViewPanel: (title: string) => string;
PanelDataErrorMessage: string;
menuItems: (item: string) => string;
menu: (title: string) => string;
};
Visualization: {
Table: {
Expand All @@ -59,6 +61,11 @@ export type Components = {
VizLegend: {
seriesName: (name: string) => string;
};
Drawer: {
General: {
title: (title: string) => string;
};
};
PanelEditor: {
General: {
content: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const versionedComponents = {
PanelDataErrorMessage: {
'10.4.0': 'data-testid Panel data error message',
},
menuItems: { '9.5.0': (item: string) => `data-testid Panel menu item ${item}` },
menu: { '9.5.0': (item: string) => `data-testid Panel menu ${item}` },
},
Visualization: {
Table: {
Expand All @@ -82,6 +84,13 @@ export const versionedComponents = {
[MIN_GRAFANA_VERSION]: (name: string) => `VizLegend series ${name}`,
},
},
Drawer: {
General: {
title: {
[MIN_GRAFANA_VERSION]: (title: string) => `Drawer title ${title}`,
},
},
},
PanelEditor: {
General: {
content: {
Expand Down
27 changes: 27 additions & 0 deletions packages/plugin-e2e/src/models/components/Panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ export class Panel extends GrafanaPage {
return panel.locator('[role="cell"]');
}

/**
* Click on a menu item in the panel menu.
*
* Pass options.parentItem to specify the parent item of the menu item to click.
*/
async clickOnMenuItem(item: string, options?: { parentItem?: string }): Promise<void> {
let panelMenu = this.getByGrafanaSelector(this.ctx.selectors.components.Panels.Panel.menu(''), {
startsWith: true,
root: this.locator,
});
let parentMenuItem = this.getByGrafanaSelector(
this.ctx.selectors.components.Panels.Panel.menuItems(options?.parentItem ?? '')
);
let menuItem = this.getByGrafanaSelector(this.ctx.selectors.components.Panels.Panel.menuItems(item));

// before 9.5.0, there were no proper selectors for the panel menu items
if (semver.lt(this.ctx.grafanaVersion, '9.5.0')) {
panelMenu = this.locator.getByRole('heading');
this.ctx.page.locator(`[aria-label="Panel header item ${options?.parentItem}"]`);
this.ctx.page.locator(`[aria-label="Panel header item ${item}"]`);
}

await panelMenu.click({ force: true });
options?.parentItem && parentMenuItem.hover();
await menuItem.click();
}

/**
* Returns the locator for the panel error (if any)
*/
Expand Down
4 changes: 1 addition & 3 deletions packages/plugin-e2e/src/models/pages/DashboardPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ export class DashboardPage extends GrafanaPage {
* await expect(panel.fieldNames).toContainText(['time', 'temperature']);
*/
getPanelByTitle(title: string): Panel {
let locator = this.getByGrafanaSelector(this.ctx.selectors.components.Panels.Panel.title(title), {
startsWith: true,
});
let locator = this.getByGrafanaSelector(this.ctx.selectors.components.Panels.Panel.title(title));
// in older versions, the panel selector is added to a child element, so we need to go up two levels to get the wrapper
if (semver.lt(this.ctx.grafanaVersion, '9.5.0')) {
locator = locator.locator('..').locator('..');
Expand Down
19 changes: 19 additions & 0 deletions packages/plugin-e2e/tests/as-admin-user/panel/panelMenu.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { test, expect } from '../../../src';

test('click on menu item', async ({ readProvisionedDashboard, gotoDashboardPage, page }) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const dashboardPage = await gotoDashboardPage(dashboard);
const panel = await dashboardPage.getPanelByTitle('Basic table example');
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 dashboardPage = await gotoDashboardPage(dashboard);
const panel = await dashboardPage.getPanelByTitle('Basic table example');
await panel.clickOnMenuItem('Query', { parentItem: 'Inspect' });
await expect(
dashboardPage.getByGrafanaSelector(selectors.components.Drawer.General.title(''), { startsWith: true })
).toBeVisible();
});
Loading