|
| 1 | +/* eslint-disable no-undef */ |
| 2 | +import { flashClassMap } from '../../../../support/assertions/assertion_constants'; |
| 3 | +import { |
| 4 | + LABEL_CONFIG_KEYS, |
| 5 | + FIELD_CONFIG_KEYS, |
| 6 | + BUTTON_CONFIG_KEYS, |
| 7 | + DUAL_LIST_ACTION_TYPE, |
| 8 | +} from '../../../../support/commands/constants/command_constants.js'; |
| 9 | + |
| 10 | +// Component route url |
| 11 | +const COMPONENT_ROUTE_URL = '/catalog/explorer'; |
| 12 | + |
| 13 | +// Menu options |
| 14 | +const SERVICES_MENU_OPTION = 'Services'; |
| 15 | +const CATALOGS_MENU_OPTION = 'Catalogs'; |
| 16 | + |
| 17 | +// Field labels |
| 18 | +const FORM_HEADER = 'Catalog'; |
| 19 | +const NAME_FIELD_LABEL = 'Name'; |
| 20 | +const DESCRIPTION_FIELD_LABEL = 'Description'; |
| 21 | +const CATALOG_ITEMS_HEADER = 'Catalog Items'; |
| 22 | +const DUAL_LIST_AVAILABLE_ITEMS_HEADER = 'Unassigned'; |
| 23 | +const DUAL_LIST_SELECTED_ITEMS_HEADER = 'Selected'; |
| 24 | +const REMOVE_CATALOG_MODAL_HEADER_TEXT = 'Delete'; |
| 25 | + |
| 26 | +// Field values |
| 27 | +const CATALOG_ITEM_NAME_1 = 'Test-Catalog-Item-1'; |
| 28 | +const CATALOG_ITEM_NAME_2 = 'Test-Catalog-Item-2'; |
| 29 | +const TEST_CATALOG_NAME = 'Test-Catalog'; |
| 30 | +const TEST_DESCRIPTION = 'Test-Description'; |
| 31 | + |
| 32 | +// Config options |
| 33 | +const CONFIG_TOOLBAR_BUTTON = 'Configuration'; |
| 34 | +const ADD_CATALOG_ITEM_CONFIG_OPTION = 'Add a New Catalog Item'; |
| 35 | +const ADD_CATALOG_CONFIG_OPTION = 'Add a New Catalog'; |
| 36 | +const EDIT_CATALOG_CONFIG_OPTION = 'Edit this Item'; |
| 37 | +const REMOVE_CATALOG_CONFIG_OPTION = 'Remove Catalog'; |
| 38 | +const DELETE_CATALOG_ITEMS_CONFIG_OPTION = 'Delete Catalog Items'; |
| 39 | + |
| 40 | +// Buttons |
| 41 | +const ADD_BUTTON_TEXT = 'Add'; |
| 42 | +const SAVE_BUTTON_TEXT = 'Save'; |
| 43 | +const CANCEL_BUTTON_TEXT = 'Cancel'; |
| 44 | +const RESET_BUTTON_TEXT = 'Reset'; |
| 45 | +const DELETE_BUTTON_TEXT = 'Delete'; |
| 46 | + |
| 47 | +// Flash message text snippets |
| 48 | +const FLASH_MESSAGE_ADDED = 'added'; |
| 49 | +const FLASH_MESSAGE_SAVED = 'saved'; |
| 50 | +const FLASH_MESSAGE_CANCELLED = 'cancelled'; |
| 51 | +const FLASH_MESSAGE_DELETED = 'delete'; |
| 52 | +const FLASH_MESSAGE_RESET = 'reset'; |
| 53 | + |
| 54 | +// Browser alert text snippets |
| 55 | +const BROWSER_ALERT_REMOVE_CONFIRM_TEXT = 'removed'; |
| 56 | + |
| 57 | +// Accordion items |
| 58 | +const CATALOGS_ACCORDION_ITEM = 'Catalogs'; |
| 59 | +const CATALOG_ITEMS_ACCORDION_ITEM = 'Catalog Items'; |
| 60 | +const ALL_CATALOGS_ACCORDION_ITEM = 'All Catalogs'; |
| 61 | +const ALL_CATALOG_ITEMS_ACCORDION_ITEM = 'All Catalog Items'; |
| 62 | +const UNASSIGNED_ACCORDION_ITEM = 'Unassigned'; |
| 63 | + |
| 64 | +function addCatalogItem(catalogItemName) { |
| 65 | + cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_CATALOG_ITEM_CONFIG_OPTION); |
| 66 | + cy.contains('button[data-id="st_prov_type"]', 'Choose').click(); |
| 67 | + cy.contains('.form-group ul.dropdown-menu li a', 'Generic').click(); |
| 68 | + cy.get('input#name').type(catalogItemName); |
| 69 | + cy.contains('#form_buttons_div button', ADD_BUTTON_TEXT).click(); |
| 70 | + cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_ADDED); |
| 71 | +} |
| 72 | + |
| 73 | +function validateElements({ isEditForm }) { |
| 74 | + cy.expect_explorer_title(FORM_HEADER); |
| 75 | + // Validate form labels |
| 76 | + cy.validateFormLabels([ |
| 77 | + { |
| 78 | + [LABEL_CONFIG_KEYS.FOR_VALUE]: 'name', |
| 79 | + [LABEL_CONFIG_KEYS.EXPECTED_TEXT]: NAME_FIELD_LABEL, |
| 80 | + }, |
| 81 | + { |
| 82 | + [LABEL_CONFIG_KEYS.FOR_VALUE]: 'description', |
| 83 | + [LABEL_CONFIG_KEYS.EXPECTED_TEXT]: DESCRIPTION_FIELD_LABEL, |
| 84 | + }, |
| 85 | + ]); |
| 86 | + // Validate form fields |
| 87 | + cy.validateFormFields([ |
| 88 | + { |
| 89 | + [FIELD_CONFIG_KEYS.ID]: 'name', |
| 90 | + }, |
| 91 | + { |
| 92 | + [FIELD_CONFIG_KEYS.ID]: 'description', |
| 93 | + }, |
| 94 | + ]); |
| 95 | + // Validate form footer buttons |
| 96 | + cy.validateFormFooterButtons([ |
| 97 | + { |
| 98 | + [BUTTON_CONFIG_KEYS.BUTTON_TEXT]: isEditForm |
| 99 | + ? SAVE_BUTTON_TEXT |
| 100 | + : ADD_BUTTON_TEXT, |
| 101 | + [BUTTON_CONFIG_KEYS.BUTTON_TYPE]: 'submit', |
| 102 | + [BUTTON_CONFIG_KEYS.SHOULD_BE_DISABLED]: true, |
| 103 | + }, |
| 104 | + { |
| 105 | + [BUTTON_CONFIG_KEYS.BUTTON_TEXT]: CANCEL_BUTTON_TEXT, |
| 106 | + }, |
| 107 | + ...(isEditForm |
| 108 | + ? [ |
| 109 | + { |
| 110 | + [BUTTON_CONFIG_KEYS.BUTTON_TEXT]: RESET_BUTTON_TEXT, |
| 111 | + [BUTTON_CONFIG_KEYS.SHOULD_BE_DISABLED]: true, |
| 112 | + }, |
| 113 | + ] |
| 114 | + : []), |
| 115 | + ]); |
| 116 | + cy.getFormLegendByText({ legendText: CATALOG_ITEMS_HEADER }); |
| 117 | + if (isEditForm) { |
| 118 | + cy.expect_dual_list({ |
| 119 | + availableItemsHeaderText: DUAL_LIST_AVAILABLE_ITEMS_HEADER, |
| 120 | + selectedItemsHeaderText: DUAL_LIST_SELECTED_ITEMS_HEADER, |
| 121 | + // Test-Catalog-Item-1 is added while creating the catalog item so it will be on the right side |
| 122 | + selectedItems: [CATALOG_ITEM_NAME_1], |
| 123 | + }); |
| 124 | + } else { |
| 125 | + cy.expect_dual_list({ |
| 126 | + availableItemsHeaderText: DUAL_LIST_AVAILABLE_ITEMS_HEADER, |
| 127 | + selectedItemsHeaderText: DUAL_LIST_SELECTED_ITEMS_HEADER, |
| 128 | + availableItems: [CATALOG_ITEM_NAME_1, CATALOG_ITEM_NAME_2], |
| 129 | + }); |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +describe('Automate Catalog form operations: Services > Catalogs > Catalogs > Configuration > Add a New Catalog', () => { |
| 134 | + beforeEach(() => { |
| 135 | + cy.login(); |
| 136 | + cy.menu(SERVICES_MENU_OPTION, CATALOGS_MENU_OPTION); |
| 137 | + |
| 138 | + // TODO: replace with better data setup approach |
| 139 | + // Adding 2 catalog items first before validating Catalog form |
| 140 | + cy.accordion(CATALOG_ITEMS_ACCORDION_ITEM); |
| 141 | + cy.selectAccordionItem([ |
| 142 | + ALL_CATALOG_ITEMS_ACCORDION_ITEM, |
| 143 | + UNASSIGNED_ACCORDION_ITEM, |
| 144 | + ]); |
| 145 | + addCatalogItem(CATALOG_ITEM_NAME_1); |
| 146 | + addCatalogItem(CATALOG_ITEM_NAME_2); |
| 147 | + |
| 148 | + cy.accordion(CATALOGS_ACCORDION_ITEM); |
| 149 | + cy.selectAccordionItem([ALL_CATALOGS_ACCORDION_ITEM]); |
| 150 | + }); |
| 151 | + |
| 152 | + describe('Validate add form fields and verify add, edit, and delete operations', () => { |
| 153 | + beforeEach(() => { |
| 154 | + cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_CATALOG_CONFIG_OPTION); |
| 155 | + }); |
| 156 | + |
| 157 | + it('Verify visibility of elements and validate cancel button', () => { |
| 158 | + // Validate elements |
| 159 | + validateElements({ isEditForm: false }); |
| 160 | + // Cancel |
| 161 | + cy.getFormFooterButtonByTypeWithText({ |
| 162 | + buttonText: CANCEL_BUTTON_TEXT, |
| 163 | + }).click(); |
| 164 | + cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_CANCELLED); |
| 165 | + }); |
| 166 | + |
| 167 | + it('Verify add, edit & delete catalog', () => { |
| 168 | + // Add |
| 169 | + cy.getFormInputFieldByIdAndType({ inputId: 'name' }).type( |
| 170 | + TEST_CATALOG_NAME |
| 171 | + ); |
| 172 | + cy.getFormInputFieldByIdAndType({ inputId: 'description' }).type( |
| 173 | + TEST_DESCRIPTION |
| 174 | + ); |
| 175 | + cy.dualListAction({ |
| 176 | + actionType: DUAL_LIST_ACTION_TYPE.ADD, |
| 177 | + optionsToSelect: [CATALOG_ITEM_NAME_1], |
| 178 | + }); |
| 179 | + cy.getFormFooterButtonByTypeWithText({ |
| 180 | + buttonText: ADD_BUTTON_TEXT, |
| 181 | + buttonType: 'submit', |
| 182 | + }).click(); |
| 183 | + cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_SAVED); |
| 184 | + // Edit |
| 185 | + cy.selectAccordionItem([ALL_CATALOGS_ACCORDION_ITEM, TEST_CATALOG_NAME]); |
| 186 | + cy.toolbar(CONFIG_TOOLBAR_BUTTON, EDIT_CATALOG_CONFIG_OPTION); |
| 187 | + cy.getFormInputFieldByIdAndType({ inputId: 'description' }).type( |
| 188 | + '-Updated' |
| 189 | + ); |
| 190 | + cy.getFormFooterButtonByTypeWithText({ |
| 191 | + buttonText: SAVE_BUTTON_TEXT, |
| 192 | + buttonType: 'submit', |
| 193 | + }).click(); |
| 194 | + cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_SAVED); |
| 195 | + // Delete |
| 196 | + cy.selectAccordionItem([ALL_CATALOGS_ACCORDION_ITEM, TEST_CATALOG_NAME]); |
| 197 | + cy.expect_browser_confirm_with_text({ |
| 198 | + confirmTriggerFn: () => |
| 199 | + cy.toolbar(CONFIG_TOOLBAR_BUTTON, REMOVE_CATALOG_CONFIG_OPTION), |
| 200 | + containsText: BROWSER_ALERT_REMOVE_CONFIRM_TEXT, |
| 201 | + }); |
| 202 | + cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_DELETED); |
| 203 | + }); |
| 204 | + }); |
| 205 | + |
| 206 | + describe('Validate edit form fields and catalog name uniqueness', () => { |
| 207 | + beforeEach(() => { |
| 208 | + cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_CATALOG_CONFIG_OPTION); |
| 209 | + cy.getFormInputFieldByIdAndType({ inputId: 'name' }).type( |
| 210 | + TEST_CATALOG_NAME |
| 211 | + ); |
| 212 | + cy.getFormInputFieldByIdAndType({ inputId: 'description' }).type( |
| 213 | + TEST_DESCRIPTION |
| 214 | + ); |
| 215 | + cy.dualListAction({ |
| 216 | + actionType: DUAL_LIST_ACTION_TYPE.ADD, |
| 217 | + optionsToSelect: [CATALOG_ITEM_NAME_1], |
| 218 | + }); |
| 219 | + cy.getFormFooterButtonByTypeWithText({ |
| 220 | + buttonText: ADD_BUTTON_TEXT, |
| 221 | + buttonType: 'submit', |
| 222 | + }).click(); |
| 223 | + cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_SAVED); |
| 224 | + }); |
| 225 | + |
| 226 | + it('Verify visibility of elements and validate reset & cancel buttons', () => { |
| 227 | + // Validate elements |
| 228 | + cy.selectAccordionItem([ALL_CATALOGS_ACCORDION_ITEM, TEST_CATALOG_NAME]); |
| 229 | + cy.toolbar(CONFIG_TOOLBAR_BUTTON, EDIT_CATALOG_CONFIG_OPTION); |
| 230 | + validateElements({ isEditForm: true }); |
| 231 | + // Reset |
| 232 | + cy.getFormInputFieldByIdAndType({ inputId: 'description' }).type( |
| 233 | + '-Updated' |
| 234 | + ); |
| 235 | + cy.getFormFooterButtonByTypeWithText({ |
| 236 | + buttonText: RESET_BUTTON_TEXT, |
| 237 | + }).click(); |
| 238 | + cy.expect_flash(flashClassMap.warning, FLASH_MESSAGE_RESET); |
| 239 | + cy.getFormInputFieldByIdAndType({ inputId: 'description' }).should( |
| 240 | + 'have.value', |
| 241 | + TEST_DESCRIPTION |
| 242 | + ); |
| 243 | + // Cancel |
| 244 | + cy.getFormFooterButtonByTypeWithText({ |
| 245 | + buttonText: CANCEL_BUTTON_TEXT, |
| 246 | + }).click(); |
| 247 | + cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_CANCELLED); |
| 248 | + }); |
| 249 | + |
| 250 | + it('Catalog name uniqueness validation', () => { |
| 251 | + cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_CATALOG_CONFIG_OPTION); |
| 252 | + cy.getFormInputFieldByIdAndType({ inputId: 'name' }).type( |
| 253 | + TEST_CATALOG_NAME |
| 254 | + ); |
| 255 | + cy.expect_inline_field_errors({ containsText: 'taken' }); |
| 256 | + }); |
| 257 | + |
| 258 | + afterEach(() => { |
| 259 | + // TODO: Replace with better cleanup approach |
| 260 | + cy.url() |
| 261 | + .then((url) => { |
| 262 | + // Ensures navigation to Services -> Catalogs in the UI |
| 263 | + if (!url.endsWith(COMPONENT_ROUTE_URL)) { |
| 264 | + cy.visit(COMPONENT_ROUTE_URL); |
| 265 | + } |
| 266 | + cy.accordion(CATALOGS_ACCORDION_ITEM); |
| 267 | + }) |
| 268 | + .then(() => { |
| 269 | + cy.selectAccordionItem([ |
| 270 | + ALL_CATALOGS_ACCORDION_ITEM, |
| 271 | + TEST_CATALOG_NAME, |
| 272 | + ]); |
| 273 | + cy.expect_browser_confirm_with_text({ |
| 274 | + confirmTriggerFn: () => |
| 275 | + cy.toolbar(CONFIG_TOOLBAR_BUTTON, REMOVE_CATALOG_CONFIG_OPTION), |
| 276 | + containsText: BROWSER_ALERT_REMOVE_CONFIRM_TEXT, |
| 277 | + }); |
| 278 | + }); |
| 279 | + }); |
| 280 | + }); |
| 281 | + |
| 282 | + afterEach(() => { |
| 283 | + // TODO: Replace with better cleanup approach |
| 284 | + cy.url() |
| 285 | + .then((url) => { |
| 286 | + // Ensures navigation to Services -> Catalogs in the UI |
| 287 | + if (!url.endsWith(COMPONENT_ROUTE_URL)) { |
| 288 | + cy.visit(COMPONENT_ROUTE_URL); |
| 289 | + } |
| 290 | + cy.accordion(CATALOG_ITEMS_ACCORDION_ITEM); |
| 291 | + }) |
| 292 | + .then(() => { |
| 293 | + cy.selectAccordionItem([ |
| 294 | + ALL_CATALOG_ITEMS_ACCORDION_ITEM, |
| 295 | + UNASSIGNED_ACCORDION_ITEM, |
| 296 | + ]); |
| 297 | + cy.selectTableRowsByText({ |
| 298 | + textArray: [CATALOG_ITEM_NAME_1, CATALOG_ITEM_NAME_2], |
| 299 | + }); |
| 300 | + cy.toolbar(CONFIG_TOOLBAR_BUTTON, DELETE_CATALOG_ITEMS_CONFIG_OPTION); |
| 301 | + cy.expect_modal({ |
| 302 | + modalHeaderText: REMOVE_CATALOG_MODAL_HEADER_TEXT, |
| 303 | + modalContentExpectedTexts: [ |
| 304 | + 'delete', |
| 305 | + CATALOG_ITEM_NAME_1, |
| 306 | + CATALOG_ITEM_NAME_2, |
| 307 | + ], |
| 308 | + targetFooterButtonText: DELETE_BUTTON_TEXT, |
| 309 | + }); |
| 310 | + }); |
| 311 | + }); |
| 312 | +}); |
0 commit comments