chore: use user admin and template admin for even more e2e tests (#16974)

This commit is contained in:
ケイラ
2025-03-18 09:11:39 -06:00
committed by GitHub
parent 49a35e3784
commit cb19fd47b0
11 changed files with 139 additions and 132 deletions
+7 -4
View File
@@ -267,9 +267,8 @@ export const createTemplate = async (
);
}
// picker is disabled if only one org is available
// The organization picker will be disabled if there is only one option.
const pickerIsDisabled = await orgPicker.isDisabled();
if (!pickerIsDisabled) {
await orgPicker.click();
await page.getByText(orgName, { exact: true }).click();
@@ -1094,8 +1093,12 @@ export async function createUser(
const orgPicker = page.getByLabel("Organization *");
const organizationsEnabled = await orgPicker.isVisible();
if (organizationsEnabled) {
await orgPicker.click();
await page.getByText(orgName, { exact: true }).click();
// The organization picker will be disabled if there is only one option.
const pickerIsDisabled = await orgPicker.isDisabled();
if (!pickerIsDisabled) {
await orgPicker.click();
await page.getByText(orgName, { exact: true }).click();
}
}
await page.getByLabel("Login Type").click();
+100 -87
View File
@@ -1,10 +1,11 @@
import { type Page, expect, test } from "@playwright/test";
import { users } from "../constants";
import { defaultPassword, users } from "../constants";
import {
createTemplate,
createUser,
createWorkspace,
currentUser,
login,
randomName,
requiresLicense,
} from "../helpers";
import { beforeCoderTest } from "../hooks";
@@ -15,6 +16,14 @@ test.beforeEach(async ({ page }) => {
beforeCoderTest(page);
});
const name = randomName();
const userToAudit = {
username: `peep-${name}`,
password: defaultPassword,
email: `peep-${name}@coder.com`,
roles: ["Template Admin", "User Admin"],
};
async function resetSearch(page: Page, username: string) {
const clearButton = page.getByLabel("Clear search");
if (await clearButton.isVisible()) {
@@ -27,92 +36,96 @@ async function resetSearch(page: Page, username: string) {
await expect(page.getByText("All users")).not.toBeVisible();
}
test("logins are logged", async ({ page }) => {
test.describe("audit logs", () => {
requiresLicense();
// Go to the audit history
await login(page, users.auditor);
await page.goto("/audit");
const username = users.auditor.username;
const loginMessage = `${username} logged in`;
// Make sure those things we did all actually show up
await resetSearch(page, username);
await expect(page.getByText(loginMessage).first()).toBeVisible();
});
test("creating templates and workspaces is logged", async ({ page }) => {
requiresLicense();
// Do some stuff that should show up in the audit logs
await login(page, users.templateAdmin);
const username = users.templateAdmin.username;
const templateName = await createTemplate(page);
const workspaceName = await createWorkspace(page, templateName);
// Go to the audit history
await login(page, users.auditor);
await page.goto("/audit");
// Make sure those things we did all actually show up
await resetSearch(page, username);
await expect(
page.getByText(`${username} created template ${templateName}`),
).toBeVisible();
await expect(
page.getByText(`${username} created workspace ${workspaceName}`),
).toBeVisible();
await expect(
page.getByText(`${username} started workspace ${workspaceName}`),
).toBeVisible();
// Make sure we can inspect the details of the log item
const createdWorkspace = page.locator(".MuiTableRow-root", {
hasText: `${username} created workspace ${workspaceName}`,
test.beforeAll(async ({ browser }) => {
const context = await browser.newContext();
const page = await context.newPage();
await login(page);
await createUser(page, userToAudit);
});
test("logins are logged", async ({ page }) => {
// Go to the audit history
await login(page, users.auditor);
await page.goto("/audit");
// Make sure those things we did all actually show up
await resetSearch(page, users.auditor.username);
const loginMessage = `${users.auditor.username} logged in`;
await expect(page.getByText(loginMessage).first()).toBeVisible();
});
test("creating templates and workspaces is logged", async ({ page }) => {
// Do some stuff that should show up in the audit logs
await login(page, userToAudit);
const username = userToAudit.username;
const templateName = await createTemplate(page);
const workspaceName = await createWorkspace(page, templateName);
// Go to the audit history
await login(page, users.auditor);
await page.goto("/audit");
// Make sure those things we did all actually show up
await resetSearch(page, username);
await expect(
page.getByText(`${username} created template ${templateName}`),
).toBeVisible();
await expect(
page.getByText(`${username} created workspace ${workspaceName}`),
).toBeVisible();
await expect(
page.getByText(`${username} started workspace ${workspaceName}`),
).toBeVisible();
// Make sure we can inspect the details of the log item
const createdWorkspace = page.locator(".MuiTableRow-root", {
hasText: `${username} created workspace ${workspaceName}`,
});
await createdWorkspace.getByLabel("open-dropdown").click();
await expect(
createdWorkspace.getByText(`automatic_updates: "never"`),
).toBeVisible();
await expect(
createdWorkspace.getByText(`name: "${workspaceName}"`),
).toBeVisible();
});
test("inspecting and filtering audit logs", async ({ page }) => {
// Do some stuff that should show up in the audit logs
await login(page, userToAudit);
const username = userToAudit.username;
const templateName = await createTemplate(page);
const workspaceName = await createWorkspace(page, templateName);
// Go to the audit history
await login(page, users.auditor);
await page.goto("/audit");
const loginMessage = `${username} logged in`;
const startedWorkspaceMessage = `${username} started workspace ${workspaceName}`;
// Filter by resource type
await resetSearch(page, username);
await page.getByText("All resource types").click();
const workspaceBuildsOption = page.getByText("Workspace Build");
await workspaceBuildsOption.scrollIntoViewIfNeeded({ timeout: 5000 });
await workspaceBuildsOption.click();
// Our workspace build should be visible
await expect(page.getByText(startedWorkspaceMessage)).toBeVisible();
// Logins should no longer be visible
await expect(page.getByText(loginMessage)).not.toBeVisible();
await page.getByLabel("Clear search").click();
await expect(page.getByText("All resource types")).toBeVisible();
// Filter by action type
await resetSearch(page, username);
await page.getByText("All actions").click();
await page.getByText("Login", { exact: true }).click();
// Logins should be visible
await expect(page.getByText(loginMessage).first()).toBeVisible();
// Our workspace build should no longer be visible
await expect(page.getByText(startedWorkspaceMessage)).not.toBeVisible();
});
await createdWorkspace.getByLabel("open-dropdown").click();
await expect(
createdWorkspace.getByText(`automatic_updates: "never"`),
).toBeVisible();
await expect(
createdWorkspace.getByText(`name: "${workspaceName}"`),
).toBeVisible();
});
test("inspecting and filtering audit logs", async ({ page }) => {
requiresLicense();
// Do some stuff that should show up in the audit logs
await login(page, users.templateAdmin);
const username = users.templateAdmin.username;
const templateName = await createTemplate(page);
const workspaceName = await createWorkspace(page, templateName);
// Go to the audit history
await login(page, users.auditor);
await page.goto("/audit");
const loginMessage = `${username} logged in`;
const startedWorkspaceMessage = `${username} started workspace ${workspaceName}`;
// Filter by resource type
await resetSearch(page, username);
await page.getByText("All resource types").click();
const workspaceBuildsOption = page.getByText("Workspace Build");
await workspaceBuildsOption.scrollIntoViewIfNeeded({ timeout: 5000 });
await workspaceBuildsOption.click();
// Our workspace build should be visible
await expect(page.getByText(startedWorkspaceMessage)).toBeVisible();
// Logins should no longer be visible
await expect(page.getByText(loginMessage)).not.toBeVisible();
await page.getByLabel("Clear search").click();
await expect(page.getByText("All resource types")).toBeVisible();
// Filter by action type
await resetSearch(page, username);
await page.getByText("All actions").click();
await page.getByText("Login", { exact: true }).click();
// Logins should be visible
await expect(page.getByText(loginMessage).first()).toBeVisible();
// Our workspace build should no longer be visible
await expect(page.getByText(startedWorkspaceMessage)).not.toBeVisible();
});
+6 -15
View File
@@ -5,8 +5,8 @@ import {
deleteOrganization,
setupApiCalls,
} from "../../api";
import { randomName, requiresLicense } from "../../helpers";
import { login } from "../../helpers";
import { users } from "../../constants";
import { login, randomName, requiresLicense } from "../../helpers";
import { beforeCoderTest } from "../../hooks";
test.beforeEach(async ({ page }) => {
@@ -15,13 +15,14 @@ test.beforeEach(async ({ page }) => {
await setupApiCalls(page);
});
test.describe("IdpOrgSyncPage", () => {
test.describe("IdP organization sync", () => {
requiresLicense();
test.describe.configure({ retries: 1 });
test("show empty table when no org mappings are present", async ({
page,
}) => {
requiresLicense();
await page.goto("/deployment/idp-org-sync", {
waitUntil: "domcontentloaded",
});
@@ -35,8 +36,6 @@ test.describe("IdpOrgSyncPage", () => {
});
test("add new IdP organization mapping with API", async ({ page }) => {
requiresLicense();
await createOrganizationSyncSettings();
await page.goto("/deployment/idp-org-sync", {
@@ -59,7 +58,6 @@ test.describe("IdpOrgSyncPage", () => {
});
test("delete a IdP org to coder org mapping row", async ({ page }) => {
requiresLicense();
await createOrganizationSyncSettings();
await page.goto("/deployment/idp-org-sync", {
waitUntil: "domcontentloaded",
@@ -77,7 +75,6 @@ test.describe("IdpOrgSyncPage", () => {
});
test("update sync field", async ({ page }) => {
requiresLicense();
await page.goto("/deployment/idp-org-sync", {
waitUntil: "domcontentloaded",
});
@@ -100,7 +97,6 @@ test.describe("IdpOrgSyncPage", () => {
});
test("toggle off default organization assignment", async ({ page }) => {
requiresLicense();
await page.goto("/deployment/idp-org-sync", {
waitUntil: "domcontentloaded",
});
@@ -126,8 +122,6 @@ test.describe("IdpOrgSyncPage", () => {
test("export policy button is enabled when sync settings are present", async ({
page,
}) => {
requiresLicense();
await page.goto("/deployment/idp-org-sync", {
waitUntil: "domcontentloaded",
});
@@ -140,10 +134,7 @@ test.describe("IdpOrgSyncPage", () => {
});
test("add new IdP organization mapping with UI", async ({ page }) => {
requiresLicense();
const orgName = randomName();
await createOrganizationWithName(orgName);
await page.goto("/deployment/idp-org-sync", {
@@ -172,7 +163,7 @@ test.describe("IdpOrgSyncPage", () => {
await orgSelector.click();
await page.waitForTimeout(1000);
const option = await page.getByRole("option", { name: orgName });
const option = page.getByRole("option", { name: orgName });
await expect(option).toBeAttached({ timeout: 30000 });
await expect(option).toBeVisible();
await option.click();
+3 -4
View File
@@ -5,14 +5,13 @@ import {
getCurrentOrgId,
setupApiCalls,
} from "../../api";
import { defaultOrganizationName } from "../../constants";
import { requiresLicense } from "../../helpers";
import { login } from "../../helpers";
import { defaultOrganizationName, users } from "../../constants";
import { login, requiresLicense } from "../../helpers";
import { beforeCoderTest } from "../../hooks";
test.beforeEach(async ({ page }) => {
beforeCoderTest(page);
await login(page);
await login(page, users.userAdmin);
await setupApiCalls(page);
});
@@ -1,13 +1,12 @@
import { expect, test } from "@playwright/test";
import { createUser, getCurrentOrgId, setupApiCalls } from "../../api";
import { defaultOrganizationName } from "../../constants";
import { requiresLicense } from "../../helpers";
import { login } from "../../helpers";
import { defaultOrganizationName, users } from "../../constants";
import { login, requiresLicense } from "../../helpers";
import { beforeCoderTest } from "../../hooks";
test.beforeEach(async ({ page }) => {
beforeCoderTest(page);
await login(page);
await login(page, users.userAdmin);
});
const DEFAULT_GROUP_NAME = "Everyone";
+3 -4
View File
@@ -1,12 +1,11 @@
import { expect, test } from "@playwright/test";
import { defaultOrganizationName } from "../../constants";
import { randomName, requiresLicense } from "../../helpers";
import { login } from "../../helpers";
import { defaultOrganizationName, users } from "../../constants";
import { login, randomName, requiresLicense } from "../../helpers";
import { beforeCoderTest } from "../../hooks";
test.beforeEach(async ({ page }) => {
beforeCoderTest(page);
await login(page);
await login(page, users.userAdmin);
});
test("create group", async ({ page, baseURL }) => {
+3 -4
View File
@@ -1,13 +1,12 @@
import { expect, test } from "@playwright/test";
import { createGroup, getCurrentOrgId, setupApiCalls } from "../../api";
import { defaultOrganizationName } from "../../constants";
import { requiresLicense } from "../../helpers";
import { login } from "../../helpers";
import { defaultOrganizationName, users } from "../../constants";
import { login, requiresLicense } from "../../helpers";
import { beforeCoderTest } from "../../hooks";
test.beforeEach(async ({ page }) => {
beforeCoderTest(page);
await login(page);
await login(page, users.userAdmin);
await setupApiCalls(page);
});
+3 -4
View File
@@ -6,14 +6,13 @@ import {
getCurrentOrgId,
setupApiCalls,
} from "../../api";
import { defaultOrganizationName } from "../../constants";
import { requiresLicense } from "../../helpers";
import { login } from "../../helpers";
import { defaultOrganizationName, users } from "../../constants";
import { login, requiresLicense } from "../../helpers";
import { beforeCoderTest } from "../../hooks";
test.beforeEach(async ({ page }) => {
beforeCoderTest(page);
await login(page);
await login(page, users.userAdmin);
await setupApiCalls(page);
});
@@ -1,10 +1,11 @@
import { expect, test } from "@playwright/test";
import { users } from "../../constants";
import { login } from "../../helpers";
import { beforeCoderTest } from "../../hooks";
test.beforeEach(async ({ page }) => {
beforeCoderTest(page);
await login(page);
await login(page, users.templateAdmin);
});
test("list templates", async ({ page, baseURL }) => {
@@ -1,12 +1,13 @@
import { expect, test } from "@playwright/test";
import { API } from "api/api";
import { getCurrentOrgId, setupApiCalls } from "../../api";
import { users } from "../../constants";
import { login } from "../../helpers";
import { beforeCoderTest } from "../../hooks";
test.beforeEach(async ({ page }) => {
beforeCoderTest(page);
await login(page);
await login(page, users.templateAdmin);
await setupApiCalls(page);
});
+7 -4
View File
@@ -1,20 +1,20 @@
import { expect, test } from "@playwright/test";
import { defaultOrganizationName } from "../constants";
import { defaultOrganizationName, users } from "../constants";
import { expectUrl } from "../expectUrl";
import {
createGroup,
createTemplate,
login,
requiresLicense,
updateTemplateSettings,
} from "../helpers";
import { login } from "../helpers";
import { beforeCoderTest } from "../hooks";
test.describe.configure({ mode: "parallel" });
test.beforeEach(async ({ page }) => {
beforeCoderTest(page);
await login(page);
await login(page, users.templateAdmin);
});
test("template update with new name redirects on successful submit", async ({
@@ -29,10 +29,13 @@ test("template update with new name redirects on successful submit", async ({
test("add and remove a group", async ({ page }) => {
requiresLicense();
await login(page, users.userAdmin);
const orgName = defaultOrganizationName;
const templateName = await createTemplate(page);
const groupName = await createGroup(page, orgName);
await login(page, users.templateAdmin);
const templateName = await createTemplate(page);
await page.goto(
`/templates/${orgName}/${templateName}/settings/permissions`,
{ waitUntil: "domcontentloaded" },