|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { |
| 3 | + createGroup, |
| 4 | + createOrganization, |
| 5 | + createUser, |
| 6 | + setupApiCalls, |
| 7 | +} from "../api"; |
| 8 | +import { expectUrl } from "../expectUrl"; |
| 9 | +import { randomName, requiresLicense } from "../helpers"; |
| 10 | +import { beforeCoderTest } from "../hooks"; |
| 11 | + |
| 12 | +test.beforeEach(async ({ page }) => { |
| 13 | + await beforeCoderTest(page); |
| 14 | + await setupApiCalls(page); |
| 15 | +}); |
| 16 | + |
| 17 | +test("create group", async ({ page }) => { |
| 18 | + requiresLicense(); |
| 19 | + |
| 20 | + // Create a new organization |
| 21 | + const org = await createOrganization(); |
| 22 | + await page.goto(`/organizations/${org.name}`); |
| 23 | + |
| 24 | + // Navigate to groups page |
| 25 | + await page.getByText("Groups").click(); |
| 26 | + await expect(page).toHaveTitle(`Groups - Org ${org.name} - Coder`); |
| 27 | + |
| 28 | + // Create a new group |
| 29 | + await page.getByText("Create group").click(); |
| 30 | + await expect(page).toHaveTitle("Create Group - Coder"); |
| 31 | + const name = randomName(); |
| 32 | + await page.getByLabel("Name", { exact: true }).fill(name); |
| 33 | + const displayName = `Group ${name}`; |
| 34 | + await page.getByLabel("Display Name").fill(displayName); |
| 35 | + await page.getByLabel("Avatar URL").fill("/emojis/1f60d.png"); |
| 36 | + await page.getByRole("button", { name: "Submit" }).click(); |
| 37 | + |
| 38 | + await expectUrl(page).toHavePathName( |
| 39 | + `/organizations/${org.name}/groups/${name}`, |
| 40 | + ); |
| 41 | + await expect(page).toHaveTitle(`${displayName} - Coder`); |
| 42 | + await expect(page.getByText("No members yet")).toBeVisible(); |
| 43 | + await expect(page.getByText(displayName)).toBeVisible(); |
| 44 | + |
| 45 | + // Add a user to the group |
| 46 | + const personToAdd = await createUser(org.id); |
| 47 | + await page.getByPlaceholder("User email or username").fill(personToAdd.email); |
| 48 | + await page.getByRole("option", { name: personToAdd.email }).click(); |
| 49 | + await page.getByRole("button", { name: "Add user" }).click(); |
| 50 | + const addedRow = page.locator("tr", { hasText: personToAdd.email }); |
| 51 | + await expect(addedRow).toBeVisible(); |
| 52 | + |
| 53 | + // Ensure we can't add a user who isn't in the org |
| 54 | + const otherOrg = await createOrganization(); |
| 55 | + const personToReject = await createUser(otherOrg.id); |
| 56 | + await page |
| 57 | + .getByPlaceholder("User email or username") |
| 58 | + .fill(personToReject.email); |
| 59 | + await expect(page.getByText("No users found")).toBeVisible(); |
| 60 | + |
| 61 | + // Remove someone from the group |
| 62 | + await addedRow.getByLabel("More options").click(); |
| 63 | + await page.getByText("Remove").click(); |
| 64 | + await expect(addedRow).not.toBeVisible(); |
| 65 | + |
| 66 | + // Delete the group |
| 67 | + await page.getByRole("button", { name: "Delete" }).click(); |
| 68 | + const dialog = page.getByTestId("dialog"); |
| 69 | + await dialog.getByLabel("Name of the group to delete").fill(name); |
| 70 | + await dialog.getByRole("button", { name: "Delete" }).click(); |
| 71 | + await expect(page.getByText("Group deleted successfully.")).toBeVisible(); |
| 72 | + |
| 73 | + await expectUrl(page).toHavePathName(`/organizations/${org.name}/groups`); |
| 74 | + await expect(page).toHaveTitle(`Groups - Org ${org.name} - Coder`); |
| 75 | +}); |
| 76 | + |
| 77 | +test("change quota settings", async ({ page }) => { |
| 78 | + requiresLicense(); |
| 79 | + |
| 80 | + // Create a new organization and group |
| 81 | + const org = await createOrganization(); |
| 82 | + const group = await createGroup(org.id); |
| 83 | + |
| 84 | + // Go to settings |
| 85 | + await page.goto(`/organizations/${org.name}/groups/${group.name}`); |
| 86 | + await page.getByRole("button", { name: "Settings" }).click(); |
| 87 | + expectUrl(page).toHavePathName( |
| 88 | + `/organizations/${org.name}/groups/${group.name}/settings`, |
| 89 | + ); |
| 90 | + |
| 91 | + // Update Quota |
| 92 | + await page.getByLabel("Quota Allowance").fill("100"); |
| 93 | + await page.getByRole("button", { name: "Submit" }).click(); |
| 94 | + |
| 95 | + // We should get sent back to the group page afterwards |
| 96 | + expectUrl(page).toHavePathName( |
| 97 | + `/organizations/${org.name}/groups/${group.name}`, |
| 98 | + ); |
| 99 | + |
| 100 | + // ...and that setting should persist if we go back |
| 101 | + await page.getByRole("button", { name: "Settings" }).click(); |
| 102 | + await expect(page.getByLabel("Quota Allowance")).toHaveValue("100"); |
| 103 | +}); |
0 commit comments