oncall-engine/grafana-plugin/integration-tests/utils/schedule.ts
Joey Orlando f5495ed702
add first multi-role e2e tests (#2417)
# What this PR does

Lays ground work for #1586. Adds three new fixtures, `adminRolePage`,
`editorRolePage`, and `viewerRolePage`. These fixtures can be easily
accessed in a `test` context and allow the test to be run as a user
authenticated with one of these Grafana basic roles.

The bulk of the changes in the PR are to the "global setup" step. There
is a bit of logic + communication with the Grafana instance's API, in
order to create all the necessary authentication credentials.

Lastly, adds the first basic role authorization test, asserting that
Admin/Editors can view the list of OnCall users, whereas Viewers cannot.

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-07-04 09:19:14 +00:00

56 lines
1.8 KiB
TypeScript

import { Page } from '@playwright/test';
import { clickButton, fillInInput, selectDropdownValue } from './forms';
import { goToOnCallPage } from './navigation';
import dayjs from 'dayjs';
export const createOnCallSchedule = async (page: Page, scheduleName: string, userName: string): Promise<void> => {
// go to the schedules page
await goToOnCallPage(page, 'schedules');
// create an oncall-rotation schedule
await clickButton({ page, buttonText: 'New Schedule' });
(await page.waitForSelector('button >> text=Create >> nth=0')).click();
// fill in the name input
await fillInInput(page, 'div[class*="ScheduleForm"] input[name="name"]', scheduleName);
// Add a new layer w/ the current user to it
await clickButton({ page, buttonText: 'Create Schedule' });
await clickButton({ page, buttonText: 'Add rotation' });
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,
};
};