Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: create e2e tests for IDP org sync settings page #15767

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 3 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion site/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ code .
Enterprise tests require a license key to run.

```shell
export CODER_E2E_ENTERPRISE_LICENSE=<license key>
export CODER_E2E_LICENSE=<license key>
```

# Debugging tests
Expand Down
29 changes: 29 additions & 0 deletions site/e2e/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ export const createOrganization = async () => {
return org;
};

export const deleteOrganization = async (orgName: string) => {
await API.deleteOrganization(orgName);
};

export const createOrganizationWithName = async (name: string) => {
const org = await API.createOrganization({
name,
display_name: `${name}`,
description: `Org description ${name}`,
icon: "/emojis/1f957.png",
});
return org;
};

export const createOrganizationSyncSettings = async () => {
const settings = await API.patchOrganizationIdpSyncSettings({
field: "organization-field-test",
mapping: {
"idp-org-1": [
"fbd2116a-8961-4954-87ae-e4575bd29ce0",
"13de3eb4-9b4f-49e7-b0f8-0c3728a0d2e2",
],
"idp-org-2": ["fbd2116a-8961-4954-87ae-e4575bd29ce0"],
},
organization_assign_default: true,
});
return settings;
};

export async function verifyConfigFlagBoolean(
page: Page,
config: DeploymentConfig,
Expand Down
157 changes: 157 additions & 0 deletions site/e2e/tests/deployment/idpOrgSync.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import { expect, test } from "@playwright/test";
import {
createOrganizationSyncSettings,
createOrganizationWithName,
deleteOrganization,
setupApiCalls,
} from "../../api";
import { requiresLicense } from "../../helpers";
import { beforeCoderTest } from "../../hooks";

test.describe("IdpOrgSyncPage", () => {
test.beforeEach(async ({ page }) => await beforeCoderTest(page));

test("add new IdP organization mapping with API", async ({ page }) => {
requiresLicense();
await setupApiCalls(page);

await createOrganizationSyncSettings();

await page.goto("/deployment/idp-org-sync", {
waitUntil: "domcontentloaded",
});

await expect(
page.getByRole("switch", { name: "Assign Default Organization" }),
).toBeChecked();

await expect(page.getByText("idp-org-1")).toBeVisible();
await expect(
page.getByText("fbd2116a-8961-4954-87ae-e4575bd29ce0").first(),
).toBeVisible();

await expect(page.getByText("idp-org-2")).toBeVisible();
await expect(
page.getByText("fbd2116a-8961-4954-87ae-e4575bd29ce0").last(),
).toBeVisible();
});

test("delete a IdP org to coder org mapping row", async ({ page }) => {
requiresLicense();
await setupApiCalls(page);
await createOrganizationSyncSettings();
await page.goto("/deployment/idp-org-sync", {
waitUntil: "domcontentloaded",
});

await expect(page.getByText("idp-org-1")).toBeVisible();
await page
.getByRole("button", { name: /delete/i })
.first()
.click();
await expect(page.getByText("idp-org-1")).not.toBeVisible();
await expect(
page.getByText("Organization sync settings updated."),
).toBeVisible();
});

test("update sync field", async ({ page }) => {
requiresLicense();
await page.goto("/deployment/idp-org-sync", {
waitUntil: "domcontentloaded",
});

const syncField = page.getByRole("textbox", {
name: "Organization sync field",
});
const saveButton = page.getByRole("button", { name: "Save" }).first();

await expect(saveButton).toBeDisabled();

await syncField.fill("test-field");
await expect(saveButton).toBeEnabled();

await page.getByRole("button", { name: "Save" }).click();

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

test("toggle default organization assignment", async ({ page }) => {
requiresLicense();
await page.goto("/deployment/idp-org-sync", {
waitUntil: "domcontentloaded",
});

const toggle = page.getByRole("switch", {
name: "Assign Default Organization",
});
await toggle.click();

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

await expect(toggle).not.toBeChecked();
});

test("export policy button is enabled when sync settings are present", async ({
page,
}) => {
requiresLicense();
await setupApiCalls(page);

await page.goto("/deployment/idp-org-sync", {
waitUntil: "domcontentloaded",
});

const exportButton = page.getByRole("button", { name: /Export Policy/i });
await createOrganizationSyncSettings();

await expect(exportButton).toBeEnabled();
await exportButton.click();
});

test("add new IdP organization mapping with UI", async ({ page }) => {
requiresLicense();
await setupApiCalls(page);

await createOrganizationWithName("developers");

await page.goto("/deployment/idp-org-sync", {
waitUntil: "domcontentloaded",
});

const idpOrgInput = page.getByLabel("IdP organization name");
const orgSelector = page.getByPlaceholder("Select organization");
const addButton = page.getByRole("button", {
name: /Add IdP organization/i,
});

await expect(addButton).toBeDisabled();

await idpOrgInput.fill("new-idp-org");

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

// Add button should now be enabled
await expect(addButton).toBeEnabled();

await addButton.click();

// Verify new mapping appears in table
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("developers")).toBeVisible();

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

await deleteOrganization("developers");
});
});
Loading