Skip to content

Commit 1d2d008

Browse files
authored
chore: add e2e tests for template permissions (#12731)
1 parent eeb3d63 commit 1d2d008

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

site/e2e/global.setup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Language } from "pages/CreateUserPage/CreateUserForm";
33
import * as constants from "./constants";
44
import { storageState } from "./playwright.config";
55

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

99
// Setup first user

site/e2e/helpers.ts

+15
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,21 @@ export const createTemplate = async (
150150
return name;
151151
};
152152

153+
// createGroup navigates to the /groups/create page and creates a group with a
154+
// random name.
155+
export const createGroup = async (page: Page): Promise<string> => {
156+
await page.goto("/groups/create", { waitUntil: "domcontentloaded" });
157+
await expect(page).toHaveURL("/groups/create");
158+
159+
const name = randomName();
160+
await page.getByLabel("Name", { exact: true }).fill(name);
161+
await page.getByTestId("form-submit").click();
162+
await expect(page).toHaveURL(
163+
/\/groups\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,
164+
);
165+
return name;
166+
};
167+
153168
// sshIntoWorkspace spawns a Coder SSH process and a client connected to it.
154169
export const sshIntoWorkspace = async (
155170
page: Page,

site/e2e/playwright.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default defineConfig({
2222
testMatch: /.*\.spec\.ts/,
2323
dependencies: ["testsSetup"],
2424
use: { storageState },
25-
timeout: 60_000,
25+
timeout: 20_000,
2626
},
2727
],
2828
reporter: [["./reporter.ts"]],

site/e2e/tests/updateTemplate.spec.ts

+27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect, test } from "@playwright/test";
22
import {
3+
createGroup,
34
createTemplate,
45
requiresEnterpriseLicense,
56
updateTemplateSettings,
@@ -15,6 +16,32 @@ test("template update with new name redirects on successful submit", async ({
1516
});
1617
});
1718

19+
test("add and remove a group", async ({ page }) => {
20+
requiresEnterpriseLicense();
21+
22+
const templateName = await createTemplate(page);
23+
const groupName = await createGroup(page);
24+
25+
await page.goto(`/templates/${templateName}/settings/permissions`, {
26+
waitUntil: "domcontentloaded",
27+
});
28+
await expect(page).toHaveURL(
29+
`/templates/${templateName}/settings/permissions`,
30+
);
31+
32+
// Type the first half of the group name
33+
await page
34+
.getByPlaceholder("Search for user or group", { exact: true })
35+
.fill(groupName.slice(0, 4));
36+
37+
// Select the group from the list and add it
38+
await page.getByText(groupName).click();
39+
await page.getByText("Add member").click();
40+
await expect(
41+
page.locator(".MuiTable-root").getByText(groupName),
42+
).toBeVisible();
43+
});
44+
1845
test("require latest version", async ({ page }) => {
1946
requiresEnterpriseLicense();
2047

0 commit comments

Comments
 (0)