oncall-engine/grafana-plugin/e2e-tests/utils/integrations.ts
Dominik Broj 6d3b836df7
Back merge irm (#5098)
# What this PR does

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*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-10-01 12:59:24 +00:00

126 lines
4.2 KiB
TypeScript

import { Page, expect } from '@playwright/test';
import { clickButton, generateRandomValue, selectDropdownValue } from './forms';
import { goToOnCallPage } from './navigation';
export const openCreateIntegrationModal = async (page: Page): Promise<void> => {
// open the create integration modal
await page.getByRole('button', { name: 'New integration' }).click();
// wait for it to pop up
await page.getByTestId('create-integration-modal').waitFor();
};
export const createIntegration = async ({
page,
integrationName = `integration-${generateRandomValue()}`,
integrationSearchText = 'Webhook',
shouldGoToIntegrationsPage = true,
}: {
page: Page;
integrationName?: string;
integrationSearchText?: string;
shouldGoToIntegrationsPage?: boolean;
}): Promise<void> => {
if (shouldGoToIntegrationsPage) {
// go to the integrations page
await goToOnCallPage(page, 'integrations');
}
await openCreateIntegrationModal(page);
// create an integration
await page
.getByTestId('create-integration-modal')
.getByTestId('integration-display-name')
.filter({ hasText: integrationSearchText })
.first()
.click();
// fill in the required inputs
await page.getByPlaceholder('Integration Name').fill(integrationName);
await page.getByPlaceholder('Integration Description').fill('Here goes your integration description');
await page.getByTestId('update-integration-button').focus();
await page.getByTestId('update-integration-button').click();
await goToOnCallPage(page, 'integrations');
await searchIntegrationAndAssertItsPresence({ page, integrationName });
await page.getByRole('link', { name: integrationName }).click();
await page.waitForLoadState('networkidle');
};
export const assignEscalationChainToIntegration = async (page: Page, escalationChainName: string): Promise<void> => {
const notSelected = page.getByTestId('integration-escalation-chain-not-selected');
if (await notSelected.isHidden()) {
await clickButton({ page, buttonText: 'Add route' });
await page.waitForTimeout(500);
}
await notSelected.last().click();
// assign the escalation chain to the integration
await selectDropdownValue({
page,
selectType: 'grafanaSelect',
placeholderText: 'Select Escalation Chain',
value: escalationChainName,
startingLocator: page.getByTestId('escalation-chain-select').last(),
});
};
export const sendDemoAlert = async (page: Page): Promise<void> => {
await clickButton({ page, buttonText: 'Send demo alert' });
await clickButton({ page, buttonText: 'Send Alert' });
await page.getByTestId('demo-alert-sent-notification').waitFor({ state: 'visible' });
};
export const createIntegrationAndSendDemoAlert = async (
page: Page,
integrationName: string,
escalationChainName?: string
): Promise<void> => {
await createIntegration({ page, integrationName });
if (escalationChainName) {
await assignEscalationChainToIntegration(page, escalationChainName);
}
await sendDemoAlert(page);
};
export const filterIntegrationsTableAndGoToDetailPage = async (page: Page, integrationName: string): Promise<void> => {
// filter the integrations page by the integration in question, then go to its detail page
await selectDropdownValue({
page,
selectType: 'grafanaSelect',
placeholderText: 'Search or filter results...',
value: integrationName,
pressEnterInsteadOfSelectingOption: true,
});
await page.getByTestId('integrations-table').getByText(`${integrationName}`).click();
};
export const searchIntegrationAndAssertItsPresence = async ({
page,
integrationName,
visibleExpected = true,
}: {
page: Page;
integrationName: string;
visibleExpected?: boolean;
}) => {
await page
.locator('div')
.filter({ hasText: /^Search or filter results\.\.\.$/ })
.nth(1)
.click();
const integrationsTable = page.getByTestId('integrations-table');
await page.keyboard.insertText(integrationName);
await page.keyboard.press('Enter');
await page.waitForTimeout(2000);
const nbOfResults = await integrationsTable.getByText(integrationName).count();
if (visibleExpected) {
expect(nbOfResults).toBeGreaterThanOrEqual(1);
} else {
expect(nbOfResults).toBe(0);
}
};