-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin E2E: Make it possible to test query editor in panel edit page #551
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a12c8ff
add setup proj that adds data source
sunker 03da826
add custom selector engine
sunker 3ae2282
add new fixtures and models
sunker f19ab91
internalize certain types
sunker 8ec6237
add custom matcher for panel error
sunker e575dcf
cleanup
sunker 87af085
add tests
sunker 2934f45
fix request
sunker 50752f3
include ds version in multi dimensional matrix
sunker 1f717b0
use props ds name
sunker 51be95b
remove example test
sunker f55f80b
use better selector
sunker 8f4c157
improve name
sunker 0c02c26
tidy up
sunker da2f1e0
provision ds instead of using setup proj
sunker b749741
fix env variable name
sunker cdd4f14
mount provisioning folder as volume
sunker 2634e64
remove not used file
sunker dc459ea
remove empty dashboard page
sunker c71f37e
use correct type
sunker 522856a
Update packages/plugin-e2e/src/api.ts
sunker be1805b
Update packages/plugin-e2e/src/api.ts
sunker 1f88ca8
Update packages/plugin-e2e/src/api.ts
sunker 63f28c2
pr feedback
sunker 49b6b9b
fix broken selector
sunker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an idea: I think this comment is ok as it is and already really useful, however maybe in the future we could add some Grafana-related examples which we could link to from here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 100%! Actually this comment was made before I knew that it's possible to use env variables in provisioning files. That kind of makes this comment obsolete. I'll change it. But we should definitely have examples of using provisioning with (and without) secrets in plugin-examples eventually.