Skip to content

chore: add e2e tests for template permissions #12731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion site/e2e/global.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Language } from "pages/CreateUserPage/CreateUserForm";
import * as constants from "./constants";
import { storageState } from "./playwright.config";

test("setup first user", async ({ page }) => {
test("setup deployment", async ({ page }) => {
await page.goto("/", { waitUntil: "domcontentloaded" });

// Setup first user
Expand Down
15 changes: 15 additions & 0 deletions site/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ export const createTemplate = async (
return name;
};

// createGroup navigates to the /groups/create page and creates a group with a
// random name.
export const createGroup = async (page: Page): Promise<string> => {
await page.goto("/groups/create", { waitUntil: "domcontentloaded" });
await expect(page).toHaveURL("/groups/create");

const name = randomName();
await page.getByLabel("Name", { exact: true }).fill(name);
await page.getByTestId("form-submit").click();
await expect(page).toHaveURL(
/\/groups\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,
);
return name;
};

// sshIntoWorkspace spawns a Coder SSH process and a client connected to it.
export const sshIntoWorkspace = async (
page: Page,
Expand Down
2 changes: 1 addition & 1 deletion site/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default defineConfig({
testMatch: /.*\.spec\.ts/,
dependencies: ["testsSetup"],
use: { storageState },
timeout: 60_000,
timeout: 20_000,
},
],
reporter: [["./reporter.ts"]],
Expand Down
27 changes: 27 additions & 0 deletions site/e2e/tests/updateTemplate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from "@playwright/test";
import {
createGroup,
createTemplate,
requiresEnterpriseLicense,
updateTemplateSettings,
Expand All @@ -15,6 +16,32 @@ test("template update with new name redirects on successful submit", async ({
});
});

test("add and remove a group", async ({ page }) => {
requiresEnterpriseLicense();

const templateName = await createTemplate(page);
const groupName = await createGroup(page);

await page.goto(`/templates/${templateName}/settings/permissions`, {
waitUntil: "domcontentloaded",
});
await expect(page).toHaveURL(
`/templates/${templateName}/settings/permissions`,
);

// Type the first half of the group name
await page
.getByPlaceholder("Search for user or group", { exact: true })
.fill(groupName.slice(0, 4));

// Select the group from the list and add it
await page.getByText(groupName).click();
await page.getByText("Add member").click();
await expect(
page.locator(".MuiTable-root").getByText(groupName),
).toBeVisible();
});

test("require latest version", async ({ page }) => {
requiresEnterpriseLicense();

Expand Down