-
Notifications
You must be signed in to change notification settings - Fork 901
feat: create e2e tests for organization custom roles page #15814
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
Changes from 8 commits
c2268e4
ab42630
1ef60fc
1c16357
eae7fae
992c579
6330959
6723ce8
d5ca1b0
4a8a8a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
import { expect, test } from "@playwright/test"; | ||
import { | ||
createCustomRole, | ||
createOrganizationWithName, | ||
deleteOrganization, | ||
setupApiCalls, | ||
} from "../../../api"; | ||
import { noPremiumLicense, requiresLicense } from "../../../helpers"; | ||
import { beforeCoderTest } from "../../../hooks"; | ||
|
||
test.describe("CustomRolesPage", () => { | ||
test.beforeEach(async ({ page }) => await beforeCoderTest(page)); | ||
|
||
test("create custom role and cancel edit changes", async ({ page }) => { | ||
requiresLicense(); | ||
await setupApiCalls(page); | ||
|
||
const org = await createOrganizationWithName("developers"); | ||
|
||
const customRole = await createCustomRole( | ||
org.id, | ||
"custom-role-test-1", | ||
"Custom Role Test 1", | ||
); | ||
|
||
await page.goto(`/organizations/${org.name}/roles`); | ||
const roleRow = page.getByTestId(`role-${customRole.name}`); | ||
await expect(roleRow.getByText(customRole.display_name)).toBeVisible(); | ||
await expect(roleRow.getByText("organization_member")).toBeVisible(); | ||
|
||
await roleRow.getByRole("button", { name: "More options" }).click(); | ||
const menu = page.locator("#more-options"); | ||
await menu.getByText("Edit").click(); | ||
|
||
await expect(page).toHaveURL( | ||
`/organizations/${org.name}/roles/${customRole.name}`, | ||
); | ||
|
||
const cancelButton = page.getByRole("button", { name: "Cancel" }).first(); | ||
await expect(cancelButton).toBeVisible(); | ||
await cancelButton.click(); | ||
|
||
await expect(page).toHaveURL(`/organizations/${org.name}/roles`); | ||
|
||
await deleteOrganization("developers"); | ||
}); | ||
|
||
test("create custom role, edit role and save changes", async ({ page }) => { | ||
requiresLicense(); | ||
await setupApiCalls(page); | ||
|
||
const org = await createOrganizationWithName("users"); | ||
|
||
const customRole = await createCustomRole( | ||
org.id, | ||
"custom-role-test-1", | ||
"Custom Role Test 1", | ||
); | ||
|
||
await page.goto(`/organizations/${org.name}/roles`); | ||
const roleRow = page.getByTestId(`role-${customRole.name}`); | ||
await expect(roleRow.getByText(customRole.display_name)).toBeVisible(); | ||
await expect(roleRow.getByText("organization_member")).toBeVisible(); | ||
|
||
await page.goto(`/organizations/${org.name}/roles/${customRole.name}`); | ||
|
||
const displayNameInput = page.getByRole("textbox", { | ||
name: "Display name", | ||
}); | ||
await displayNameInput.fill("Custom Role Test 2 Edited"); | ||
|
||
const groupCheckbox = page.getByTestId("group").getByRole("checkbox"); | ||
await expect(groupCheckbox).toBeVisible(); | ||
await groupCheckbox.click(); | ||
|
||
const organizationMemberCheckbox = page | ||
.getByTestId("organization_member") | ||
.getByRole("checkbox"); | ||
await expect(organizationMemberCheckbox).toBeVisible(); | ||
await organizationMemberCheckbox.click(); | ||
|
||
const saveButton = page.getByRole("button", { name: "Save" }).first(); | ||
await expect(saveButton).toBeVisible(); | ||
await saveButton.click(); | ||
|
||
await expect(roleRow.getByText("Custom Role Test 2 Edited")).toBeVisible(); | ||
|
||
const roleRow2 = page.getByTestId(`role-${customRole.name}`); | ||
await expect(roleRow2.getByText("organization_member")).not.toBeVisible(); | ||
await expect(roleRow2.getByText("group")).toBeVisible(); | ||
|
||
await expect(page).toHaveURL(`/organizations/${org.name}/roles`); | ||
|
||
await deleteOrganization("users"); | ||
}); | ||
|
||
test("displays built-in role without edit/delete options", async ({ | ||
page, | ||
}) => { | ||
requiresLicense(); | ||
await setupApiCalls(page); | ||
|
||
const org = await createOrganizationWithName("testers"); | ||
|
||
await page.goto(`/organizations/${org.name}/roles`); | ||
|
||
const roleRow = page.getByTestId("role-organization-admin"); | ||
await expect(roleRow).toBeVisible(); | ||
|
||
await expect(roleRow.getByText("Organization Admin")).toBeVisible(); | ||
|
||
// Verify that the more menu (three dots) is not present for built-in roles | ||
await expect( | ||
roleRow.getByRole("button", { name: "More options" }), | ||
).not.toBeVisible(); | ||
|
||
await deleteOrganization("testers"); | ||
}); | ||
|
||
test("create custom role with UI", async ({ page }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not make this a helper and call it from the other test rather than using the api? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have actually been going the route of having 2 different types of tests, one that starts with a change using the api and then completing the test through the UI and then another that does the same thing through the UI. I think there is the potential catching edge cases through this way of testing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aslilac Looking around at many of the existing tests, I see this pattern when the same things to happen for many tests, for example creating a template, the API is used but then atleast one test would do the same thing through the UI if possible. I feel like this many be a bit more performant than going through the UI for every test. The except would be if there are many variations of path the user could take through the UI. |
||
requiresLicense(); | ||
await setupApiCalls(page); | ||
|
||
const org = await createOrganizationWithName("contractors"); | ||
|
||
await page.goto(`/organizations/${org.name}/roles`); | ||
|
||
await page | ||
.getByRole("link", { name: "Create custom role" }) | ||
.first() | ||
.click(); | ||
|
||
await expect(page).toHaveURL(`/organizations/${org.name}/roles/create`); | ||
|
||
const customRoleName = "custom-role-test"; | ||
const roleNameInput = page.getByRole("textbox", { | ||
exact: true, | ||
name: "Name", | ||
}); | ||
await roleNameInput.fill(customRoleName); | ||
|
||
const customRoleDisplayName = "Custom Role Test"; | ||
const displayNameInput = page.getByRole("textbox", { | ||
exact: true, | ||
name: "Display Name", | ||
}); | ||
await displayNameInput.fill(customRoleDisplayName); | ||
|
||
await page.getByRole("button", { name: "Create Role" }).first().click(); | ||
|
||
await expect(page).toHaveURL(`/organizations/${org.name}/roles`); | ||
|
||
const roleRow = page.getByTestId(`role-${customRoleName}`); | ||
await expect(roleRow.getByText(customRoleDisplayName)).toBeVisible(); | ||
await expect(roleRow.getByText("None")).toBeVisible(); | ||
|
||
await deleteOrganization("contractors"); | ||
}); | ||
|
||
test("delete custom role", async ({ page }) => { | ||
requiresLicense(); | ||
await setupApiCalls(page); | ||
|
||
const org = await createOrganizationWithName("custom1"); | ||
const customRole = await createCustomRole( | ||
org.id, | ||
"custom-role-test-1", | ||
"Custom Role Test 1", | ||
); | ||
await page.goto(`/organizations/${org.name}/roles`); | ||
|
||
const roleRow = page.getByTestId(`role-${customRole.name}`); | ||
await roleRow.getByRole("button", { name: "More options" }).click(); | ||
|
||
const menu = page.locator("#more-options"); | ||
await menu.getByText("Delete…").click(); | ||
|
||
const input = page.getByRole("textbox"); | ||
await input.fill(customRole.name); | ||
await page.getByRole("button", { name: "Delete" }).click(); | ||
|
||
await expect( | ||
page.getByText("Custom role deleted successfully!"), | ||
).toBeVisible(); | ||
|
||
await deleteOrganization("custom1"); | ||
}); | ||
}); | ||
|
||
test("custom roles disabled", async ({ page }) => { | ||
noPremiumLicense(); | ||
await page.goto("/organizations/coder/roles"); | ||
await expect(page).toHaveURL("/organizations/coder/roles"); | ||
|
||
await expect( | ||
page.getByText("Upgrade to a premium license to create a custom role"), | ||
).toBeVisible(); | ||
await expect( | ||
page.getByRole("link", { name: "Create custom role" }), | ||
).not.toBeVisible(); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.