@grafana/plugin-e2e 1.1.1 → 1.2.0-canary.779.b3ed39b.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,9 @@ export type E2ESelectors = {
4
4
  apis: APIs;
5
5
  };
6
6
  export type APIs = {
7
+ Alerting: {
8
+ eval: string;
9
+ };
7
10
  DataSource: {
8
11
  resourcePattern: string;
9
12
  resourceUIDPattern: string;
@@ -130,6 +133,14 @@ export type Pages = {
130
133
  Home: {
131
134
  url: string;
132
135
  };
136
+ Alerting: {
137
+ AddAlertRule: {
138
+ url: string;
139
+ };
140
+ EditAlertRule: {
141
+ url: (alertRuleUid: string) => string;
142
+ };
143
+ };
133
144
  DataSource: {
134
145
  name: string;
135
146
  delete: string;
@@ -1,4 +1,9 @@
1
1
  export declare const versionedAPIs: {
2
+ Alerting: {
3
+ eval: {
4
+ "8.0.0": string;
5
+ };
6
+ };
2
7
  DataSource: {
3
8
  resourcePattern: {
4
9
  "8.0.0": string;
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.versionedAPIs = void 0;
4
4
  const constants_1 = require("./constants");
5
5
  exports.versionedAPIs = {
6
+ Alerting: {
7
+ eval: {
8
+ [constants_1.MIN_GRAFANA_VERSION]: '/api/v1/eval',
9
+ },
10
+ },
6
11
  DataSource: {
7
12
  resourcePattern: {
8
13
  [constants_1.MIN_GRAFANA_VERSION]: '/api/datasources/*/resources',
@@ -4,6 +4,19 @@ export declare const versionedPages: {
4
4
  "8.0.0": string;
5
5
  };
6
6
  };
7
+ Alerting: {
8
+ AddAlertRule: {
9
+ url: {
10
+ "10.0.0": string;
11
+ "8.0.0": string;
12
+ };
13
+ };
14
+ EditAlertRule: {
15
+ url: {
16
+ "8.0.0": (alertRuleUid: string) => string;
17
+ };
18
+ };
19
+ };
7
20
  DataSource: {
8
21
  saveAndTest: {
9
22
  '10.0.0': string;
@@ -8,6 +8,19 @@ exports.versionedPages = {
8
8
  [constants_1.MIN_GRAFANA_VERSION]: '/',
9
9
  },
10
10
  },
11
+ Alerting: {
12
+ AddAlertRule: {
13
+ url: {
14
+ ['10.0.0']: '/alerting/new/alerting',
15
+ [constants_1.MIN_GRAFANA_VERSION]: '/alerting/new',
16
+ },
17
+ },
18
+ EditAlertRule: {
19
+ url: {
20
+ [constants_1.MIN_GRAFANA_VERSION]: (alertRuleUid) => `alerting/${alertRuleUid}/edit`,
21
+ },
22
+ },
23
+ },
11
24
  DataSource: {
12
25
  saveAndTest: {
13
26
  '10.0.0': 'data-testid Data source settings page Save and Test button',
@@ -0,0 +1,6 @@
1
+ import { TestFixture } from '@playwright/test';
2
+ import { AlertRuleEditPage } from '../models/pages/AlertRuleEditPage';
3
+ import { PlaywrightArgs } from '../types';
4
+ type AlertRuleEditPageFixture = TestFixture<AlertRuleEditPage, PlaywrightArgs>;
5
+ export declare const alertRuleEditPage: AlertRuleEditPageFixture;
6
+ export {};
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.alertRuleEditPage = void 0;
4
+ const AlertRuleEditPage_1 = require("../models/pages/AlertRuleEditPage");
5
+ const alertRuleEditPage = async ({ page, selectors, grafanaVersion, request }, use, testInfo) => {
6
+ const alertRuleEditPage = new AlertRuleEditPage_1.AlertRuleEditPage({ page, selectors, grafanaVersion, request, testInfo });
7
+ await alertRuleEditPage.goto();
8
+ await use(alertRuleEditPage);
9
+ };
10
+ exports.alertRuleEditPage = alertRuleEditPage;
@@ -0,0 +1,6 @@
1
+ import { TestFixture } from '@playwright/test';
2
+ import { AlertRuleArgs, PlaywrightArgs } from '../../types';
3
+ import { AlertRuleEditPage } from '../../models/pages/AlertRuleEditPage';
4
+ type GotoAlertRuleEditPageFixture = TestFixture<(args: AlertRuleArgs) => Promise<AlertRuleEditPage>, PlaywrightArgs>;
5
+ export declare const gotoAlertRuleEditPage: GotoAlertRuleEditPageFixture;
6
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gotoAlertRuleEditPage = void 0;
4
+ const AlertRuleEditPage_1 = require("../../models/pages/AlertRuleEditPage");
5
+ const gotoAlertRuleEditPage = async ({ request, page, selectors, grafanaVersion }, use, testInfo) => {
6
+ await use(async (args) => {
7
+ const alertRuleEditPage = new AlertRuleEditPage_1.AlertRuleEditPage({ page, selectors, grafanaVersion, request, testInfo }, args);
8
+ await alertRuleEditPage.goto();
9
+ return alertRuleEditPage;
10
+ });
11
+ };
12
+ exports.gotoAlertRuleEditPage = gotoAlertRuleEditPage;
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ const gotoAppPage_1 = require("./fixtures/commands/gotoAppPage");
26
26
  const gotoDashboardPage_1 = require("./fixtures/commands/gotoDashboardPage");
27
27
  const gotoDataSourceConfigPage_1 = require("./fixtures/commands/gotoDataSourceConfigPage");
28
28
  const gotoPanelEditPage_1 = require("./fixtures/commands/gotoPanelEditPage");
29
+ const gotoAlertRuleEditPage_1 = require("./fixtures/commands/gotoAlertRuleEditPage");
29
30
  const gotoVariableEditPage_1 = require("./fixtures/commands/gotoVariableEditPage");
30
31
  const login_1 = require("./fixtures/commands/login");
31
32
  const readProvisionedDashboard_1 = require("./fixtures/commands/readProvisionedDashboard");
@@ -38,6 +39,7 @@ const page_1 = require("./fixtures/page");
38
39
  const panelEditPage_1 = require("./fixtures/panelEditPage");
39
40
  const selectors_1 = require("./fixtures/selectors");
40
41
  const variableEditPage_1 = require("./fixtures/variableEditPage");
42
+ const alertRuleEditPage_1 = require("./fixtures/alertRuleEditPage");
41
43
  const options_1 = require("./options");
42
44
  const toHaveAlert_1 = require("./matchers/toHaveAlert");
43
45
  const toDisplayPreviews_1 = require("./matchers/toDisplayPreviews");
@@ -87,6 +89,7 @@ exports.test = test_1.test.extend({
87
89
  panelEditPage: panelEditPage_1.panelEditPage,
88
90
  variableEditPage: variableEditPage_1.variableEditPage,
89
91
  annotationEditPage: annotationEditPage_1.annotationEditPage,
92
+ alertRuleEditPage: alertRuleEditPage_1.alertRuleEditPage,
90
93
  explorePage: explorePage_1.explorePage,
91
94
  createDataSource: createDataSource_1.createDataSource,
92
95
  readProvisionedDataSource: readProvisionedDataSource_1.readProvisionedDataSource,
@@ -97,6 +100,7 @@ exports.test = test_1.test.extend({
97
100
  gotoPanelEditPage: gotoPanelEditPage_1.gotoPanelEditPage,
98
101
  gotoVariableEditPage: gotoVariableEditPage_1.gotoVariableEditPage,
99
102
  gotoAnnotationEditPage: gotoAnnotationEditPage_1.gotoAnnotationEditPage,
103
+ gotoAlertRuleEditPage: gotoAlertRuleEditPage_1.gotoAlertRuleEditPage,
100
104
  gotoDataSourceConfigPage: gotoDataSourceConfigPage_1.gotoDataSourceConfigPage,
101
105
  gotoAppConfigPage: gotoAppConfigPage_1.gotoAppConfigPage,
102
106
  gotoAppPage: gotoAppPage_1.gotoAppPage,
@@ -0,0 +1,11 @@
1
+ import { DataSourcePicker } from './DataSourcePicker';
2
+ import { getByGrafanaSelectorOptions, PluginTestCtx } from '../../types';
3
+ import { GrafanaPage } from '../pages/GrafanaPage';
4
+ import { Locator } from '@playwright/test';
5
+ export declare class AlertRuleQuery extends GrafanaPage {
6
+ readonly ctx: PluginTestCtx;
7
+ readonly locator: Locator;
8
+ datasource: DataSourcePicker;
9
+ constructor(ctx: PluginTestCtx, locator: Locator);
10
+ getByGrafanaSelector(selector: string, options?: getByGrafanaSelectorOptions): Locator;
11
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AlertRuleQuery = void 0;
4
+ const DataSourcePicker_1 = require("./DataSourcePicker");
5
+ const GrafanaPage_1 = require("../pages/GrafanaPage");
6
+ class AlertRuleQuery extends GrafanaPage_1.GrafanaPage {
7
+ ctx;
8
+ locator;
9
+ datasource;
10
+ constructor(ctx, locator) {
11
+ super(ctx);
12
+ this.ctx = ctx;
13
+ this.locator = locator;
14
+ this.datasource = new DataSourcePicker_1.DataSourcePicker(ctx);
15
+ }
16
+ getByGrafanaSelector(selector, options = {}) {
17
+ return super.getByGrafanaSelector(selector, {
18
+ root: this.locator,
19
+ ...options,
20
+ });
21
+ }
22
+ }
23
+ exports.AlertRuleQuery = AlertRuleQuery;
@@ -0,0 +1,14 @@
1
+ import { AlertRuleArgs, NavigateOptions, PluginTestCtx, RequestOptions } from '../../types';
2
+ import { GrafanaPage } from './GrafanaPage';
3
+ import { AlertRuleQuery } from '../components/AlertRuleQuery';
4
+ export declare class AlertRuleEditPage extends GrafanaPage {
5
+ readonly ctx: PluginTestCtx;
6
+ readonly args?: AlertRuleArgs | undefined;
7
+ constructor(ctx: PluginTestCtx, args?: AlertRuleArgs | undefined);
8
+ /**
9
+ * Navigates to the annotation edit page. If a dashboard uid was not provided, it's assumed that it's a new dashboard.
10
+ */
11
+ goto(options?: NavigateOptions): Promise<void>;
12
+ getAlertRuleQueryRow(refId: string): AlertRuleQuery;
13
+ evaluate(options?: RequestOptions): Promise<import("playwright-core").Response>;
14
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.AlertRuleEditPage = void 0;
27
+ const semver = __importStar(require("semver"));
28
+ const GrafanaPage_1 = require("./GrafanaPage");
29
+ const AlertRuleQuery_1 = require("../components/AlertRuleQuery");
30
+ class AlertRuleEditPage extends GrafanaPage_1.GrafanaPage {
31
+ ctx;
32
+ args;
33
+ constructor(ctx, args) {
34
+ super(ctx);
35
+ this.ctx = ctx;
36
+ this.args = args;
37
+ }
38
+ /**
39
+ * Navigates to the annotation edit page. If a dashboard uid was not provided, it's assumed that it's a new dashboard.
40
+ */
41
+ async goto(options) {
42
+ const { AddAlertRule, EditAlertRule } = this.ctx.selectors.pages.Alerting;
43
+ const url = this.args?.uid ? EditAlertRule.url(this.args.uid) : AddAlertRule.url;
44
+ return super.navigate(url, options);
45
+ }
46
+ getAlertRuleQueryRow(refId) {
47
+ const locator = this.getByGrafanaSelector(this.ctx.selectors.components.QueryEditorRows.rows).filter({
48
+ has: this.getByGrafanaSelector(this.ctx.selectors.components.QueryEditorRow.title(refId)),
49
+ });
50
+ return new AlertRuleQuery_1.AlertRuleQuery(this.ctx, locator);
51
+ }
52
+ async evaluate(options) {
53
+ if (semver.gte(this.ctx.grafanaVersion, '10.0.0')) {
54
+ this.ctx.page.route(this.ctx.selectors.apis.Alerting.eval, async (route) => {
55
+ const response = await route.fetch();
56
+ let body = await response.json();
57
+ const statuses = Object.keys(body.results).map((key) => body.results[key].status);
58
+ route.fulfill({
59
+ response,
60
+ status: statuses.every((status) => status >= 200 && status < 300) ? 200 : statuses[0],
61
+ });
62
+ });
63
+ }
64
+ const responsePromise = this.ctx.page.waitForResponse((resp) => resp.url().includes(this.ctx.selectors.apis.Alerting.eval), options);
65
+ await this.ctx.page.getByRole('button', { name: 'Preview', exact: true }).click();
66
+ return responsePromise;
67
+ }
68
+ }
69
+ exports.AlertRuleEditPage = AlertRuleEditPage;
package/dist/types.d.ts CHANGED
@@ -8,6 +8,7 @@ import { DataSourceConfigPage } from './models/pages/DataSourceConfigPage';
8
8
  import { ExplorePage } from './models/pages/ExplorePage';
9
9
  import { PanelEditPage } from './models/pages/PanelEditPage';
10
10
  import { VariableEditPage } from './models/pages/VariableEditPage';
11
+ import { AlertRuleEditPage } from './models/pages/AlertRuleEditPage';
11
12
  export type PluginOptions = {
12
13
  /**
13
14
  * When using the readProvisioning fixture, files will be read from this directory. If no directory is provided,
@@ -96,6 +97,13 @@ export type PluginFixture = {
96
97
  * To load an existing dashboard with an existing annotation, use the {@link gotoAnnotationEditPage} fixture.
97
98
  */
98
99
  annotationEditPage: AnnotationEditPage;
100
+ /**
101
+ * Isolated {@link AlertRuleEditPage} instance for each test.
102
+ *
103
+ * When using this fixture in a test, you will get an empty alert rule page form
104
+ * To load an existing alert rule, use the {@link gotoAlertRulePage} fixture.
105
+ */
106
+ alertRuleEditPage: AlertRuleEditPage;
99
107
  /**
100
108
  * Isolated {@link ExplorePage} instance for each test.
101
109
  */
@@ -211,6 +219,10 @@ export type PluginFixture = {
211
219
  * Fixture command that navigates an annotation edit page for an already existing annotation query in a dashboard.
212
220
  */
213
221
  gotoAnnotationEditPage: (args: DashboardEditViewArgs<string>) => Promise<AnnotationEditPage>;
222
+ /**
223
+ * Fixture command that navigates to an alert rule edit page for an already existing alert query.
224
+ */
225
+ gotoAlertRuleEditPage: (args: AlertRuleArgs) => Promise<AlertRuleEditPage>;
214
226
  /**
215
227
  * Fixture command that navigates a configuration page for an already existing data source instance.
216
228
  */
@@ -350,6 +362,9 @@ export type DashboardEditViewArgs<T> = {
350
362
  dashboard?: DashboardPageArgs;
351
363
  id: T;
352
364
  };
365
+ export type AlertRuleArgs = {
366
+ uid: string;
367
+ };
353
368
  export type ReadProvisionedDashboardArgs = {
354
369
  /**
355
370
  * The path, relative to the provisioning folder, to the dashboard json file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/plugin-e2e",
3
- "version": "1.1.1",
3
+ "version": "1.2.0-canary.779.b3ed39b.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -55,5 +55,5 @@
55
55
  "start": "cls || clear"
56
56
  }
57
57
  },
58
- "gitHead": "8abe46bc597ff004ad174903ec61a005edd262a3"
58
+ "gitHead": "b3ed39b4063d5ca56412b4014915402dffb94611"
59
59
  }