@grafana/plugin-e2e 0.0.2 → 0.0.3-canary.610.b925ceb.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.
package/dist/api.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { E2ESelectors } from './e2e-selectors/types';
2
2
  import { CreateDataSourceArgs, CreateDataSourcePageArgs, DataSource, ReadProvisionArgs } from './types';
3
- import { PanelEditPage, DataSourceConfigPage, DashboardPage, VariableEditPage, AnnotationEditPage } from './models';
3
+ import { PanelEditPage, GrafanaPage, DataSourceConfigPage, DashboardPage, VariableEditPage, AnnotationEditPage } from './models';
4
4
  import { ExplorePage } from './models/ExplorePage';
5
5
  export type PluginOptions = {
6
6
  selectorRegistration: void;
@@ -37,5 +37,9 @@ export declare const expect: import("@playwright/test").Expect<{
37
37
  actual: boolean;
38
38
  message: () => string;
39
39
  }>;
40
+ toHaveAlert: (grafanaPage: GrafanaPage, severity: import("./matchers/toHaveAlert").AlertVariant, options?: import("./types").AlertPageOptions) => Promise<{
41
+ message: () => any;
42
+ pass: boolean;
43
+ }>;
40
44
  }>;
41
45
  export { selectors } from '@playwright/test';
@@ -10,7 +10,7 @@ export type APIs = {
10
10
  queryPattern: string;
11
11
  query: string;
12
12
  health: (uid: string, id: string) => string;
13
- delete: (uid: string) => string;
13
+ datasourceByUID: (uid: string) => string;
14
14
  };
