oncall-engine/grafana-plugin/e2e-tests/pluginInitialization/initialization.test.ts
Dominik Broj 06d19bf6e9
New OnCall plugin initialization process (#4657)
# What this PR does

New OnCall plugin initialization process

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.

---------

Co-authored-by: Michael Derynck <michael.derynck@grafana.com>
Co-authored-by: Matias Bordese <mbordese@gmail.com>
2024-08-16 16:43:52 +00:00

78 lines
2.9 KiB
TypeScript

import semver from 'semver';
import { waitInMs } from 'utils/async';
import { test, expect, Page } from '../fixtures';
import { OrgRole } from '../utils/constants';
import { goToGrafanaPage, goToOnCallPage } from '../utils/navigation';
import { createGrafanaUser, loginAndWaitTillGrafanaIsLoaded } from '../utils/users';
const assertThatUserCanAccessOnCallWithinMinute = async (page: Page, testIdOfConnectedElem: string) => {
let isConnected = false;
let retries = 0;
while (!isConnected && retries < 12) {
await waitInMs(5_000);
await page.reload();
await page.waitForLoadState('networkidle');
isConnected = await page.getByTestId(testIdOfConnectedElem).isVisible();
}
expect(isConnected).toBe(true);
};
test.describe('Plugin initialization', () => {
test('Plugin OnCall pages work for new viewer user within 1 minute after creation', async ({
adminRolePage: { page },
browser,
}) => {
test.slow();
// Create new viewer user and login as new user
const USER_NAME = `viewer-${new Date().getTime()}`;
await createGrafanaUser({ page, username: USER_NAME, role: OrgRole.Viewer });
// Create new browser context to act as new user
const viewerUserContext = await browser.newContext();
const viewerUserPage = await viewerUserContext.newPage();
await loginAndWaitTillGrafanaIsLoaded({ page: viewerUserPage, username: USER_NAME });
// Go to OnCall and assert that plugin is connected
await goToOnCallPage(viewerUserPage, 'alert-groups');
await assertThatUserCanAccessOnCallWithinMinute(viewerUserPage, 'add-escalation-button');
});
test('Extension registered by OnCall plugin works for new editor user within 1 minute after creation', async ({
adminRolePage: { page },
browser,
}) => {
test.slow();
test.skip(
semver.lt(process.env.CURRENT_GRAFANA_VERSION, '10.3.0'),
'Extension is only available in Grafana 10.3.0 and above'
);
// Create new editor user
const USER_NAME = `editor-${new Date().getTime()}`;
await createGrafanaUser({ page, username: USER_NAME, role: OrgRole.Editor });
await page.waitForLoadState('networkidle');
// Create new browser context to act as new user
const editorUserContext = await browser.newContext();
const editorUserPage = await editorUserContext.newPage();
await loginAndWaitTillGrafanaIsLoaded({ page: editorUserPage, username: USER_NAME });
// Start watching for HTTP responses
const networkResponseStatuses: number[] = [];
editorUserPage.on('requestfinished', async (request) =>
networkResponseStatuses.push((await request.response()).status())
);
// Go to profile -> IRM tab where OnCall plugin extension is registered and assert that none of the requests failed
await goToGrafanaPage(editorUserPage, '/profile?tab=irm');
await assertThatUserCanAccessOnCallWithinMinute(editorUserPage, 'mobile-app-connection');
});
});