Skip to content
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
44 changes: 44 additions & 0 deletions packages/plugin-e2e/src/models/pages/DashboardPage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, it, expect, vi } from 'vitest';
import { DashboardPage } from './DashboardPage';
import { PluginTestCtx } from '../../types';

const NAV_TOOLBAR = 'data-testid Nav toolbar';
const DASHBOARD_CONTROLS = 'data-testid dashboard controls';

/**
* Returns the selector `toolbar` passes to `page.locator`, by standing in a locator factory that
* hands back the selector it was given.
*/
function resolveToolbarSelector(grafanaVersion: string): string {
const ctx = {
page: { locator: vi.fn((selector: string) => selector) },
grafanaVersion,
selectors: {
components: { NavToolbar: { container: NAV_TOOLBAR } },
pages: { Dashboard: { Controls: DASHBOARD_CONTROLS } },
},
} as unknown as PluginTestCtx;

return new DashboardPage(ctx).toolbar as unknown as string;
}

describe('DashboardPage.toolbar', () => {
// Each threshold is the version at which that toolbar became the default, not the version at
// which its selector first existed. Both toolbars shipped behind a feature toggle that stayed
// off by default for two more minor releases, so gating on first availability resolved to an
// element Grafana never renders, and a scoped locator then waited out the whole test timeout.
it.each([
['8.5.27', '.page-toolbar'],
// topnav exists from 9.4.0 but is only default-on from 9.5.0
['9.4.17', '.page-toolbar'],
['9.5.0', `[data-testid="${NAV_TOOLBAR}"]`],
['11.0.11', `[data-testid="${NAV_TOOLBAR}"]`],
// dashboardScene exists from 11.1.0 but is only default-on from 11.3.0
['11.1.13', `[data-testid="${NAV_TOOLBAR}"]`],
['11.2.10', `[data-testid="${NAV_TOOLBAR}"]`],
['11.3.0', `[data-testid="${DASHBOARD_CONTROLS}"]`],
['13.2.0', `[data-testid="${DASHBOARD_CONTROLS}"]`],
])('resolves the toolbar on Grafana %s to %s', (grafanaVersion, expected) => {
expect(resolveToolbarSelector(grafanaVersion)).toBe(expected);
});
});
20 changes: 15 additions & 5 deletions packages/plugin-e2e/src/models/pages/DashboardPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,26 @@ export class DashboardPage extends GrafanaPage {
/**
* Returns a locator for the dashboard toolbar area that contains the time range controls.
*
* - Grafana ≥ 11.1.0: resolves to `Dashboard.Controls` (scenes-based dashboard controls bar)
* - Grafana 9.4.0–11.0.x: resolves to `NavToolbar.container`
* - Grafana < 9.4.0: falls back to `.page-toolbar`
* The thresholds are the versions at which each toolbar became the *default*, not the versions
* at which its selector first existed. Both toolbars shipped behind a feature toggle that was
* still off by default for two minor releases, so gating on first availability resolves to an
* element that Grafana never renders:
*
* - `dashboard controls` is declared from 11.1.0 but belongs to the scenes dashboard, and
* `dashboardScene` is only default-on from 11.3.0.
* - `Nav toolbar` is declared from 9.4.0 but belongs to the top nav, and `topnav` is only
* default-on from 9.5.0 — the same threshold `addPanel` already uses below.
*
* - Grafana ≥ 11.3.0: resolves to `Dashboard.Controls` (scenes-based dashboard controls bar)
* - Grafana 9.5.0–11.2.x: resolves to `NavToolbar.container`
* - Grafana < 9.5.0: falls back to `.page-toolbar`
*/
get toolbar() {
const { components, pages } = this.ctx.selectors;
if (gte(this.ctx.grafanaVersion, '11.1.0')) {
if (gte(this.ctx.grafanaVersion, '11.3.0')) {
return this.getByGrafanaSelector(pages.Dashboard.Controls);
}
return gte(this.ctx.grafanaVersion, '9.4.0')
return gte(this.ctx.grafanaVersion, '9.5.0')
? this.getByGrafanaSelector(components.NavToolbar.container)
: this.ctx.page.locator('.page-toolbar');
}
Expand Down
Loading