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

Create plugin: update scaffolded tests when creating an app plugin #892

Merged
merged 1 commit into from
Apr 25, 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from './fixtures';

test('should be possible to save app configuration', async ({ appConfigPage, page }) => {
const saveForm = page.getByRole('button', { name: /Save API settings/i });
const saveButton = page.getByRole('button', { name: /Save API settings/i });

// reset the configured secret
await page.getByRole('button', { name: /reset/i }).click();
Expand All @@ -14,6 +14,6 @@ test('should be possible to save app configuration', async ({ appConfigPage, pag
// listen for the server response on the saved form
const saveResponse = appConfigPage.waitForSettingsResponse();

await saveForm.click();
await saveButton.click();
await expect(saveResponse).toBeOK();
});
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import pluginJson from '../src/plugin.json';
import { test, expect } from '@grafana/plugin-e2e';
import { test, expect } from './fixtures';
import { ROUTES } from '../src/constants';

test.describe('navigating app', () => {
test('page one should render successfully', async ({ page }) => {
await page.goto(`/a/${pluginJson.id}/${ROUTES.One}`);
test('page one should render successfully', async ({ gotoPage, page }) => {
await gotoPage(`/${ROUTES.One}`);
await expect(page.getByText('This is page one.')).toBeVisible();
});

test('page two should render successfully', async ({ page }) => {
await page.goto(`/a/${pluginJson.id}/${ROUTES.Two}`);
test('page two should render successfully', async ({ gotoPage, page }) => {
await gotoPage(`/${ROUTES.Two}`);
await expect(page.getByText('This is page two.')).toBeVisible();
});

test('page three should support an id parameter', async ({ page }) => {
await page.goto(`/a/${pluginJson.id}/${ROUTES.Three}/123456`);
test('page three should support an id parameter', async ({ gotoPage, page }) => {
await gotoPage(`/${ROUTES.Three}/123456`);
await expect(page.getByText('ID: 123456')).toBeVisible();
});

test('page three should render sucessfully', async ({ page }) => {
test('page three should render sucessfully', async ({ gotoPage, page }) => {
// wait for page to successfully render
await page.goto(`/a/${pluginJson.id}/${ROUTES.One}`);
await gotoPage(`/${ROUTES.One}`);
await expect(page.getByText('This is page one.')).toBeVisible();

// navigating to page four with full width layout without sidebar menu
Expand Down
27 changes: 17 additions & 10 deletions packages/create-plugin/templates/app/tests/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { AppConfigPage, test as base } from '@grafana/plugin-e2e';
import { AppConfigPage, AppPage, test as base } from '@grafana/plugin-e2e';
import pluginJson from '../src/plugin.json';

type AppTestFixture = { appConfigPage: AppConfigPage };
type AppTestFixture = {
appConfigPage: AppConfigPage;
gotoPage: (path?: string) => Promise<AppPage>;
};

export const test = base.extend<AppTestFixture>({
appConfigPage: async ({ page, selectors, grafanaVersion, request }, use, testInfo) => {
const configPage = new AppConfigPage(
{ page, selectors, grafanaVersion, request, testInfo },
{
appConfigPage: async ({ gotoAppConfigPage }, use) => {
const configPage = await gotoAppConfigPage({
pluginId: pluginJson.id,
});
await use(configPage);
},
gotoPage: async ({ gotoAppPage }, use) => {
await use((path) =>
gotoAppPage({
path,
pluginId: pluginJson.id,
}
})
);
await configPage.goto();
await use(configPage);
},
});

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