-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin E2E: Make it possible to test query editor in panel edit page (#…
…551) Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
- Loading branch information
1 parent
1430c7e
commit 33000d1
Showing
28 changed files
with
581 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/plugin-e2e/provisioning/datasources/google-sheets-datasource-jwt.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# config file version | ||
apiVersion: 1 | ||
|
||
deleteDatasources: | ||
- name: Google Sheets Service Account | ||
orgId: 1 | ||
|
||
datasources: | ||
- editable: true | ||
enabled: true | ||
jsonData: | ||
authType: jwt | ||
name: Google Sheets Service Account | ||
secureJsonData: | ||
jwt: ${GOOGLE_JWT_FILE} | ||
type: grafana-googlesheets-datasource | ||
version: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/plugin-e2e/src/fixtures/commands/readProvision.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { TestFixture } from '@playwright/test'; | ||
import { promises } from 'fs'; | ||
import { resolve as resolvePath } from 'path'; | ||
import { parse as parseYml } from 'yaml'; | ||
import { PluginFixture, PluginOptions } from '../../api'; | ||
import { ReadProvisionArgs } from '../../types'; | ||
import { PlaywrightCombinedArgs } from '../types'; | ||
|
||
type ReadProvisionFixture = TestFixture< | ||
<T = any>(args: ReadProvisionArgs) => Promise<T>, | ||
PluginFixture & PluginOptions & PlaywrightCombinedArgs | ||
>; | ||
|
||
const readProvision: ReadProvisionFixture = async ({}, use) => { | ||
await use(async ({ filePath }) => { | ||
const resolvedPath = resolvePath(process.cwd(), 'provisioning', filePath); | ||
const contents = await promises.readFile(resolvedPath, 'utf8'); | ||
return parseYml(contents); | ||
}); | ||
}; | ||
|
||
export default readProvision; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { TestFixture, expect } from '@playwright/test'; | ||
import { PluginFixture, PluginOptions } from '../api'; | ||
import { DashboardPage } from '../models'; | ||
import { PlaywrightCombinedArgs } from './types'; | ||
|
||
type NewDashboardPageFixture = TestFixture<DashboardPage, PluginFixture & PluginOptions & PlaywrightCombinedArgs>; | ||
|
||
const newDashboardPage: NewDashboardPageFixture = async ({ page, request, selectors, grafanaVersion }, use) => { | ||
const newDashboardPage = new DashboardPage({ page, selectors, grafanaVersion, request }, expect); | ||
await newDashboardPage.goto(); | ||
await use(newDashboardPage); | ||
}; | ||
|
||
export default newDashboardPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { TestFixture } from '@playwright/test'; | ||
import { PluginFixture, PluginOptions } from '../api'; | ||
import { PanelEditPage } from '../models'; | ||
import { PlaywrightCombinedArgs } from './types'; | ||
|
||
type PanelEditPageFixture = TestFixture<PanelEditPage, PluginFixture & PluginOptions & PlaywrightCombinedArgs>; | ||
|
||
const panelEditPage: PanelEditPageFixture = async ({ newDashboardPage }, use) => { | ||
const panelEditPage = await newDashboardPage.addPanel(); | ||
await use(panelEditPage); | ||
}; | ||
|
||
export default panelEditPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import toBeOK from './toBeOK'; | ||
import toHavePanelError from './toHavePanelError'; | ||
|
||
export default { | ||
toBeOK, | ||
toHavePanelError, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { expect } from '@playwright/test'; | ||
import { PanelError } from '../types'; | ||
import { getMessage } from './utils'; | ||
|
||
const toHavePanelError = async (panelError: PanelError, options?: { timeout?: number }) => { | ||
let pass = true; | ||
let actual; | ||
let message: any = 'A panel error to be displayed'; | ||
|
||
try { | ||
const numberOfErrors = await panelError.getPanelError().count(); | ||
await expect(numberOfErrors).toBe(1); | ||
} catch (_) { | ||
message = getMessage(message, 'No panel error was found on the page'); | ||
actual = await panelError.getPanelError().count(); | ||
pass = false; | ||
} | ||
|
||
return { | ||
message: () => message, | ||
pass, | ||
actual, | ||
}; | ||
}; | ||
|
||
export default toHavePanelError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const gte = require('semver/functions/gte'); | ||
|
||
import { GotoDashboardArgs, PluginTestCtx } from '../types'; | ||
|
||
import { Expect } from '@playwright/test'; | ||
import { DataSourcePicker } from './DataSourcePicker'; | ||
import { GrafanaPage } from './GrafanaPage'; | ||
import { PanelEditPage } from './PanelEditPage'; | ||
import { TimeRange } from './TimeRange'; | ||
|
||
export class DashboardPage extends GrafanaPage { | ||
dataSourcePicker: any; | ||
timeRange: TimeRange; | ||
|
||
constructor(ctx: PluginTestCtx, expect: Expect<any>, protected readonly dashboardUid?: string) { | ||
super(ctx, expect); | ||
this.dataSourcePicker = new DataSourcePicker(ctx, expect); | ||
this.timeRange = new TimeRange(ctx, this.expect); | ||
} | ||
|
||
async goto(opts?: GotoDashboardArgs) { | ||
const uid = opts?.uid || this.dashboardUid; | ||
let url = uid ? this.ctx.selectors.pages.Dashboard.url(uid) : this.ctx.selectors.pages.AddDashboard.url; | ||
if (opts?.queryParams) { | ||
url += `?${opts.queryParams.toString()}`; | ||
} | ||
await this.ctx.page.goto(url, { | ||
waitUntil: 'networkidle', | ||
}); | ||
if (opts?.timeRange) { | ||
await this.timeRange.set(opts.timeRange); | ||
} | ||
} | ||
|
||
async gotoPanelEditPage(panelId: string) { | ||
const url = this.ctx.selectors.pages.Dashboard.url(this.dashboardUid ?? ''); | ||
await this.ctx.page.goto(`${url}?editPanel=${panelId}`, { | ||
waitUntil: 'networkidle', | ||
}); | ||
return new PanelEditPage(this.ctx, this.expect); | ||
} | ||
|
||
async addPanel(): Promise<PanelEditPage> { | ||
if (gte(this.ctx.grafanaVersion, '10.0.0')) { | ||
//TODO: add new selector and use it in grafana/ui | ||
const title = gte(this.ctx.grafanaVersion, '10.1.0') ? 'Add button' : 'Add panel button'; | ||
await this.getByTestIdOrAriaLabel(this.ctx.selectors.components.PageToolbar.itemButton(title)).click(); | ||
await this.getByTestIdOrAriaLabel( | ||
this.ctx.selectors.pages.AddDashboard.itemButton('Add new visualization menu item') | ||
).click(); | ||
} else { | ||
await this.getByTestIdOrAriaLabel(this.ctx.selectors.pages.AddDashboard.addNewPanel).click(); | ||
} | ||
|
||
return new PanelEditPage(this.ctx, this.expect); | ||
} | ||
|
||
async deleteDashboard() { | ||
await this.ctx.request.delete(`/api/datasources/uid/${this.dashboardUid}`); | ||
} | ||
|
||
async refreshDashboard() { | ||
await this.ctx.page.getByTestId(this.ctx.selectors.components.RefreshPicker.runButtonV2).click(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Expect } from '@playwright/test'; | ||
import { PluginTestCtx } from '../types'; | ||
import { GrafanaPage } from './GrafanaPage'; | ||
|
||
export class DataSourcePicker extends GrafanaPage { | ||
constructor(ctx: PluginTestCtx, expect: Expect<any>) { | ||
super(ctx, expect); | ||
} | ||
|
||
async set(name: string) { | ||
await this.getByTestIdOrAriaLabel(this.ctx.selectors.components.DataSourcePicker.container) | ||
.locator('input') | ||
.fill(name); | ||
|
||
// this is a hack to get the selection to work in 10.ish versions of Grafana. | ||
// TODO: investigate if the select component can somehow be refactored so that its easier to test with playwright | ||
await this.ctx.page.keyboard.press('ArrowDown'); | ||
await this.ctx.page.keyboard.press('ArrowUp'); | ||
await this.ctx.page.keyboard.press('Enter'); | ||
} | ||
} |
Oops, something went wrong.