Skip to content

Commit 788449a

Browse files
committed
feat: create e2e tests for IDP org sync settings page
1 parent 069655a commit 788449a

File tree

3 files changed

+180
-1
lines changed

3 files changed

+180
-1
lines changed

site/e2e/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ code .
5555
Enterprise tests require a license key to run.
5656

5757
```shell
58-
export CODER_E2E_ENTERPRISE_LICENSE=<license key>
58+
export CODER_E2E_LICENSE=<license key>
5959
```
6060

6161
# Debugging tests

site/e2e/api.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@ export const createOrganization = async () => {
6363
return org;
6464
};
6565

66+
export const createOrganizationWithName = async (name: string) => {
67+
const org = await API.createOrganization({
68+
name,
69+
display_name: `${name}`,
70+
description: `Org description ${name}`,
71+
icon: "/emojis/1f957.png",
72+
});
73+
return org;
74+
};
75+
76+
export const createOrganizationSyncSettings = async () => {
77+
const settings = await API.patchOrganizationIdpSyncSettings({
78+
field: "organization-field-test",
79+
mapping: {
80+
"idp-org-1": [
81+
"fbd2116a-8961-4954-87ae-e4575bd29ce0",
82+
"13de3eb4-9b4f-49e7-b0f8-0c3728a0d2e2",
83+
],
84+
"idp-org-2": ["fbd2116a-8961-4954-87ae-e4575bd29ce0"],
85+
},
86+
organization_assign_default: true,
87+
});
88+
return settings;
89+
};
90+
6691
export async function verifyConfigFlagBoolean(
6792
page: Page,
6893
config: DeploymentConfig,
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import { expect, test } from "@playwright/test";
2+
import {
3+
createOrganizationSyncSettings,
4+
createOrganizationWithName,
5+
setupApiCalls,
6+
} from "../../api";
7+
import { requiresLicense } from "../../helpers";
8+
import { beforeCoderTest } from "../../hooks";
9+
10+
test.describe("IdpOrgSyncPage", () => {
11+
test.beforeEach(async ({ page }) => await beforeCoderTest(page));
12+
13+
test("add new IdP organization mapping with API", async ({ page }) => {
14+
requiresLicense();
15+
await setupApiCalls(page);
16+
17+
await createOrganizationSyncSettings();
18+
19+
await page.goto("/deployment/idp-org-sync", {
20+
waitUntil: "domcontentloaded",
21+
});
22+
23+
await expect(
24+
page.getByRole("switch", { name: "Assign Default Organization" }),
25+
).toBeChecked();
26+
27+
await expect(page.getByText("idp-org-1")).toBeVisible();
28+
await expect(
29+
page.getByText("fbd2116a-8961-4954-87ae-e4575bd29ce0").first(),
30+
).toBeVisible();
31+
32+
await expect(page.getByText("idp-org-2")).toBeVisible();
33+
await expect(
34+
page.getByText("fbd2116a-8961-4954-87ae-e4575bd29ce0").last(),
35+
).toBeVisible();
36+
});
37+
38+
test("delete a IdP org to coder org mapping row", async ({ page }) => {
39+
requiresLicense();
40+
await setupApiCalls(page);
41+
await createOrganizationSyncSettings();
42+
await page.goto("/deployment/idp-org-sync", {
43+
waitUntil: "domcontentloaded",
44+
});
45+
46+
await expect(page.getByText("idp-org-1")).toBeVisible();
47+
await page
48+
.getByRole("button", { name: /delete/i })
49+
.first()
50+
.click();
51+
await expect(page.getByText("idp-org-1")).not.toBeVisible();
52+
await expect(
53+
page.getByText("Organization sync settings updated."),
54+
).toBeVisible();
55+
});
56+
57+
test("update sync field", async ({ page }) => {
58+
requiresLicense();
59+
await page.goto("/deployment/idp-org-sync", {
60+
waitUntil: "domcontentloaded",
61+
});
62+
63+
const syncField = page.getByRole("textbox", {
64+
name: "Organization sync field",
65+
});
66+
const saveButton = page.getByRole("button", { name: "Save" }).first();
67+
68+
await expect(saveButton).toBeDisabled();
69+
70+
await syncField.fill("test-field");
71+
await expect(saveButton).toBeEnabled();
72+
73+
await page.getByRole("button", { name: "Save" }).click();
74+
75+
await expect(
76+
page.getByText("Organization sync settings updated."),
77+
).toBeVisible();
78+
});
79+
80+
test("toggle default organization assignment", async ({ page }) => {
81+
requiresLicense();
82+
await page.goto("/deployment/idp-org-sync", {
83+
waitUntil: "domcontentloaded",
84+
});
85+
86+
const toggle = page.getByRole("switch", {
87+
name: "Assign Default Organization",
88+
});
89+
await toggle.click();
90+
91+
await expect(
92+
page.getByText("Organization sync settings updated."),
93+
).toBeVisible();
94+
95+
await expect(toggle).not.toBeChecked();
96+
});
97+
98+
test("export policy button is enabled when sync settings are present", async ({
99+
page,
100+
}) => {
101+
requiresLicense();
102+
await setupApiCalls(page);
103+
104+
await page.goto("/deployment/idp-org-sync", {
105+
waitUntil: "domcontentloaded",
106+
});
107+
108+
const exportButton = page.getByRole("button", { name: /Export Policy/i });
109+
await createOrganizationSyncSettings();
110+
111+
await expect(exportButton).toBeEnabled();
112+
await exportButton.click();
113+
});
114+
115+
test("add new IdP organization mapping with UI", async ({ page }) => {
116+
requiresLicense();
117+
await setupApiCalls(page);
118+
119+
await createOrganizationWithName("developers");
120+
121+
await page.goto("/deployment/idp-org-sync", {
122+
waitUntil: "domcontentloaded",
123+
});
124+
125+
const idpOrgInput = page.getByLabel("IdP organization name");
126+
const orgSelector = page.getByPlaceholder("Select organization");
127+
const addButton = page.getByRole("button", {
128+
name: /Add IdP organization/i,
129+
});
130+
131+
await expect(addButton).toBeDisabled();
132+
133+
await idpOrgInput.fill("new-idp-org");
134+
135+
// Select Coder organization from combobox
136+
await orgSelector.click();
137+
await page.getByRole("option", { name: "developers" }).click();
138+
139+
// Add button should now be enabled
140+
await expect(addButton).toBeEnabled();
141+
142+
await addButton.click();
143+
144+
// Verify new mapping appears in table
145+
const newRow = page.getByTestId("idp-org-new-idp-org");
146+
await expect(newRow).toBeVisible();
147+
await expect(newRow.getByText("new-idp-org")).toBeVisible();
148+
await expect(newRow.getByText("developers")).toBeVisible();
149+
150+
await expect(
151+
page.getByText("Organization sync settings updated."),
152+
).toBeVisible();
153+
});
154+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy