oncall-engine/grafana-plugin/integration-tests/users/viewUsers.test.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

34 lines
1.3 KiB
TypeScript

import { test, expect, Page } from '../fixtures';
import { goToOnCallPage } from '../utils/navigation';
test.describe('view list of users', () => {
const testFlow = async (page: Page, isAllowedToView = true): Promise<void> => {
await goToOnCallPage(page, 'users');
if (isAllowedToView) {
const usersTableElement = page.getByTestId('users-table');
await usersTableElement.waitFor({ state: 'visible' });
const userRowsContext = await usersTableElement.locator('tbody > tr').allTextContents();
expect(userRowsContext.length).toBeGreaterThan(0);
} else {
const missingPermissionsMessageElement = page.getByTestId('view-users-missing-permission-message');
await missingPermissionsMessageElement.waitFor({ state: 'visible' });
const missingPermissionMessage = await missingPermissionsMessageElement.textContent();
expect(missingPermissionMessage).toMatch(/You are missing the .* to be able to view OnCall users/);
}
};
test('admin is allowed to', async ({ adminRolePage }) => {
await testFlow(adminRolePage.page);
});
test('editor is allowed to', async ({ editorRolePage }) => {
await testFlow(editorRolePage.page);
});
test('viewer is not allowed to', async ({ viewerRolePage }) => {
await testFlow(viewerRolePage.page, false);
});
});