@grafana/plugin-e2e
Advanced tools
Comparing version 1.17.1 to 1.17.2-canary.1508.08864124983722c.0
@@ -16,8 +16,20 @@ import { AlertRuleArgs, NavigateOptions, PluginTestCtx, RequestOptions } from '../../types'; | ||
get alertRuleNameField(): import("playwright-core").Locator; | ||
get advancedModeSwitch(): import("playwright-core").Locator; | ||
isAdvancedModeSupported(): Promise<boolean>; | ||
enableAdvancedQueryMode(): Promise<void>; | ||
disableAdvancedQueryMode(): Promise<void>; | ||
getQueryRow(refId?: string): Promise<AlertRuleQuery>; | ||
/** | ||
* Returns an instance of the {@link AlertRuleQuery} class for the query row with the provided refId. | ||
* @deprecated Use getQueryRow instead | ||
* Returns an instance of the {@link AlertRuleQuery} class for a query in the query and expression step (step 2) | ||
* | ||
* @param refId is optional. If not provided, it will return query row with refId 'A' in Grafana versions <11.6. | ||
* In Grafana versions >=11.6 where advanced mode is supported, it will return the default query if advanced mode | ||
* is not enabled. If advanced mode is enabled, it will return the a query by refId. | ||
*/ | ||
getAlertRuleQueryRow(refId: string): AlertRuleQuery; | ||
getAlertRuleQueryRow(refId?: string): AlertRuleQuery; | ||
/** | ||
* Clicks the "Add query" button and returns an instance of the {@link AlertRuleQuery} class for the new query row. | ||
* | ||
* Since Grafana 11.6, this method is only available if advanced mode is enabled. Use enableQueryAdvancedMode() method to enable it. | ||
*/ | ||
@@ -24,0 +36,0 @@ clickAddQueryRow(): Promise<AlertRuleQuery>; |
@@ -40,2 +40,3 @@ "use strict"; | ||
const AlertRuleQuery_1 = require("../components/AlertRuleQuery"); | ||
const QUERY_AND_EXPRESSION_STEP_ID = '2'; | ||
class AlertRuleEditPage extends GrafanaPage_1.GrafanaPage { | ||
@@ -66,6 +67,55 @@ ctx; | ||
} | ||
get advancedModeSwitch() { | ||
return this.getByGrafanaSelector(this.ctx.selectors.components.AlertRules.stepAdvancedModeSwitch(QUERY_AND_EXPRESSION_STEP_ID)); | ||
} | ||
async isAdvancedModeSupported() { | ||
// why not check if alertingQueryAndExpressionsStepMode feature is enabled? then we'd have to update the code when the toggle is removed. | ||
const count = await this.getByGrafanaSelector(this.ctx.selectors.components.AlertRules.stepAdvancedModeSwitch(QUERY_AND_EXPRESSION_STEP_ID)).count(); | ||
return count > 0; | ||
} | ||
/* | ||
* Enables the advanced mode for the query and expression step. | ||
* Only available in Grafana 11.6.0 and later. If advanced mode is not supported, this method will do nothing. | ||
*/ | ||
async enableAdvancedQueryMode() { | ||
const advancedModeSupported = await this.isAdvancedModeSupported(); | ||
if (!advancedModeSupported) { | ||
console.log('Advanced query mode is not supported in this Grafana version. Ignoring the request.'); | ||
return; | ||
} | ||
await this.getByGrafanaSelector(this.ctx.selectors.components.AlertRules.stepAdvancedModeSwitch(QUERY_AND_EXPRESSION_STEP_ID)).check({ force: true }); | ||
} | ||
/* | ||
* Disabled the advanced mode for the query and expression step. | ||
* Advanced mode is enabled by default in Grafana 11.6.0 and later. | ||
*/ | ||
async disableAdvancedQueryMode() { | ||
const advancedModeSupported = await this.isAdvancedModeSupported(); | ||
if (!advancedModeSupported) { | ||
console.log('Advanced query mode is not supported in this Grafana version. Ignoring the request.'); | ||
return; | ||
} | ||
await this.getByGrafanaSelector(this.ctx.selectors.components.AlertRules.stepAdvancedModeSwitch(QUERY_AND_EXPRESSION_STEP_ID)).uncheck({ force: true }); | ||
} | ||
async getQueryRow(refId = 'A') { | ||
const advancedModeSupported = await this.isAdvancedModeSupported(); | ||
if (advancedModeSupported && !(await this.advancedModeSwitch.isChecked()) && refId === 'A') { | ||
// return the default query row | ||
return new AlertRuleQuery_1.AlertRuleQuery(this.ctx, this.ctx.page.getByTestId('query-editor-row')); | ||
} | ||
// return query by refId | ||
const locator = this.getByGrafanaSelector(this.ctx.selectors.components.QueryEditorRows.rows).filter({ | ||
has: this.getByGrafanaSelector(this.ctx.selectors.components.QueryEditorRow.title(refId)), | ||
}); | ||
return new AlertRuleQuery_1.AlertRuleQuery(this.ctx, locator); | ||
} | ||
/** | ||
* Returns an instance of the {@link AlertRuleQuery} class for the query row with the provided refId. | ||
* @deprecated Use getQueryRow instead | ||
* Returns an instance of the {@link AlertRuleQuery} class for a query in the query and expression step (step 2) | ||
* | ||
* @param refId is optional. If not provided, it will return query row with refId 'A' in Grafana versions <11.6. | ||
* In Grafana versions >=11.6 where advanced mode is supported, it will return the default query if advanced mode | ||
* is not enabled. If advanced mode is enabled, it will return the a query by refId. | ||
*/ | ||
getAlertRuleQueryRow(refId) { | ||
getAlertRuleQueryRow(refId = 'A') { | ||
const locator = this.getByGrafanaSelector(this.ctx.selectors.components.QueryEditorRows.rows).filter({ | ||
@@ -78,4 +128,10 @@ has: this.getByGrafanaSelector(this.ctx.selectors.components.QueryEditorRow.title(refId)), | ||
* Clicks the "Add query" button and returns an instance of the {@link AlertRuleQuery} class for the new query row. | ||
* | ||
* Since Grafana 11.6, this method is only available if advanced mode is enabled. Use enableQueryAdvancedMode() method to enable it. | ||
*/ | ||
async clickAddQueryRow() { | ||
const advancedModeSupported = await this.isAdvancedModeSupported(); | ||
if (advancedModeSupported && !(await this.advancedModeSwitch.isChecked())) { | ||
throw new Error('Since Grafana 11.6, you need to enable advanced mode to add queries. Use enableQueryAdvancedMode() method to enable it.'); | ||
} | ||
await this.getByGrafanaSelector(this.ctx.selectors.components.QueryTab.addQuery).click(); | ||
@@ -82,0 +138,0 @@ const locator = this.getByGrafanaSelector(this.ctx.selectors.components.QueryEditorRows.rows).last(); |
{ | ||
"name": "@grafana/plugin-e2e", | ||
"version": "1.17.1", | ||
"version": "1.17.2-canary.1508.08864124983722c.0", | ||
"main": "./dist/index.js", | ||
@@ -39,3 +39,3 @@ "types": "./dist/index.d.ts", | ||
"devDependencies": { | ||
"@playwright/test": "^1.50.0", | ||
"@playwright/test": "^1.50.1", | ||
"@types/uuid": "^10.0.0", | ||
@@ -59,3 +59,3 @@ "dotenv": "^16.4.7" | ||
}, | ||
"gitHead": "eb261766bea8898f97d078b211338a8556e3985a" | ||
"gitHead": "08864124983722c3363c965236f8d88203258ef3" | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
213012
4374
2
7
64
2
277