- Notifications
You must be signed in to change notification settings - Fork928
chore(site): add e2e tests for groups#12866
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
11 commits Select commitHold shift + click to select a range
f9c376c
Add create group test
BrunoQuaresma89237fc
Add remove group test
BrunoQuaresma438aa6f
Add add members test
BrunoQuaresmac643c6a
Add test to remove member
BrunoQuaresma23dd879
Add missing test
BrunoQuaresma6111994
Fix user test
BrunoQuaresma5d2b96e
Fix create group test
BrunoQuaresmabefe669
Fix navigate test
BrunoQuaresma8b0bdd9
Add check for enterprise license in the groups tests
BrunoQuaresma3b260c8
Add everyone test
BrunoQuaresma128abda
Merge branch 'main' of https://github.com/coder/coder into bq/add-e2e…
BrunoQuaresmaFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
45 changes: 45 additions & 0 deletionssite/e2e/api.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { Page } from "@playwright/test"; | ||
import * as API from "api/api"; | ||
import { coderPort } from "./constants"; | ||
import { findSessionToken, randomName } from "./helpers"; | ||
let currentOrgId: string; | ||
export const setupApiCalls = async (page: Page) => { | ||
const token = await findSessionToken(page); | ||
API.setSessionToken(token); | ||
API.setHost(`http://127.0.0.1:${coderPort}`); | ||
}; | ||
export const getCurrentOrgId = async (): Promise<string> => { | ||
if (currentOrgId) { | ||
return currentOrgId; | ||
} | ||
const currentUser = await API.getAuthenticatedUser(); | ||
currentOrgId = currentUser.organization_ids[0]; | ||
return currentOrgId; | ||
}; | ||
export const createUser = async (orgId: string) => { | ||
const name = randomName(); | ||
const user = await API.createUser({ | ||
email: `${name}@coder.com`, | ||
username: name, | ||
password: "s3cure&password!", | ||
login_type: "password", | ||
disable_login: false, | ||
organization_id: orgId, | ||
}); | ||
return user; | ||
}; | ||
export const createGroup = async (orgId: string) => { | ||
const name = randomName(); | ||
const group = await API.createGroup(orgId, { | ||
name, | ||
display_name: `Display ${name}`, | ||
avatar_url: "/emojis/1f60d.png", | ||
quota_allowance: 0, | ||
}); | ||
return group; | ||
}; |
7 changes: 0 additions & 7 deletionssite/e2e/helpers.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletionssite/e2e/tests/groups/addMembers.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { | ||
createGroup, | ||
createUser, | ||
getCurrentOrgId, | ||
setupApiCalls, | ||
} from "../../api"; | ||
import { requiresEnterpriseLicense } from "../../helpers"; | ||
import { beforeCoderTest } from "../../hooks"; | ||
test.beforeEach(async ({ page }) => await beforeCoderTest(page)); | ||
test("add members", async ({ page, baseURL }) => { | ||
requiresEnterpriseLicense(); | ||
await setupApiCalls(page); | ||
const orgId = await getCurrentOrgId(); | ||
const group = await createGroup(orgId); | ||
const numberOfMembers = 3; | ||
const users = await Promise.all( | ||
Array.from({ length: numberOfMembers }, () => createUser(orgId)), | ||
); | ||
await page.goto(`${baseURL}/groups/${group.id}`, { | ||
waitUntil: "domcontentloaded", | ||
}); | ||
await expect(page).toHaveTitle(`${group.display_name} - Coder`); | ||
for (const user of users) { | ||
await page.getByPlaceholder("User email or username").fill(user.username); | ||
await page.getByRole("option", { name: user.email }).click(); | ||
await page.getByRole("button", { name: "Add user" }).click(); | ||
await expect(page.getByRole("row", { name: user.username })).toBeVisible(); | ||
} | ||
}); |
32 changes: 32 additions & 0 deletionssite/e2e/tests/groups/addUsersToDefaultGroup.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { createUser, getCurrentOrgId, setupApiCalls } from "../../api"; | ||
import { requiresEnterpriseLicense } from "../../helpers"; | ||
import { beforeCoderTest } from "../../hooks"; | ||
test.beforeEach(async ({ page }) => await beforeCoderTest(page)); | ||
const DEFAULT_GROUP_NAME = "Everyone"; | ||
test(`Every user should be automatically added to the default '${DEFAULT_GROUP_NAME}' group upon creation`, async ({ | ||
page, | ||
baseURL, | ||
}) => { | ||
requiresEnterpriseLicense(); | ||
await setupApiCalls(page); | ||
const orgId = await getCurrentOrgId(); | ||
const numberOfMembers = 3; | ||
const users = await Promise.all( | ||
Array.from({ length: numberOfMembers }, () => createUser(orgId)), | ||
); | ||
await page.goto(`${baseURL}/groups`, { waitUntil: "domcontentloaded" }); | ||
await expect(page).toHaveTitle("Groups - Coder"); | ||
const groupRow = page.getByRole("row", { name: DEFAULT_GROUP_NAME }); | ||
await groupRow.click(); | ||
await expect(page).toHaveTitle(`${DEFAULT_GROUP_NAME} - Coder`); | ||
for (const user of users) { | ||
await expect(page.getByRole("row", { name: user.username })).toBeVisible(); | ||
} | ||
}); |
30 changes: 30 additions & 0 deletionssite/e2e/tests/groups/createGroup.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { randomName, requiresEnterpriseLicense } from "../../helpers"; | ||
import { beforeCoderTest } from "../../hooks"; | ||
test.beforeEach(async ({ page }) => await beforeCoderTest(page)); | ||
test("create group", async ({ page, baseURL }) => { | ||
requiresEnterpriseLicense(); | ||
await page.goto(`${baseURL}/groups`, { waitUntil: "domcontentloaded" }); | ||
await expect(page).toHaveTitle("Groups - Coder"); | ||
await page.getByText("Create group").click(); | ||
await expect(page).toHaveTitle("Create Group - Coder"); | ||
const name = randomName(); | ||
const groupValues = { | ||
name: name, | ||
displayName: `Display Name for ${name}`, | ||
avatarURL: "/emojis/1f60d.png", | ||
}; | ||
await page.getByLabel("Name", { exact: true }).fill(groupValues.name); | ||
await page.getByLabel("Display Name").fill(groupValues.displayName); | ||
await page.getByLabel("Avatar URL").fill(groupValues.avatarURL); | ||
await page.getByRole("button", { name: "Submit" }).click(); | ||
await expect(page).toHaveTitle(`${groupValues.displayName} - Coder`); | ||
await expect(page.getByText(groupValues.displayName)).toBeVisible(); | ||
await expect(page.getByText("No members yet")).toBeVisible(); | ||
}); |
23 changes: 23 additions & 0 deletionssite/e2e/tests/groups/navigateToGroupPage.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { createGroup, getCurrentOrgId, setupApiCalls } from "../../api"; | ||
import { requiresEnterpriseLicense } from "../../helpers"; | ||
import { beforeCoderTest } from "../../hooks"; | ||
test.beforeEach(async ({ page }) => await beforeCoderTest(page)); | ||
test("navigate to group page", async ({ page, baseURL }) => { | ||
requiresEnterpriseLicense(); | ||
await setupApiCalls(page); | ||
const orgId = await getCurrentOrgId(); | ||
const group = await createGroup(orgId); | ||
await page.goto(`${baseURL}/users`, { waitUntil: "domcontentloaded" }); | ||
await expect(page).toHaveTitle("Users - Coder"); | ||
await page.getByRole("link", { name: "Groups" }).click(); | ||
await expect(page).toHaveTitle("Groups - Coder"); | ||
const groupRow = page.getByRole("row", { name: group.display_name }); | ||
await groupRow.click(); | ||
await expect(page).toHaveTitle(`${group.display_name} - Coder`); | ||
}); |
26 changes: 26 additions & 0 deletionssite/e2e/tests/groups/removeGroup.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { createGroup, getCurrentOrgId, setupApiCalls } from "../../api"; | ||
import { requiresEnterpriseLicense } from "../../helpers"; | ||
import { beforeCoderTest } from "../../hooks"; | ||
test.beforeEach(async ({ page }) => await beforeCoderTest(page)); | ||
test("remove group", async ({ page, baseURL }) => { | ||
requiresEnterpriseLicense(); | ||
await setupApiCalls(page); | ||
const orgId = await getCurrentOrgId(); | ||
const group = await createGroup(orgId); | ||
await page.goto(`${baseURL}/groups/${group.id}`, { | ||
waitUntil: "domcontentloaded", | ||
}); | ||
await expect(page).toHaveTitle(`${group.display_name} - Coder`); | ||
await page.getByRole("button", { name: "Delete" }).click(); | ||
const dialog = page.getByTestId("dialog"); | ||
await dialog.getByLabel("Name of the group to delete").fill(group.name); | ||
await dialog.getByRole("button", { name: "Delete" }).click(); | ||
await expect(page.getByText("Group deleted successfully.")).toBeVisible(); | ||
await expect(page).toHaveTitle("Groups - Coder"); | ||
}); |
36 changes: 36 additions & 0 deletionssite/e2e/tests/groups/removeMember.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import * as API from "api/api"; | ||
import { | ||
createGroup, | ||
createUser, | ||
getCurrentOrgId, | ||
setupApiCalls, | ||
} from "../../api"; | ||
import { requiresEnterpriseLicense } from "../../helpers"; | ||
import { beforeCoderTest } from "../../hooks"; | ||
test.beforeEach(async ({ page }) => await beforeCoderTest(page)); | ||
test("remove member", async ({ page, baseURL }) => { | ||
requiresEnterpriseLicense(); | ||
await setupApiCalls(page); | ||
const orgId = await getCurrentOrgId(); | ||
const [group, member] = await Promise.all([ | ||
createGroup(orgId), | ||
createUser(orgId), | ||
]); | ||
await API.addMember(group.id, member.id); | ||
await page.goto(`${baseURL}/groups/${group.id}`, { | ||
waitUntil: "domcontentloaded", | ||
}); | ||
await expect(page).toHaveTitle(`${group.display_name} - Coder`); | ||
const userRow = page.getByRole("row", { name: member.username }); | ||
await userRow.getByRole("button", { name: "More options" }).click(); | ||
const menu = page.locator("#more-options"); | ||
await menu.getByText("Remove").click({ timeout: 1_000 }); | ||
await expect(page.getByText("Member removed successfully.")).toBeVisible(); | ||
}); |
20 changes: 6 additions & 14 deletionssite/e2e/tests/users/removeUser.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletionsite/src/api/api.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionssite/src/pages/GroupsPage/GroupPage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletionssite/src/pages/UsersPage/UsersLayout.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.