MCPcopy Index your code
hub / github.com/coder/coder / createUser

Function createUser

site/e2e/helpers.ts:1289–1350  ·  view source on GitHub ↗
(
	page: Page,
	userValues: Partial<UserValues> = {},
	orgName = defaultOrganizationName,
)

Source from the content-addressed store, hash-verified

1287};
1288
1289export async function createUser(
1290 page: Page,
1291 userValues: Partial<UserValues> = {},
1292 orgName = defaultOrganizationName,
1293): Promise<UserValues> {
1294 const returnTo = page.url();
1295
1296 await page.goto("/deployment/users", { waitUntil: "domcontentloaded" });
1297 await expect(page).toHaveTitle("Users - Coder");
1298
1299 await page.getByRole("link", { name: "Create user" }).click();
1300 await expect(page).toHaveTitle("Create User - Coder");
1301
1302 const username = userValues.username ?? randomName();
1303 const name = userValues.name ?? username;
1304 const email = userValues.email ?? `${username}@coder.com`;
1305 const password = userValues.password || defaultPassword;
1306 const roles = userValues.roles ?? [];
1307
1308 await page.getByLabel("Username").fill(username);
1309 if (name) {
1310 await page.getByLabel("Full name").fill(name);
1311 }
1312 await page.getByLabel("Email").fill(email);
1313
1314 // If the organization picker is present on the page, select the default
1315 // organization.
1316 const orgPicker = page.getByLabel("Organization *");
1317 const organizationsEnabled = await orgPicker.isVisible();
1318 if (organizationsEnabled) {
1319 // The organization picker will be disabled if there is only one option.
1320 const pickerIsDisabled = await orgPicker.isDisabled();
1321 if (!pickerIsDisabled) {
1322 await orgPicker.click();
1323 await page.getByText(orgName, { exact: true }).click();
1324 }
1325 }
1326
1327 await page.getByLabel("Login Type").click();
1328 await page.getByRole("option", { name: "Password", exact: false }).click();
1329 // Using input[name=password] due to the select element utilizing 'password'
1330 // as the label for the currently active option.
1331 const passwordField = page.locator("input[name=password]");
1332 await passwordField.fill(password);
1333 await page.getByRole("button", { name: /save/i }).click();
1334 await expect(page.getByText(/created successfully/)).toBeVisible();
1335
1336 await expect(page).toHaveTitle("Users - Coder");
1337 const addedRow = page.locator("tr", { hasText: email });
1338 await expect(addedRow).toBeVisible();
1339
1340 // Give them a role
1341 await addedRow.getByLabel("Open menu").click();
1342 await page.getByText("Edit roles").click();
1343 for (const role of roles) {
1344 await page.getByRole("dialog").getByText(role, { exact: true }).click();
1345 }
1346 await page.getByText("Confirm").click();

Calls 2

randomNameFunction · 0.85
urlMethod · 0.65

Tested by

no test coverage detected