|
| 1 | +import * as _ from "../../../../support/Objects/ObjectsCore"; |
| 2 | +import AdminsSettings from "../../../../locators/AdminsSettings"; |
| 3 | + |
| 4 | +describe("Static URL - Slug Persistence", { tags: ["@tag.Settings"] }, () => { |
| 5 | + it("1. Should auto-generate slug from application name when Static URL toggle is enabled", () => { |
| 6 | + // Navigate to General Settings |
| 7 | + _.appSettings.OpenAppSettings(); |
| 8 | + _.appSettings.GoToGeneralSettings(); |
| 9 | + |
| 10 | + // Get the current application name |
| 11 | + _.agHelper.GetText(AdminsSettings.generalSettingsAppName, "val").then((appName) => { |
| 12 | + const appNameStr = appName as string; |
| 13 | + // Convert app name to expected slug format (lowercase, spaces replaced with hyphens) |
| 14 | + const expectedSlug = appNameStr |
| 15 | + .toLowerCase() |
| 16 | + .trim() |
| 17 | + .replace(/\s+/g, "-") |
| 18 | + .replace(/[^a-z0-9-]/g, ""); // Remove any special characters except hyphens |
| 19 | + |
| 20 | + // Toggle on Static URL |
| 21 | + _.agHelper.GetNClick(AdminsSettings.generalSettingsStaticUrl); |
| 22 | + |
| 23 | + // Wait for the API call to complete |
| 24 | + _.assertHelper.AssertNetworkStatus("@fetchAppSlugSuggestion", 200); |
| 25 | + cy.get("@fetchAppSlugSuggestion").then((interception: any) => { |
| 26 | + const suggestedSlug = interception.response.body.data; |
| 27 | + |
| 28 | + // Verify the slug input field is visible and contains the suggested slug |
| 29 | + _.agHelper.AssertElementVisibility(AdminsSettings.generalSettingsStaticAppSlug); |
| 30 | + _.agHelper.AssertText(AdminsSettings.generalSettingsStaticAppSlug, "val", suggestedSlug); |
| 31 | + |
| 32 | + // Verify the suggested slug starts with the expected slug derived from the application name |
| 33 | + // Backend appends a random hash after a hyphen for uniqueness |
| 34 | + expect(suggestedSlug).to.satisfy((slug: string) => |
| 35 | + slug.startsWith(`${expectedSlug}`) |
| 36 | + ); |
| 37 | + }); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + it("2. Should allow editing slug and show available status with updated URL preview", () => { |
| 42 | + // Continue from test 1 - static URL is already enabled and slug is already set |
| 43 | + // Get the current slug from the input field |
| 44 | + _.agHelper.GetText(AdminsSettings.generalSettingsStaticAppSlug, "val").then((initialSlug) => { |
| 45 | + const initialSlugStr = initialSlug as string; |
| 46 | + |
| 47 | + // Verify the slug input field is visible and contains the suggested slug |
| 48 | + _.agHelper.AssertElementVisibility(AdminsSettings.generalSettingsStaticAppSlug); |
| 49 | + _.agHelper.AssertText(AdminsSettings.generalSettingsStaticAppSlug, "val", initialSlugStr); |
| 50 | + |
| 51 | + // Modify the slug by appending "1" |
| 52 | + const modifiedSlug = initialSlugStr + "1"; |
| 53 | + _.agHelper.ClearNType(AdminsSettings.generalSettingsStaticAppSlug, modifiedSlug); |
| 54 | + |
| 55 | + // Wait for the validation API call to complete |
| 56 | + _.assertHelper.AssertNetworkStatus("@validateAppSlug", 200); |
| 57 | + |
| 58 | + // Verify the "Available" message appears |
| 59 | + _.agHelper.AssertContains("Available", "be.visible"); |
| 60 | + |
| 61 | + // Verify the URL preview shows the modified slug |
| 62 | + // The URL preview should contain the full URL ending with the modified slug |
| 63 | + _.agHelper.AssertContains(`/app/${modifiedSlug}`, "be.visible"); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + it("3. Should persist slug after confirmation and reflect on page reload", () => { |
| 68 | + // Continue from test 2 - slug is already modified and available |
| 69 | + // Get the modified slug from the input field |
| 70 | + _.agHelper.GetText(AdminsSettings.generalSettingsStaticAppSlug, "val").then((modifiedSlug) => { |
| 71 | + const modifiedSlugStr = modifiedSlug as string; |
| 72 | + |
| 73 | + // Verify the "Available" message is still visible |
| 74 | + _.agHelper.AssertContains("Available", "be.visible"); |
| 75 | + |
| 76 | + // Click on "Apply" button to open confirmation modal |
| 77 | + // The Apply button is in the settings pane, not in the modal |
| 78 | + _.agHelper.AssertElementEnabledDisabled(AdminsSettings.staticUrlConfirmationConfirm, 0, false); |
| 79 | + _.agHelper.GetNClickByContains(AdminsSettings.staticUrlConfirmationConfirm, "Apply"); |
| 80 | + |
| 81 | + // Verify the modal appears with title "Change App Slug" |
| 82 | + _.agHelper.AssertElementVisibility(AdminsSettings.staticUrlConfirmationModal); |
| 83 | + _.agHelper.AssertContains("Change App Slug", "be.visible"); |
| 84 | + |
| 85 | + // Verify the modal shows the "To" URL with the modified slug |
| 86 | + _.agHelper.AssertContains("To", "be.visible"); |
| 87 | + _.agHelper.AssertContains(`/app/${modifiedSlugStr}`, "be.visible"); |
| 88 | + |
| 89 | + // Click on "Change App Slug" button in the modal to confirm |
| 90 | + _.agHelper.GetNClickByContains(AdminsSettings.staticUrlConfirmationConfirm, "Change App Slug"); |
| 91 | + |
| 92 | + // Verify the success toast notification appears |
| 93 | + _.agHelper.ValidateToastMessage("App slug updated"); |
| 94 | + |
| 95 | + // Reload the page |
| 96 | + _.agHelper.CypressReload(); |
| 97 | + |
| 98 | + // Verify the slug persists after reload |
| 99 | + _.agHelper.AssertElementVisibility(AdminsSettings.generalSettingsStaticAppSlug); |
| 100 | + _.agHelper.AssertText(AdminsSettings.generalSettingsStaticAppSlug, "val", modifiedSlugStr); |
| 101 | + }); |
| 102 | + }); |
| 103 | + |
| 104 | + it("4. Should not persist slug when modal is cancelled", () => { |
| 105 | + // Continue from test 3 - slug is already persisted from previous test |
| 106 | + // Get the current persisted slug from the input field |
| 107 | + _.agHelper.GetText(AdminsSettings.generalSettingsStaticAppSlug, "val").then((persistedSlug) => { |
| 108 | + const persistedSlugStr = persistedSlug as string; |
| 109 | + |
| 110 | + // Modify the slug by appending "2" to create a new modified slug |
| 111 | + const modifiedSlug = persistedSlugStr + "2"; |
| 112 | + _.agHelper.ClearNType(AdminsSettings.generalSettingsStaticAppSlug, modifiedSlug); |
| 113 | + |
| 114 | + // Wait for the validation API call to complete |
| 115 | + _.assertHelper.AssertNetworkStatus("@validateAppSlug", 200); |
| 116 | + |
| 117 | + // Verify the "Available" message appears |
| 118 | + _.agHelper.AssertContains("Available", "be.visible"); |
| 119 | + |
| 120 | + // Click on "Apply" button to open confirmation modal |
| 121 | + _.agHelper.AssertElementEnabledDisabled(AdminsSettings.staticUrlConfirmationConfirm, 0, false); |
| 122 | + _.agHelper.GetNClickByContains(AdminsSettings.staticUrlConfirmationConfirm, "Apply"); |
| 123 | + |
| 124 | + // Verify the modal appears with title "Change App Slug" |
| 125 | + _.agHelper.AssertElementVisibility(AdminsSettings.staticUrlConfirmationModal); |
| 126 | + _.agHelper.AssertContains("Change App Slug", "be.visible"); |
| 127 | + |
| 128 | + // Verify the modal shows the "To" URL with the modified slug |
| 129 | + _.agHelper.AssertContains("To", "be.visible"); |
| 130 | + _.agHelper.AssertContains(`/app/${modifiedSlug}`, "be.visible"); |
| 131 | + |
| 132 | + // Click on "Cancel" button in the modal instead of confirming |
| 133 | + // This should close the modal without persisting the slug |
| 134 | + _.agHelper.GetNClickByContains(AdminsSettings.staticUrlConfirmationCancel, "Cancel"); |
| 135 | + |
| 136 | + // Verify the modal is closed |
| 137 | + _.agHelper.AssertElementAbsence(AdminsSettings.staticUrlConfirmationModal); |
| 138 | + |
| 139 | + // Reload the page |
| 140 | + _.agHelper.CypressReload(); |
| 141 | + |
| 142 | + // Wait for the page to load |
| 143 | + _.appSettings.OpenAppSettings(); |
| 144 | + _.appSettings.GoToGeneralSettings(); |
| 145 | + |
| 146 | + // Verify the modified slug does NOT persist after reload |
| 147 | + // The slug should revert to the previously persisted slug (from test 3) |
| 148 | + _.agHelper.AssertElementVisibility(AdminsSettings.generalSettingsStaticAppSlug); |
| 149 | + _.agHelper.AssertText(AdminsSettings.generalSettingsStaticAppSlug, "val", persistedSlugStr); |
| 150 | + // Note: AssertText doesn't support "not.have.value", so keeping the original assertion |
| 151 | + cy.get(AdminsSettings.generalSettingsStaticAppSlug).should("not.have.value", modifiedSlug); |
| 152 | + }); |
| 153 | + }); |
| 154 | + |
| 155 | + it("5. Should delete persisted slug and generate new slug when Static URL is disabled and re-enabled", () => { |
| 156 | + // Continue from test 4 - slug is already persisted from previous test |
| 157 | + // Get the current persisted slug and application name |
| 158 | + let appNameStr: string; |
| 159 | + let persistedSlugStr: string; |
| 160 | + |
| 161 | + _.agHelper.GetText(AdminsSettings.generalSettingsAppName, "val").then((appName) => { |
| 162 | + appNameStr = appName as string; |
| 163 | + }); |
| 164 | + |
| 165 | + _.agHelper.GetText(AdminsSettings.generalSettingsStaticAppSlug, "val").then((persistedSlug) => { |
| 166 | + persistedSlugStr = persistedSlug as string; |
| 167 | + }); |
| 168 | + |
| 169 | + cy.then(() => { |
| 170 | + // Convert app name to expected slug format (lowercase, spaces replaced with hyphens) |
| 171 | + const expectedSlug = appNameStr |
| 172 | + .toLowerCase() |
| 173 | + .trim() |
| 174 | + .replace(/\s+/g, "-") |
| 175 | + .replace(/[^a-z0-9-]/g, ""); // Remove any special characters except hyphens |
| 176 | + |
| 177 | + // Disable Static URL toggle |
| 178 | + _.agHelper.GetNClick(AdminsSettings.generalSettingsStaticUrl); |
| 179 | + |
| 180 | + // Verify the confirmation modal appears for disabling |
| 181 | + _.agHelper.AssertElementVisibility(AdminsSettings.staticUrlConfirmationModal); |
| 182 | + _.agHelper.AssertContains("Disable App Static URL", "be.visible"); |
| 183 | + |
| 184 | + // Confirm disabling in the modal |
| 185 | + _.agHelper.GetNClickByContains(AdminsSettings.staticUrlConfirmationConfirm, "Disable Static URL"); |
| 186 | + |
| 187 | + // Wait for the snackbar notification |
| 188 | + _.agHelper.ValidateToastMessage("Static URL disabled. The app has reverted to default Appsmith URLs."); |
| 189 | + |
| 190 | + // Verify the slug input field is no longer visible (toggle is off) |
| 191 | + _.agHelper.AssertElementAbsence(AdminsSettings.generalSettingsStaticAppSlug); |
| 192 | + |
| 193 | + // Re-enable Static URL toggle |
| 194 | + _.agHelper.GetNClick(AdminsSettings.generalSettingsStaticUrl); |
| 195 | + |
| 196 | + // Wait for the API call to fetch new slug suggestion |
| 197 | + _.assertHelper.WaitForNetworkCall("@fetchAppSlugSuggestion").then((response: any) => { |
| 198 | + const newSuggestedSlug = response.body.data; |
| 199 | + |
| 200 | + // Verify the slug input field is visible again |
| 201 | + _.agHelper.AssertElementVisibility(AdminsSettings.generalSettingsStaticAppSlug); |
| 202 | + _.agHelper.AssertText(AdminsSettings.generalSettingsStaticAppSlug, "val", newSuggestedSlug); |
| 203 | + |
| 204 | + // Verify the new slug is different from the previously persisted slug |
| 205 | + expect(newSuggestedSlug).to.not.eq(persistedSlugStr); |
| 206 | + |
| 207 | + // Verify the new slug starts with the expected slug derived from the application name |
| 208 | + // Backend appends a random hash after a hyphen for uniqueness |
| 209 | + expect(newSuggestedSlug).to.satisfy((slug: string) => |
| 210 | + slug.startsWith(`${expectedSlug}-`) |
| 211 | + ); |
| 212 | + }); |
| 213 | + }); |
| 214 | + }); |
| 215 | +}); |
0 commit comments