Skip to content
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

E2E: Added command and page to interact with app pages #821

Merged
merged 3 commits into from
Mar 18, 2024

Conversation

mckn
Copy link
Collaborator

@mckn mckn commented Mar 14, 2024

What this PR does / why we need it:
This PR adds an AppPage that will make it easier to write tests agains pages added within a Grafana app plugin. It removes the need of constructing the base path /a/${pluginId} in every test. If we, for some reason, change the base path for apps we have this thin layer where we can cater for that in different versions of Grafana.

This functionality can be used in two different ways.

Either you call gotoAppPage({pluginId: '', path: ''}) to navigate to the page you want to test.

test('should navigate to app sub page when calling goto with path', async ({ gotoAppPage, page }) => {
  await gotoAppPage({ pluginId: 'redis-app', path: '/create' });
  await expect(page).toHaveURL(/.*\/a\/redis-app\/create$/);
});

Or you can create your own app fixture that you can use within your plugin to write tests.

// fixtures.ts
import { AppConfigPage, test as base } from '@grafana/plugin-e2e';
import pluginJson from '../src/plugin.json';

type AppTestFixture = { pageOne: AppPage };

export const test = base.extend<AppTestFixture>({
  pageOne: async ({ page, selectors, grafanaVersion, request }, use, testInfo) => {
    await use(
      new appPage(
        { page, selectors, grafanaVersion, request, testInfo },
        {
          pluginId: pluginJson.id,
          path: '/one',
        }
      )
    );
  },
});

export { expect } from '@grafana/plugin-e2e';

// test.spec.ts
test('navigating to page one', async ({ pageOne, page }) => {
  await pageOne.goto();
  await expect(page).toHaveURL(/.*\/a\/redis-app\/one$/)
});

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

📦 Published PR as canary version: Canary Versions

✨ Test out this PR locally via:

npm install @grafana/create-plugin@4.3.0-canary.821.518e194.0
npm install @grafana/plugin-e2e@0.22.0-canary.821.518e194.0
# or 
yarn add @grafana/create-plugin@4.3.0-canary.821.518e194.0
yarn add @grafana/plugin-e2e@0.22.0-canary.821.518e194.0

@mckn mckn requested a review from a team as a code owner March 14, 2024 12:56
@mckn mckn requested review from Ukochka and removed request for a team March 14, 2024 12:56
Copy link

github-actions bot commented Mar 14, 2024

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged and will trigger a new minor release.
NOTE: When merging a PR with the release label please avoid merging another PR. For further information see here.

@mckn mckn added minor Increment the minor version when merged release Create a release when this pr is merged labels Mar 14, 2024
@mckn mckn requested a review from sunker March 14, 2024 13:06
@mckn mckn self-assigned this Mar 14, 2024
Copy link
Contributor

@sunker sunker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just one thing.

packages/plugin-e2e/src/models/pages/AppPage.ts Outdated Show resolved Hide resolved
@mckn mckn enabled auto-merge (squash) March 18, 2024 16:29
@mckn mckn merged commit 05df81e into main Mar 18, 2024
14 checks passed
@mckn mckn deleted the mckn/adding-app-plugin-page branch March 18, 2024 16:29
@grafana-plugins-platform-bot
Copy link

🚀 PR was released in @grafana/plugin-e2e@0.22.0 🚀

@grafana-plugins-platform-bot grafana-plugins-platform-bot bot added the released This issue/pull request has been released. label Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Increment the minor version when merged release Create a release when this pr is merged released This issue/pull request has been released.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants