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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/plugin-e2e/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
DashboardPageArgs,
DashboardEditViewArgs,
GotoAppConfigPageArgs,
GotoAppPageArgs,
} from './types';
import {
PanelEditPage,
Expand All @@ -22,6 +23,7 @@ import {
VariableEditPage,
AnnotationEditPage,
AppConfigPage,
AppPage,
} from './models';
import { grafanaE2ESelectorEngine } from './selectorEngine';
import { ExplorePage } from './models/pages/ExplorePage';
Expand Down Expand Up @@ -267,6 +269,11 @@ export type PluginFixture = {
* Fixture command that navigates to the AppConfigPage for a given plugin.
*/
gotoAppConfigPage: (args: GotoAppConfigPageArgs) => Promise<AppConfigPage>;

/**
* Fixture command that navigates to an AppPage for a given plugin.
*/
gotoAppPage: (args: GotoAppPageArgs) => Promise<AppPage>;
};

// extend Playwright with Grafana plugin specific fixtures
Expand Down
19 changes: 19 additions & 0 deletions packages/plugin-e2e/src/fixtures/commands/gotoAppPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { TestFixture } from '@playwright/test';
import { PluginFixture, PluginOptions } from '../../api';
import { PlaywrightCombinedArgs } from '../types';
import { AppPage, GotoAppPageArgs } from '../..';

type GotoAppPageFixture = TestFixture<
(args: GotoAppPageArgs) => Promise<AppPage>,
PluginFixture & PluginOptions & PlaywrightCombinedArgs
>;

export const gotoAppPage: GotoAppPageFixture = async ({ page, selectors, grafanaVersion, request }, use, testInfo) => {
await use(async ({ pluginId, path }) => {
const appPage = new AppPage({ page, selectors, grafanaVersion, request, testInfo }, { pluginId });
await appPage.goto({ path });
return appPage;
});
};

export default gotoAppPage;
2 changes: 2 additions & 0 deletions packages/plugin-e2e/src/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import gotoVariableEditPage from './commands/gotoVariableEditPage';
import gotoAnnotationEditPage from './commands/gotoAnnotationEditPage';
import gotoDataSourceConfigPage from './commands/gotoDataSourceConfigPage';
import gotoAppConfigPage from './commands/gotoAppConfigPage';
import gotoAppPage from './commands/gotoAppPage';

const fixtures = {
selectors,
Expand All @@ -42,6 +43,7 @@ const fixtures = {
gotoAnnotationEditPage,
gotoDataSourceConfigPage,
gotoAppConfigPage,
gotoAppPage,
};

export default fixtures;
1 change: 1 addition & 0 deletions packages/plugin-e2e/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export { Panel } from './components/Panel';
export { TimeRange } from './components/TimeRange';
export { AppConfigPage } from './pages/AppConfigPage';
export { PluginConfigPage } from './pages/PluginConfigPage';
export { AppPage } from './pages/AppPage';
4 changes: 2 additions & 2 deletions packages/plugin-e2e/src/models/pages/AppConfigPage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Response as PlaywrightResponse } from '@playwright/test';
import { PluginConfigPageArgs, PluginTestCtx } from '../../types';
import { PluginPageArgs, PluginTestCtx } from '../../types';
import { PluginConfigPage } from './PluginConfigPage';

export class AppConfigPage extends PluginConfigPage {
constructor(readonly ctx: PluginTestCtx, readonly args: PluginConfigPageArgs) {
constructor(readonly ctx: PluginTestCtx, readonly args: PluginPageArgs) {
super(ctx, args);
}

Expand Down
19 changes: 19 additions & 0 deletions packages/plugin-e2e/src/models/pages/AppPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as nodePath from 'path';
import { AppPageNavigateOptions, PluginPageArgs, PluginTestCtx } from '../../types';
import { GrafanaPage } from '..';

export class AppPage extends GrafanaPage {
constructor(readonly ctx: PluginTestCtx, readonly args: PluginPageArgs) {
super(ctx);
}

/**
* Will append the `/a/${pluginId}` before the provided path and then
* navigate to the page.
*/
goto(options?: AppPageNavigateOptions): Promise<void> {
const path = options?.path ?? '';
const url = nodePath.join('/a/', this.args.pluginId, path);
return super.navigate(url, options);
}
}
4 changes: 2 additions & 2 deletions packages/plugin-e2e/src/models/pages/PluginConfigPage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Response as PlaywrightResponse } from '@playwright/test';
import { PluginConfigPageArgs, NavigateOptions, PluginTestCtx } from '../../types';
import { PluginPageArgs, NavigateOptions, PluginTestCtx } from '../../types';
import { GrafanaPage } from './GrafanaPage';

export class PluginConfigPage extends GrafanaPage {
constructor(readonly ctx: PluginTestCtx, readonly args: PluginConfigPageArgs) {
constructor(readonly ctx: PluginTestCtx, readonly args: PluginPageArgs) {
super(ctx);
}

Expand Down
12 changes: 10 additions & 2 deletions packages/plugin-e2e/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ export type NavigateOptions = {
queryParams?: URLSearchParams;
};

export type AppPageNavigateOptions = NavigateOptions & {
path?: string;
};

export type GetByTestIdOrAriaLabelOptions = {
/**
*Optional root locator to search within. If no locator is provided, the page will be used
Expand Down Expand Up @@ -304,8 +308,12 @@ export interface ContainTextOptions {
useInnerText?: boolean;
}

export type PluginConfigPageArgs = {
export type PluginPageArgs = {
pluginId: string;
};

export type GotoAppConfigPageArgs = PluginConfigPageArgs;
export type GotoAppConfigPageArgs = PluginPageArgs;

export type GotoAppPageArgs = PluginPageArgs & {
path?: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { AppPage, expect, test } from '../../../../src';

test('should navigate to app root page when calling goto without any path', async ({
grafanaVersion,
selectors,
page,
request,
}, testInfo) => {
const appPage = new AppPage({ grafanaVersion, selectors, page, request, testInfo }, { pluginId: 'redis-app' });
await appPage.goto();

await expect(page).toHaveURL(/.*\/a\/redis-app$/);
});

test('should navigate to app sub page when calling goto with path', async ({
grafanaVersion,
selectors,
page,
request,
}, testInfo) => {
const appPage = new AppPage({ grafanaVersion, selectors, page, request, testInfo }, { pluginId: 'redis-app' });
await appPage.goto({ path: '/create' });

await expect(page).toHaveURL(/.*\/a\/redis-app\/create$/);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect, test } from '../../../../src';

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

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$/);
});
Loading