|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { |
| 3 | + createGroupSyncSettings, |
| 4 | + createOrganizationWithName, |
| 5 | + deleteOrganization, |
| 6 | + setupApiCalls, |
| 7 | +} from "../../api"; |
| 8 | +import { randomName, requiresLicense } from "../../helpers"; |
| 9 | +import { login } from "../../helpers"; |
| 10 | +import { beforeCoderTest } from "../../hooks"; |
| 11 | + |
| 12 | +test.beforeEach(async ({ page }) => { |
| 13 | + beforeCoderTest(page); |
| 14 | + await login(page); |
| 15 | + await setupApiCalls(page); |
| 16 | +}); |
| 17 | + |
| 18 | +test.describe("IdpGroupSyncPage", () => { |
| 19 | + test("show empty table when no group mappings are present", async ({ |
| 20 | + page, |
| 21 | + }) => { |
| 22 | + requiresLicense(); |
| 23 | + const org = await createOrganizationWithName(randomName()); |
| 24 | + await page.goto(`/organizations/${org.name}/idp-sync?tab=groups`, { |
| 25 | + waitUntil: "domcontentloaded", |
| 26 | + }); |
| 27 | + |
| 28 | + await expect( |
| 29 | + page.getByRole("row", { name: "idp-group-1" }), |
| 30 | + ).not.toBeVisible(); |
| 31 | + await expect( |
| 32 | + page.getByRole("heading", { name: "No group mappings" }), |
| 33 | + ).toBeVisible(); |
| 34 | + |
| 35 | + await deleteOrganization(org.name); |
| 36 | + }); |
| 37 | + |
| 38 | + test("add new IdP group mapping with API", async ({ page }) => { |
| 39 | + requiresLicense(); |
| 40 | + const org = await createOrganizationWithName(randomName()); |
| 41 | + await createGroupSyncSettings(org.id); |
| 42 | + |
| 43 | + await page.goto(`/organizations/${org.name}/idp-sync?tab=groups`, { |
| 44 | + waitUntil: "domcontentloaded", |
| 45 | + }); |
| 46 | + |
| 47 | + await expect( |
| 48 | + page.getByRole("switch", { name: "Auto create missing groups" }), |
| 49 | + ).toBeChecked(); |
| 50 | + |
| 51 | + await expect(page.getByRole("row", { name: "idp-group-1" })).toBeVisible(); |
| 52 | + await expect( |
| 53 | + page.getByRole("row", { name: "fbd2116a-8961-4954-87ae-e4575bd29ce0" }), |
| 54 | + ).toBeVisible(); |
| 55 | + |
| 56 | + await expect(page.getByRole("row", { name: "idp-group-2" })).toBeVisible(); |
| 57 | + await expect( |
| 58 | + page.getByRole("row", { name: "6b39f0f1-6ad8-4981-b2fc-d52aef53ff1b" }), |
| 59 | + ).toBeVisible(); |
| 60 | + |
| 61 | + await deleteOrganization(org.name); |
| 62 | + }); |
| 63 | + |
| 64 | + test("delete a IdP group to coder group mapping row", async ({ page }) => { |
| 65 | + requiresLicense(); |
| 66 | + const org = await createOrganizationWithName(randomName()); |
| 67 | + await createGroupSyncSettings(org.id); |
| 68 | + |
| 69 | + await page.goto(`/organizations/${org.name}/idp-sync?tab=groups`, { |
| 70 | + waitUntil: "domcontentloaded", |
| 71 | + }); |
| 72 | + |
| 73 | + const row = page.getByTestId("group-idp-group-1"); |
| 74 | + await expect(row.getByRole("cell", { name: "idp-group-1" })).toBeVisible(); |
| 75 | + await row.getByRole("button", { name: /delete/i }).click(); |
| 76 | + await expect( |
| 77 | + row.getByRole("cell", { name: "idp-group-1" }), |
| 78 | + ).not.toBeVisible(); |
| 79 | + await expect( |
| 80 | + page.getByText("IdP Group sync settings updated."), |
| 81 | + ).toBeVisible(); |
| 82 | + }); |
| 83 | + |
| 84 | + test("update sync field", async ({ page }) => { |
| 85 | + requiresLicense(); |
| 86 | + const org = await createOrganizationWithName(randomName()); |
| 87 | + await page.goto(`/organizations/${org.name}/idp-sync?tab=groups`, { |
| 88 | + waitUntil: "domcontentloaded", |
| 89 | + }); |
| 90 | + |
| 91 | + const syncField = page.getByRole("textbox", { |
| 92 | + name: "Group sync field", |
| 93 | + }); |
| 94 | + const saveButton = page.getByRole("button", { name: /save/i }); |
| 95 | + |
| 96 | + await expect(saveButton).toBeDisabled(); |
| 97 | + |
| 98 | + await syncField.fill("test-field"); |
| 99 | + await expect(saveButton).toBeEnabled(); |
| 100 | + |
| 101 | + await page.getByRole("button", { name: /save/i }).click(); |
| 102 | + |
| 103 | + await expect( |
| 104 | + page.getByText("IdP Group sync settings updated."), |
| 105 | + ).toBeVisible(); |
| 106 | + }); |
| 107 | + |
| 108 | + test("toggle off auto create missing groups", async ({ page }) => { |
| 109 | + requiresLicense(); |
| 110 | + const org = await createOrganizationWithName(randomName()); |
| 111 | + await page.goto(`/organizations/${org.name}/idp-sync?tab=groups`, { |
| 112 | + waitUntil: "domcontentloaded", |
| 113 | + }); |
| 114 | + |
| 115 | + const toggle = page.getByRole("switch", { |
| 116 | + name: "Auto create missing groups", |
| 117 | + }); |
| 118 | + await toggle.click(); |
| 119 | + |
| 120 | + await expect( |
| 121 | + page.getByText("IdP Group sync settings updated."), |
| 122 | + ).toBeVisible(); |
| 123 | + |
| 124 | + await expect(toggle).toBeChecked(); |
| 125 | + }); |
| 126 | + |
| 127 | + test("export policy button is enabled when sync settings are present", async ({ |
| 128 | + page, |
| 129 | + }) => { |
| 130 | + requiresLicense(); |
| 131 | + const org = await createOrganizationWithName(randomName()); |
| 132 | + await createGroupSyncSettings(org.id); |
| 133 | + await page.goto(`/organizations/${org.name}/idp-sync?tab=groups`, { |
| 134 | + waitUntil: "domcontentloaded", |
| 135 | + }); |
| 136 | + |
| 137 | + const exportButton = page.getByRole("button", { name: /Export Policy/i }); |
| 138 | + await expect(exportButton).toBeEnabled(); |
| 139 | + await exportButton.click(); |
| 140 | + }); |
| 141 | + |
| 142 | + test("add new IdP group mapping with UI", async ({ page }) => { |
| 143 | + requiresLicense(); |
| 144 | + const orgName = randomName(); |
| 145 | + await createOrganizationWithName(orgName); |
| 146 | + |
| 147 | + await page.goto(`/organizations/${orgName}/idp-sync?tab=groups`, { |
| 148 | + waitUntil: "domcontentloaded", |
| 149 | + }); |
| 150 | + |
| 151 | + const idpOrgInput = page.getByLabel("IdP group name"); |
| 152 | + const orgSelector = page.getByPlaceholder("Select group"); |
| 153 | + const addButton = page.getByRole("button", { |
| 154 | + name: /Add IdP group/i, |
| 155 | + }); |
| 156 | + |
| 157 | + await expect(addButton).toBeDisabled(); |
| 158 | + |
| 159 | + await idpOrgInput.fill("new-idp-group"); |
| 160 | + |
| 161 | + // Select Coder organization from combobox |
| 162 | + await orgSelector.click(); |
| 163 | + await page.getByRole("option", { name: /Everyone/i }).click(); |
| 164 | + |
| 165 | + // Add button should now be enabled |
| 166 | + await expect(addButton).toBeEnabled(); |
| 167 | + |
| 168 | + await addButton.click(); |
| 169 | + |
| 170 | + // Verify new mapping appears in table |
| 171 | + const newRow = page.getByTestId("group-new-idp-group"); |
| 172 | + await expect(newRow).toBeVisible(); |
| 173 | + await expect( |
| 174 | + newRow.getByRole("cell", { name: "new-idp-group" }), |
| 175 | + ).toBeVisible(); |
| 176 | + await expect(newRow.getByRole("cell", { name: "Everyone" })).toBeVisible(); |
| 177 | + |
| 178 | + await expect( |
| 179 | + page.getByText("IdP Group sync settings updated."), |
| 180 | + ).toBeVisible(); |
| 181 | + |
| 182 | + await deleteOrganization(orgName); |
| 183 | + }); |
| 184 | +}); |
0 commit comments