oncall-engine/grafana-plugin/e2e-tests/utils/userSettings.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

94 lines
3.7 KiB
TypeScript

import { Locator, Page } from '@playwright/test';
import { clickButton, fillInInputByPlaceholderValue, selectDropdownValue } from './forms';
import { closeModal } from './modals';
import { goToOnCallPage } from './navigation';
import { getPhoneNumber, getVerificationCodeFromSms, waitForSms } from './phone';
type NotifyBy = 'SMS' | 'Phone call';
const openUserSettingsModal = async (page: Page): Promise<void> => {
await goToOnCallPage(page, 'users');
await clickButton({ page, buttonText: 'View my profile' });
};
const getForgetPhoneNumberButton = (page: Page): Locator => page.locator('button >> text=Forget Phone Number');
export const verifyUserPhoneNumber = async (page: Page): Promise<void> => {
// open the user settings modal
await openUserSettingsModal(page);
// go to the Phone Verification tab
await page.getByTestId('tab-phone-verification').click();
// check to see if we've already verified our phone number.. no need to do it more than once
if (await getForgetPhoneNumberButton(page).isVisible()) {
await closeModal(page);
return;
}
// get the phone number we will use
const phoneNumber = await getPhoneNumber();
/**
* input the phone number and submit the form
* on the backend this should trigger twilio to send out an SMS verification code
*/
await fillInInputByPlaceholderValue(page, 'Please enter the phone number with country code', phoneNumber.phoneNumber);
await clickButton({ page, buttonText: 'Send Code' });
// wait for the SMS verification code to arrive
const sms = await waitForSms();
// take the SMS verification code that we just received, input it into the form, and submit the form
await fillInInputByPlaceholderValue(page, 'Please enter the code', getVerificationCodeFromSms(sms));
await clickButton({ page, buttonText: 'Verify' });
// wait for a confirmation that the number has been verified and then close the modal
await getForgetPhoneNumberButton(page).click();
await closeModal(page);
};
const getDefaultNotificationSettingsSectionByTestId = (page: Page): Locator =>
page.getByTestId('default-personal-notification-settings');
/**
* gets the first row of our default notification settings
* and then gets the notification type dropdown
*/
const getFirstDefaultNotificationSettingTypeDropdown = async (page: Page): Promise<Locator> => {
const firstDefaultNotificationSettingRow = getDefaultNotificationSettingsSectionByTestId(page).locator('li >> nth=0');
// get the notification type dropdown specifically
return firstDefaultNotificationSettingRow.locator('div[class*="input-wrapper"] >> nth=1');
};
export const configureUserNotificationSettings = async (page: Page, notifyBy: NotifyBy): Promise<void> => {
// open the user settings modal
await openUserSettingsModal(page);
// select our notification type, first check if we have any already defined, if so, click the
// "Add Notification Step" button
const defaultNotificationSettingsSection = getDefaultNotificationSettingsSectionByTestId(page);
const addNotificationStepText = 'Add Notification Step';
if (!(await defaultNotificationSettingsSection.locator(`button >> text=${addNotificationStepText}`).isVisible())) {
await clickButton({
page,
buttonText: addNotificationStepText,
startingLocator: defaultNotificationSettingsSection,
});
}
const firstDefaultNotificationTypeDropdopdown = await getFirstDefaultNotificationSettingTypeDropdown(page);
await selectDropdownValue({
page,
value: notifyBy,
selectType: 'grafanaSelect',
startingLocator: firstDefaultNotificationTypeDropdopdown,
optionExactMatch: false, // there are emojis at the end
});
// close the modal
await closeModal(page);
};