Skip to content

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

Merged
merged 10 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: use randomName
  • Loading branch information
jaaydenh committed Dec 12, 2024
commit d5ca1b0124907fdbbf01c3fc5a97ac1cb67cdd99
2 changes: 1 addition & 1 deletion site/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function requiresLicense() {
test.skip(!license);
}

export function noPremiumLicense() {
export function requiresUnlicensed() {
test.skip(license.length > 0);
}

Expand Down
12 changes: 7 additions & 5 deletions site/e2e/tests/deployment/idpOrgSync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
deleteOrganization,
setupApiCalls,
} from "../../api";
import { requiresLicense } from "../../helpers";
import { randomName, requiresLicense } from "../../helpers";
import { beforeCoderTest } from "../../hooks";

test.describe("IdpOrgSyncPage", () => {
Expand Down Expand Up @@ -117,7 +117,9 @@ test.describe("IdpOrgSyncPage", () => {
requiresLicense();
await setupApiCalls(page);

await createOrganizationWithName("admins");
const orgName = randomName();

await createOrganizationWithName(orgName);

await page.goto("/deployment/idp-org-sync", {
waitUntil: "domcontentloaded",
Expand All @@ -135,7 +137,7 @@ test.describe("IdpOrgSyncPage", () => {

// Select Coder organization from combobox
await orgSelector.click();
await page.getByRole("option", { name: "admins" }).click();
await page.getByRole("option", { name: orgName }).click();

// Add button should now be enabled
await expect(addButton).toBeEnabled();
Expand All @@ -146,12 +148,12 @@ test.describe("IdpOrgSyncPage", () => {
const newRow = page.getByTestId("idp-org-new-idp-org");
await expect(newRow).toBeVisible();
await expect(newRow.getByText("new-idp-org")).toBeVisible();
await expect(newRow.getByText("admins")).toBeVisible();
await expect(newRow.getByText(orgName)).toBeVisible();

await expect(
page.getByText("Organization sync settings updated."),
).toBeVisible();

await deleteOrganization("admins");
await deleteOrganization(orgName);
});
});
24 changes: 12 additions & 12 deletions site/e2e/tests/organizations/customRoles/customRoles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
deleteOrganization,
setupApiCalls,
} from "../../../api";
import { noPremiumLicense, requiresLicense } from "../../../helpers";
import { randomName, requiresUnlicensed, requiresLicense } from "../../../helpers";
import { beforeCoderTest } from "../../../hooks";

test.describe("CustomRolesPage", () => {
Expand All @@ -15,7 +15,7 @@ test.describe("CustomRolesPage", () => {
requiresLicense();
await setupApiCalls(page);

const org = await createOrganizationWithName("developers");
const org = await createOrganizationWithName(randomName());

const customRole = await createCustomRole(
org.id,
Expand All @@ -42,14 +42,14 @@ test.describe("CustomRolesPage", () => {

await expect(page).toHaveURL(`/organizations/${org.name}/roles`);

await deleteOrganization("developers");
await deleteOrganization(org.name);
});

test("create custom role, edit role and save changes", async ({ page }) => {
requiresLicense();
await setupApiCalls(page);

const org = await createOrganizationWithName("users");
const org = await createOrganizationWithName(randomName());

const customRole = await createCustomRole(
org.id,
Expand Down Expand Up @@ -91,7 +91,7 @@ test.describe("CustomRolesPage", () => {

await expect(page).toHaveURL(`/organizations/${org.name}/roles`);

await deleteOrganization("users");
await deleteOrganization(org.name);
});

test("displays built-in role without edit/delete options", async ({
Expand All @@ -100,7 +100,7 @@ test.describe("CustomRolesPage", () => {
requiresLicense();
await setupApiCalls(page);

const org = await createOrganizationWithName("testers");
const org = await createOrganizationWithName(randomName());

await page.goto(`/organizations/${org.name}/roles`);

Expand All @@ -114,14 +114,14 @@ test.describe("CustomRolesPage", () => {
roleRow.getByRole("button", { name: "More options" }),
).not.toBeVisible();

await deleteOrganization("testers");
await deleteOrganization(org.name);
});

test("create custom role with UI", async ({ page }) => {
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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");
const org = await createOrganizationWithName(randomName());

await page.goto(`/organizations/${org.name}/roles`);

Expand Down Expand Up @@ -154,14 +154,14 @@ test.describe("CustomRolesPage", () => {
await expect(roleRow.getByText(customRoleDisplayName)).toBeVisible();
await expect(roleRow.getByText("None")).toBeVisible();

await deleteOrganization("contractors");
await deleteOrganization(org.name);
});

test("delete custom role", async ({ page }) => {
requiresLicense();
await setupApiCalls(page);

const org = await createOrganizationWithName("custom1");
const org = await createOrganizationWithName(randomName());
const customRole = await createCustomRole(
org.id,
"custom-role-test-1",
Expand All @@ -183,12 +183,12 @@ test.describe("CustomRolesPage", () => {
page.getByText("Custom role deleted successfully!"),
).toBeVisible();

await deleteOrganization("custom1");
await deleteOrganization(org.name);
});
});

test("custom roles disabled", async ({ page }) => {
noPremiumLicense();
requiresUnlicensed();
await page.goto("/organizations/coder/roles");
await expect(page).toHaveURL("/organizations/coder/roles");

Expand Down
Loading