15
15
  Dashboard: {
16
16
  delete: (uid: string) => string;
@@ -190,7 +190,10 @@ export type Components = {
190
190
  AlertTab: {
191
191
  content: string;
192
192
  };
193
- Alert: {};
193
+ Alert: {
194
+ alert: (severity: string) => string;
195
+ alertV2: (severity: string) => string;
196
+ };
194
197
  TransformTab: {
195
198
  content: string;
196
199
  };
@@ -17,7 +17,7 @@ export declare const versionedAPIs: {
17
17
  "9.5.0": (uid: string, _: string) => string;
18
18
  "8.0.0": (_: string, id: string) => string;
19
19
  };
20
- delete: {
20
+ datasourceByUID: {
21
21
  "8.0.0": (uid: string) => string;
22
22
  };
23
23
  };
@@ -21,7 +21,7 @@ exports.versionedAPIs = {
21
21
  ['9.5.0']: (uid, _) => `/api/datasources/uid/${uid}/health`,
22
22
  [constants_1.MIN_GRAFANA_VERSION]: (_, id) => `/api/datasources/${id}/health`,
23
23
  },
24
- delete: {
24
+ datasourceByUID: {
25
25
  [constants_1.MIN_GRAFANA_VERSION]: (uid) => `/api/datasources/uid/${uid}`,
26
26
  },
27
27
  },
@@ -16,5 +16,9 @@ declare const _default: {
16
16
  actual: boolean;
17
17
  message: () => string;
18
18
  }>;
19
+ toHaveAlert: (grafanaPage: import("../models").GrafanaPage, severity: import("./toHaveAlert").AlertVariant, options?: import("../types").AlertPageOptions) => Promise<{
20
+ message: () => any;
21
+ pass: boolean;
22
+ }>;
19
23
  };
20
24
  export default _default;
@@ -6,8 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const toBeOK_1 = __importDefault(require("./toBeOK"));
7
7
  const toHavePanelError_1 = __importDefault(require("./toHavePanelError"));
8
8
  const toDisplayPreviews_1 = __importDefault(require("./toDisplayPreviews"));
9
+ const toHaveAlert_1 = __importDefault(require("./toHaveAlert"));
9
10
  exports.default = {
10
11
  toBeOK: toBeOK_1.default,
11
12
  toHavePanelError: toHavePanelError_1.default,
12
13
  toDisplayPreviews: toDisplayPreviews_1.default,
14
+ toHaveAlert: toHaveAlert_1.default,
13
15
  };
@@ -0,0 +1,8 @@
1
+ import { GrafanaPage } from '../models';
2
+ import { AlertPageOptions } from '../types';
3
+ export type AlertVariant = 'success' | 'warning' | 'error' | 'info';
4
+ declare const toHaveAlert: (grafanaPage: GrafanaPage, severity: AlertVariant, options?: AlertPageOptions) => Promise<{
5
+ message: () => any;
6
+ pass: boolean;
7
+ }>;
8
+ export default toHaveAlert;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const test_1 = require("@playwright/test");
4
+ const utils_1 = require("./utils");
5
+ const toHaveAlert = async (grafanaPage, severity, options) => {
6
+ let pass = true;
7
+ let message = `An alert of variant ${severity} to be displayed on the page`;
8
+ try {
9
+ const filteredAlerts = grafanaPage
10
+ .getByTestIdOrAriaLabel(grafanaPage.ctx.selectors.components.Alert.alertV2(severity))
11
+ .filter({
12
+ hasText: options?.hasText,
13
+ hasNotText: options?.hasNotText,
14
+ has: options?.has,
15
+ hasNot: options?.hasNot,
16
+ });
17
+ await (0, test_1.expect)(filteredAlerts.first()).toBeVisible({ timeout: options?.timeout });
18
+ }
19
+ catch (err) {
20
+ message = (0, utils_1.getMessage)(message, `No alert was found on the page: ${err instanceof Error ? err.toString() : ''}`);
21
+ pass = false;
22
+ }
23
+ return {
24
+ message: () => message,
25
+ pass,
26
+ };
27
+ };
28
+ exports.default = toHaveAlert;
@@ -1,4 +1,4 @@
1
- import { DataSource, PluginTestCtx } from '../types';
1
+ import { DataSource, PluginTestCtx, TriggerQueryOptions } from '../types';
2
2
  import { GrafanaPage } from './GrafanaPage';
3
3
  export declare class DataSourceConfigPage extends GrafanaPage {
4
4
  private datasource;
@@ -6,5 +6,5 @@ export declare class DataSourceConfigPage extends GrafanaPage {
6
6
  deleteDataSource(): Promise<void>;
7
7
  goto(): Promise<void>;
8
8
  mockHealthCheckResponse<T = any>(json: T, status?: number): Promise<void>;
9
- saveAndTest(): Promise<import("playwright-core").Response>;
9
+ saveAndTest(options?: TriggerQueryOptions): Promise<void | import("playwright-core").Response>;
10
10
  }
@@ -9,7 +9,7 @@ class DataSourceConfigPage extends GrafanaPage_1.GrafanaPage {
9
9
  this.datasource = datasource;
10
10
  }
11
11
  async deleteDataSource() {
12
- await this.ctx.request.delete(this.ctx.selectors.apis.DataSource.delete(this.datasource.uid));
12
+ await this.ctx.request.delete(this.ctx.selectors.apis.DataSource.datasourceByUID(this.datasource.uid));
13
13
  }
14
14
  async goto() {
15
15
  await this.ctx.page.goto(this.ctx.selectors.pages.EditDataSource.url(this.datasource.uid), {
@@ -17,16 +17,20 @@ class DataSourceConfigPage extends GrafanaPage_1.GrafanaPage {
17
17
  });
18
18
  }
19
19
  async mockHealthCheckResponse(json, status = 200) {
20
- await this.ctx.page.route(`${this.ctx.selectors.apis.DataSource.health}`, async (route) => {
20
+ await this.ctx.page.route(`${this.ctx.selectors.apis.DataSource.health(this.datasource.uid ?? '', this.datasource.id.toString() ?? '')}`, async (route) => {
21
21
  await route.fulfill({ json, status });
22
22
  });
23
23
  }
24
- async saveAndTest() {
25
- const responsePromise = this.ctx.page.waitForResponse((resp) => resp
24
+ async saveAndTest(options) {
25
+ if (options?.skipWaitForResponse) {
26
+ return this.getByTestIdOrAriaLabel(this.ctx.selectors.pages.DataSource.saveAndTest).click();
27
+ }
28
+ const saveResponsePromise = this.ctx.page.waitForResponse((resp) => resp.url().includes(this.ctx.selectors.apis.DataSource.datasourceByUID(this.datasource.uid)));
29
+ const healthResponsePromise = this.ctx.page.waitForResponse((resp) => resp
26
30
  .url()
27
31
  .includes(this.ctx.selectors.apis.DataSource.health(this.datasource.uid ?? '', this.datasource.id.toString() ?? '')));
28
32
  await this.getByTestIdOrAriaLabel(this.ctx.selectors.pages.DataSource.saveAndTest).click();
29
- return responsePromise;
33
+ return saveResponsePromise.then(() => healthResponsePromise);
30
34
  }
31
35
  }
32
36
  exports.DataSourceConfigPage = DataSourceConfigPage;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PlaywrightTestArgs } from '@playwright/test';
1
+ import { Locator, PlaywrightTestArgs } from '@playwright/test';
2
2
  import { E2ESelectors } from './e2e-selectors/types';
3
3
  export type PluginTestCtx = {
4
4
  grafanaVersion: string;
@@ -51,4 +51,15 @@ export type NavigateOptions = {
51
51
  waitUntil?: 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
52
52
  queryParams?: URLSearchParams;
53
53
  };
54
+ export type TriggerQueryOptions = {
55
+ skipWaitForResponse: boolean;
56
+ };
54
57
  export type Visualization = 'Alert list' | 'Bar gauge' | 'Clock' | 'Dashboard list' | 'Gauge' | 'Graph' | 'Heatmap' | 'Logs' | 'News' | 'Pie Chart' | 'Plugin list' | 'Polystat' | 'Stat' | 'Table' | 'Text' | 'Time series' | 'Worldmap Panel';
58
+ export type AlertVariant = 'success' | 'warning' | 'error' | 'info';
59
+ export interface AlertPageOptions {
60
+ timeout?: number;
61
+ has?: Locator;
62
+ hasNot?: Locator;
63
+ hasNotText?: string | RegExp;
64
+ hasText?: string | RegExp;
65
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/plugin-e2e",
3
- "version": "0.0.2",
3
+ "version": "0.0.3-canary.610.b925ceb.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -44,5 +44,5 @@
44
44
  "semver": "^7.5.4",
45
45
  "uuid": "^9.0.1"
46
46
  },
47
- "gitHead": "6ae82da1ba012e5741ec16077ddc0b0ec19f3d03"
47
+ "gitHead": "b925cebc8843c7fe06312fa52f3dfcc9b38ae475"
48
48
  }