|
| 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 | +awaitlogin(page); |
| 15 | +awaitsetupApiCalls(page); |
| 16 | +}); |
| 17 | + |
| 18 | +test.describe("IdpGroupSyncPage",()=>{ |
| 19 | +test("add new IdP group mapping with API",async({ page})=>{ |
| 20 | +requiresLicense(); |
| 21 | +constorg=awaitcreateOrganizationWithName(randomName()); |
| 22 | +awaitcreateGroupSyncSettings(org.id); |
| 23 | + |
| 24 | +awaitpage.goto(`/organizations/${org.name}/idp-sync?tab=groups`,{ |
| 25 | +waitUntil:"domcontentloaded", |
| 26 | +}); |
| 27 | + |
| 28 | +awaitexpect( |
| 29 | +page.getByRole("switch",{name:"Auto create missing groups"}), |
| 30 | +).toBeChecked(); |
| 31 | + |
| 32 | +awaitexpect(page.getByText("idp-group-1")).toBeVisible(); |
| 33 | +awaitexpect( |
| 34 | +page.getByText("fbd2116a-8961-4954-87ae-e4575bd29ce0").first(), |
| 35 | +).toBeVisible(); |
| 36 | + |
| 37 | +awaitexpect(page.getByText("idp-group-2")).toBeVisible(); |
| 38 | +awaitexpect( |
| 39 | +page.getByText("fbd2116a-8961-4954-87ae-e4575bd29ce0").last(), |
| 40 | +).toBeVisible(); |
| 41 | + |
| 42 | +awaitdeleteOrganization(org.name); |
| 43 | +}); |
| 44 | + |
| 45 | +test("delete a IdP group to coder group mapping row",async({ page})=>{ |
| 46 | +requiresLicense(); |
| 47 | +constorg=awaitcreateOrganizationWithName(randomName()); |
| 48 | +awaitcreateGroupSyncSettings(org.id); |
| 49 | + |
| 50 | +awaitpage.goto(`/organizations/${org.name}/idp-sync?tab=groups`,{ |
| 51 | +waitUntil:"domcontentloaded", |
| 52 | +}); |
| 53 | + |
| 54 | +awaitexpect(page.getByText("idp-group-1")).toBeVisible(); |
| 55 | +awaitpage |
| 56 | +.getByRole("button",{name:/delete/i}) |
| 57 | +.first() |
| 58 | +.click(); |
| 59 | +awaitexpect(page.getByText("idp-group-1")).not.toBeVisible(); |
| 60 | +awaitexpect( |
| 61 | +page.getByText("IdP Group sync settings updated."), |
| 62 | +).toBeVisible(); |
| 63 | +}); |
| 64 | + |
| 65 | +test("update sync field",async({ page})=>{ |
| 66 | +requiresLicense(); |
| 67 | +constorg=awaitcreateOrganizationWithName(randomName()); |
| 68 | +awaitpage.goto(`/organizations/${org.name}/idp-sync?tab=groups`,{ |
| 69 | +waitUntil:"domcontentloaded", |
| 70 | +}); |
| 71 | + |
| 72 | +constsyncField=page.getByRole("textbox",{ |
| 73 | +name:"Group sync field", |
| 74 | +}); |
| 75 | +constsaveButton=page.getByRole("button",{name:/save/i}).first(); |
| 76 | + |
| 77 | +awaitexpect(saveButton).toBeDisabled(); |
| 78 | + |
| 79 | +awaitsyncField.fill("test-field"); |
| 80 | +awaitexpect(saveButton).toBeEnabled(); |
| 81 | + |
| 82 | +awaitpage.getByRole("button",{name:/save/i}).click(); |
| 83 | + |
| 84 | +awaitexpect( |
| 85 | +page.getByText("IdP Group sync settings updated."), |
| 86 | +).toBeVisible(); |
| 87 | +}); |
| 88 | + |
| 89 | +test("toggle off auto create missing groups",async({ page})=>{ |
| 90 | +requiresLicense(); |
| 91 | +constorg=awaitcreateOrganizationWithName(randomName()); |
| 92 | +awaitpage.goto(`/organizations/${org.name}/idp-sync?tab=groups`,{ |
| 93 | +waitUntil:"domcontentloaded", |
| 94 | +}); |
| 95 | + |
| 96 | +consttoggle=page.getByRole("switch",{ |
| 97 | +name:"Auto create missing groups", |
| 98 | +}); |
| 99 | +awaittoggle.click(); |
| 100 | + |
| 101 | +awaitexpect( |
| 102 | +page.getByText("IdP Group sync settings updated."), |
| 103 | +).toBeVisible(); |
| 104 | + |
| 105 | +awaitexpect(toggle).toBeChecked(); |
| 106 | +}); |
| 107 | + |
| 108 | +test("export policy button is enabled when sync settings are present",async({ |
| 109 | +page, |
| 110 | +})=>{ |
| 111 | +requiresLicense(); |
| 112 | +constorg=awaitcreateOrganizationWithName(randomName()); |
| 113 | +awaitcreateGroupSyncSettings(org.id); |
| 114 | +awaitpage.goto(`/organizations/${org.name}/idp-sync?tab=groups`,{ |
| 115 | +waitUntil:"domcontentloaded", |
| 116 | +}); |
| 117 | + |
| 118 | +constexportButton=page.getByRole("button",{name:/ExportPolicy/i}); |
| 119 | +awaitexpect(exportButton).toBeEnabled(); |
| 120 | +awaitexportButton.click(); |
| 121 | +}); |
| 122 | + |
| 123 | +test("add new IdP group mapping with UI",async({ page})=>{ |
| 124 | +requiresLicense(); |
| 125 | +constorgName=randomName(); |
| 126 | +awaitcreateOrganizationWithName(orgName); |
| 127 | + |
| 128 | +awaitpage.goto(`/organizations/${orgName}/idp-sync?tab=groups`,{ |
| 129 | +waitUntil:"domcontentloaded", |
| 130 | +}); |
| 131 | + |
| 132 | +constidpOrgInput=page.getByLabel("IdP group name"); |
| 133 | +constorgSelector=page.getByPlaceholder("Select group"); |
| 134 | +constaddButton=page.getByRole("button",{ |
| 135 | +name:/AddIdPgroup/i, |
| 136 | +}); |
| 137 | + |
| 138 | +awaitexpect(addButton).toBeDisabled(); |
| 139 | + |
| 140 | +awaitidpOrgInput.fill("new-idp-group"); |
| 141 | + |
| 142 | +// Select Coder organization from combobox |
| 143 | +awaitorgSelector.click(); |
| 144 | +awaitpage.getByRole("option",{name:/Everyone/i}).click(); |
| 145 | + |
| 146 | +// Add button should now be enabled |
| 147 | +awaitexpect(addButton).toBeEnabled(); |
| 148 | + |
| 149 | +awaitaddButton.click(); |
| 150 | + |
| 151 | +// Verify new mapping appears in table |
| 152 | +constnewRow=page.getByTestId("group-new-idp-group"); |
| 153 | +awaitexpect(newRow).toBeVisible(); |
| 154 | +awaitexpect(newRow.getByText("new-idp-group")).toBeVisible(); |
| 155 | +awaitexpect(newRow.getByText("Everyone")).toBeVisible(); |
| 156 | + |
| 157 | +awaitexpect( |
| 158 | +page.getByText("IdP Group sync settings updated."), |
| 159 | +).toBeVisible(); |
| 160 | + |
| 161 | +awaitdeleteOrganization(orgName); |
| 162 | +}); |
| 163 | +}); |