oncall-engine/grafana-plugin/e2e-tests/pluginInitialization/initialization.test.ts
Dominik Broj 344cd0efde
Add missing labels permissions, fix tilt ci from ops-devenv, fix expensive e2e tests (#4842)
# What this PR does

- add missing labels-related permissions for external service account
used by new oncall init process
- fix expensive e2e tests in new oncall init process
- unify Grafana versions between standard and expensive e2e tests
- fix running tilt through ops-devenv in new oncall init process
- avoid duplicated standard e2e tests on workflows that run daily and on
merges to main

## Which issue(s) this PR closes

Related to https://github.com/grafana/oncall-private/issues/2656

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## 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: Joey Orlando <joseph.t.orlando@gmail.com>
2024-08-19 18:17:10 +00:00

73 lines
2.8 KiB
TypeScript

import { waitInMs } from 'utils/async';
import { test, expect, Page } from '../fixtures';
import { OrgRole, isGrafanaVersionLowerThan } 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(isGrafanaVersionLowerThan('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');
});
});