|
| 1 | +import{expect,test}from"@playwright/test"; |
| 2 | +import{ |
| 3 | +createOrganizationSyncSettings, |
| 4 | +createOrganizationWithName, |
| 5 | +deleteOrganization, |
| 6 | +setupApiCalls, |
| 7 | +}from"../../api"; |
| 8 | +import{requiresLicense}from"../../helpers"; |
| 9 | +import{beforeCoderTest}from"../../hooks"; |
| 10 | + |
| 11 | +test.describe("IdpOrgSyncPage",()=>{ |
| 12 | +test.beforeEach(async({ page})=>awaitbeforeCoderTest(page)); |
| 13 | + |
| 14 | +test("add new IdP organization mapping with API",async({ page})=>{ |
| 15 | +requiresLicense(); |
| 16 | +awaitsetupApiCalls(page); |
| 17 | + |
| 18 | +awaitcreateOrganizationSyncSettings(); |
| 19 | + |
| 20 | +awaitpage.goto("/deployment/idp-org-sync",{ |
| 21 | +waitUntil:"domcontentloaded", |
| 22 | +}); |
| 23 | + |
| 24 | +awaitexpect( |
| 25 | +page.getByRole("switch",{name:"Assign Default Organization"}), |
| 26 | +).toBeChecked(); |
| 27 | + |
| 28 | +awaitexpect(page.getByText("idp-org-1")).toBeVisible(); |
| 29 | +awaitexpect( |
| 30 | +page.getByText("fbd2116a-8961-4954-87ae-e4575bd29ce0").first(), |
| 31 | +).toBeVisible(); |
| 32 | + |
| 33 | +awaitexpect(page.getByText("idp-org-2")).toBeVisible(); |
| 34 | +awaitexpect( |
| 35 | +page.getByText("fbd2116a-8961-4954-87ae-e4575bd29ce0").last(), |
| 36 | +).toBeVisible(); |
| 37 | +}); |
| 38 | + |
| 39 | +test("delete a IdP org to coder org mapping row",async({ page})=>{ |
| 40 | +requiresLicense(); |
| 41 | +awaitsetupApiCalls(page); |
| 42 | +awaitcreateOrganizationSyncSettings(); |
| 43 | +awaitpage.goto("/deployment/idp-org-sync",{ |
| 44 | +waitUntil:"domcontentloaded", |
| 45 | +}); |
| 46 | + |
| 47 | +awaitexpect(page.getByText("idp-org-1")).toBeVisible(); |
| 48 | +awaitpage |
| 49 | +.getByRole("button",{name:/delete/i}) |
| 50 | +.first() |
| 51 | +.click(); |
| 52 | +awaitexpect(page.getByText("idp-org-1")).not.toBeVisible(); |
| 53 | +awaitexpect( |
| 54 | +page.getByText("Organization sync settings updated."), |
| 55 | +).toBeVisible(); |
| 56 | +}); |
| 57 | + |
| 58 | +test("update sync field",async({ page})=>{ |
| 59 | +requiresLicense(); |
| 60 | +awaitpage.goto("/deployment/idp-org-sync",{ |
| 61 | +waitUntil:"domcontentloaded", |
| 62 | +}); |
| 63 | + |
| 64 | +constsyncField=page.getByRole("textbox",{ |
| 65 | +name:"Organization sync field", |
| 66 | +}); |
| 67 | +constsaveButton=page.getByRole("button",{name:"Save"}).first(); |
| 68 | + |
| 69 | +awaitexpect(saveButton).toBeDisabled(); |
| 70 | + |
| 71 | +awaitsyncField.fill("test-field"); |
| 72 | +awaitexpect(saveButton).toBeEnabled(); |
| 73 | + |
| 74 | +awaitpage.getByRole("button",{name:"Save"}).click(); |
| 75 | + |
| 76 | +awaitexpect( |
| 77 | +page.getByText("Organization sync settings updated."), |
| 78 | +).toBeVisible(); |
| 79 | +}); |
| 80 | + |
| 81 | +test("toggle default organization assignment",async({ page})=>{ |
| 82 | +requiresLicense(); |
| 83 | +awaitpage.goto("/deployment/idp-org-sync",{ |
| 84 | +waitUntil:"domcontentloaded", |
| 85 | +}); |
| 86 | + |
| 87 | +consttoggle=page.getByRole("switch",{ |
| 88 | +name:"Assign Default Organization", |
| 89 | +}); |
| 90 | +awaittoggle.click(); |
| 91 | + |
| 92 | +awaitexpect( |
| 93 | +page.getByText("Organization sync settings updated."), |
| 94 | +).toBeVisible(); |
| 95 | + |
| 96 | +awaitexpect(toggle).not.toBeChecked(); |
| 97 | +}); |
| 98 | + |
| 99 | +test("export policy button is enabled when sync settings are present",async({ |
| 100 | +page, |
| 101 | +})=>{ |
| 102 | +requiresLicense(); |
| 103 | +awaitsetupApiCalls(page); |
| 104 | + |
| 105 | +awaitpage.goto("/deployment/idp-org-sync",{ |
| 106 | +waitUntil:"domcontentloaded", |
| 107 | +}); |
| 108 | + |
| 109 | +constexportButton=page.getByRole("button",{name:/ExportPolicy/i}); |
| 110 | +awaitcreateOrganizationSyncSettings(); |
| 111 | + |
| 112 | +awaitexpect(exportButton).toBeEnabled(); |
| 113 | +awaitexportButton.click(); |
| 114 | +}); |
| 115 | + |
| 116 | +test("add new IdP organization mapping with UI",async({ page})=>{ |
| 117 | +requiresLicense(); |
| 118 | +awaitsetupApiCalls(page); |
| 119 | + |
| 120 | +awaitcreateOrganizationWithName("developers"); |
| 121 | + |
| 122 | +awaitpage.goto("/deployment/idp-org-sync",{ |
| 123 | +waitUntil:"domcontentloaded", |
| 124 | +}); |
| 125 | + |
| 126 | +constidpOrgInput=page.getByLabel("IdP organization name"); |
| 127 | +constorgSelector=page.getByPlaceholder("Select organization"); |
| 128 | +constaddButton=page.getByRole("button",{ |
| 129 | +name:/AddIdPorganization/i, |
| 130 | +}); |
| 131 | + |
| 132 | +awaitexpect(addButton).toBeDisabled(); |
| 133 | + |
| 134 | +awaitidpOrgInput.fill("new-idp-org"); |
| 135 | + |
| 136 | +// Select Coder organization from combobox |
| 137 | +awaitorgSelector.click(); |
| 138 | +awaitpage.getByRole("option",{name:"developers"}).click(); |
| 139 | + |
| 140 | +// Add button should now be enabled |
| 141 | +awaitexpect(addButton).toBeEnabled(); |
| 142 | + |
| 143 | +awaitaddButton.click(); |
| 144 | + |
| 145 | +// Verify new mapping appears in table |
| 146 | +constnewRow=page.getByTestId("idp-org-new-idp-org"); |
| 147 | +awaitexpect(newRow).toBeVisible(); |
| 148 | +awaitexpect(newRow.getByText("new-idp-org")).toBeVisible(); |
| 149 | +awaitexpect(newRow.getByText("developers")).toBeVisible(); |
| 150 | + |
| 151 | +awaitexpect( |
| 152 | +page.getByText("Organization sync settings updated."), |
| 153 | +).toBeVisible(); |
| 154 | + |
| 155 | +awaitdeleteOrganization("developers"); |
| 156 | +}); |
| 157 | +}); |