# 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.
69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import { Page } from '@playwright/test';
|
|
import dayjs from 'dayjs';
|
|
|
|
import { clickButton, selectDropdownValue } from './forms';
|
|
import { goToOnCallPage } from './navigation';
|
|
|
|
export const createOnCallSchedule = async (
|
|
page: Page,
|
|
scheduleName: string,
|
|
userName: string,
|
|
withRotation = true
|
|
): Promise<void> => {
|
|
// go to the schedules page
|
|
await goToOnCallPage(page, 'schedules');
|
|
|
|
// create an oncall-rotation schedule
|
|
await clickButton({ page, buttonText: 'New Schedule' });
|
|
await page.getByRole('button', { name: 'Create' }).first().click();
|
|
|
|
// fill in the name input
|
|
await page.getByTestId('schedule-form').locator('input[name="name"]').fill(scheduleName);
|
|
|
|
// Add a new layer w/ the current user to it
|
|
await clickButton({ page, buttonText: 'Create Schedule' });
|
|
|
|
if (withRotation) {
|
|
await createRotation(page, userName);
|
|
}
|
|
};
|
|
|
|
export const createRotation = async (page: Page, userName: string, isFirstScheduleRotation = true) => {
|
|
await clickButton({ page, buttonText: 'Add rotation' });
|
|
if (!isFirstScheduleRotation) {
|
|
await page.getByText('Layer 1 rotation', { exact: true }).click();
|
|
}
|
|
await selectDropdownValue({
|
|
page,
|
|
selectType: 'grafanaSelect',
|
|
placeholderText: 'Add user',
|
|
value: userName,
|
|
});
|
|
await clickButton({ page, buttonText: 'Create' });
|
|
};
|
|
|
|
export interface OverrideFormDateInputs {
|
|
start: dayjs.Dayjs;
|
|
end: dayjs.Dayjs;
|
|
}
|
|
|
|
export const getOverrideFormDateInputs = async (page: Page): Promise<OverrideFormDateInputs> => {
|
|
const getInputValue = async (inputNumber: number): Promise<string> => {
|
|
const element = await page.waitForSelector(`div[data-testid=\"override-inputs\"] >> input >> nth=${inputNumber}`);
|
|
return await element.inputValue();
|
|
};
|
|
|
|
const startDate = await getInputValue(0);
|
|
const startTime = await getInputValue(1);
|
|
|
|
const endDate = await getInputValue(2);
|
|
const endTime = await getInputValue(3);
|
|
|
|
const startDateTime = dayjs(`${startDate} ${startTime}`, 'MM/DD/YYYY HH:mm');
|
|
const endDateTime = dayjs(`${endDate} ${endTime}`, 'MM/DD/YYYY HH:mm');
|
|
|
|
return {
|
|
start: startDateTime,
|
|
end: endDateTime,
|
|
};
|
|
};
|