oncall-engine/grafana-plugin/e2e-tests/pluginInitialization/initialization.test.ts
Dominik Broj df6f7af8a5
chore: adjust dir names to irm (#4989)
# What this PR does

- rename utils to helpers
- rename types.ts to app-types.ts

## Which issue(s) this PR closes

Related to
https://raintank-corp.slack.com/archives/C0762D6EUDV/p1725477060488709
https://raintank-corp.slack.com/archives/C0762D6EUDV/p1724936143487849

TL;DR
IRM needs imported modules from oncall/incident to have uniq absolute
import paths

<!--
*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

- [ ] 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.
2024-09-05 14:51:29 +00:00

73 lines
2.8 KiB
TypeScript

import { waitInMs } from 'helpers/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');
});
});