|
| 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 | +} from '../../../../support/commands/constants/command_constants'; |
| 8 | + |
| 9 | +// Component route url |
| 10 | +const COMPONENT_ROUTE_URL = '/catalog/explorer'; |
| 11 | + |
| 12 | +// Menu options |
| 13 | +const SERVICES_MENU_OPTION = 'Services'; |
| 14 | +const CATALOGS_MENU_OPTION = 'Catalogs'; |
| 15 | + |
| 16 | +// Accordion items |
| 17 | +const CATALOG_ITEMS_ACCORDION_ITEM = 'Catalog Items'; |
| 18 | +const ALL_CATALOG_ITEMS_ACCORDION_ITEM = 'All Catalog Items'; |
| 19 | +const UNASSIGNED_ACCORDION_ITEM = 'Unassigned'; |
| 20 | + |
| 21 | +// Config options |
| 22 | +const CONFIG_TOOLBAR_BUTTON = 'Configuration'; |
| 23 | +const ADD_CATALOG_ITEM_CONFIG_OPTION = 'Add a New Catalog Item'; |
| 24 | +const COPY_CONFIG_OPTION = 'Copy Selected Item'; |
| 25 | +const DELETE_CATALOG_ITEMS_CONFIG_OPTION = 'Delete Catalog Items'; |
| 26 | + |
| 27 | +// Field labels |
| 28 | +const FORM_HEADER = 'Catalog'; |
| 29 | +const NAME_FIELD_LABEL = 'Name'; |
| 30 | +const COPY_TAGS_FIELD_LABEL = 'Copy Tags'; |
| 31 | +const REMOVE_CATALOG_MODAL_HEADER_TEXT = 'Delete'; |
| 32 | + |
| 33 | +// Field values |
| 34 | +const CATALOG_ITEM_NAME = 'Test-Catalog-Item'; |
| 35 | +const COPIED_CATALOG_ITEM_NAME = `Copy of ${CATALOG_ITEM_NAME}`; |
| 36 | + |
| 37 | +// Flash message text snippets |
| 38 | +const FLASH_MESSAGE_INFO_TEXT = 'will not be displayed'; |
| 39 | +const FLASH_MESSAGE_ADDED = 'added'; |
| 40 | +const FLASH_MESSAGE_CANCELLED = 'cancelled'; |
| 41 | +const FLASH_MESSAGE_SAVED = 'saved'; |
| 42 | + |
| 43 | +// Buttons |
| 44 | +const ADD_BUTTON_TEXT = 'Add'; |
| 45 | +const CANCEL_BUTTON_TEXT = 'Cancel'; |
| 46 | +const DELETE_BUTTON_TEXT = 'Delete'; |
| 47 | + |
| 48 | +function cleanUp(catalogItemToDelete) { |
| 49 | + cy.url() |
| 50 | + .then((url) => { |
| 51 | + // Ensures navigation to Services -> Catalogs in the UI |
| 52 | + if (!url.endsWith(COMPONENT_ROUTE_URL)) { |
| 53 | + cy.visit(COMPONENT_ROUTE_URL); |
| 54 | + } |
| 55 | + cy.accordion(CATALOG_ITEMS_ACCORDION_ITEM); |
| 56 | + }) |
| 57 | + .then(() => { |
| 58 | + cy.selectAccordionItem([ |
| 59 | + ALL_CATALOG_ITEMS_ACCORDION_ITEM, |
| 60 | + UNASSIGNED_ACCORDION_ITEM, |
| 61 | + ]); |
| 62 | + cy.selectTableRowsByText({ |
| 63 | + textArray: [catalogItemToDelete], |
| 64 | + }); |
| 65 | + cy.toolbar(CONFIG_TOOLBAR_BUTTON, DELETE_CATALOG_ITEMS_CONFIG_OPTION); |
| 66 | + // TODO: Replace with expect_modal once #9653 is merged |
| 67 | + cy.contains( |
| 68 | + '.bx--modal-container .bx--modal-header', |
| 69 | + REMOVE_CATALOG_MODAL_HEADER_TEXT |
| 70 | + ); |
| 71 | + cy.contains( |
| 72 | + '.bx--modal-container .bx--modal-content', |
| 73 | + catalogItemToDelete |
| 74 | + ); |
| 75 | + cy.contains( |
| 76 | + '.bx--modal-container .bx--modal-footer button', |
| 77 | + DELETE_BUTTON_TEXT |
| 78 | + ).click(); |
| 79 | + // cy.expect_modal({ |
| 80 | + // modalHeaderText: REMOVE_CATALOG_MODAL_HEADER_TEXT, |
| 81 | + // modalContentExpectedTexts: [ |
| 82 | + // 'delete', |
| 83 | + // catalogItemToDelete, |
| 84 | + // ], |
| 85 | + // targetFooterButtonText: DELETE_BUTTON_TEXT, |
| 86 | + // }); |
| 87 | + }); |
| 88 | +} |
| 89 | + |
| 90 | +describe('Automate Catalog form operations: Services > Catalogs > Catalogs > Configuration > Add a New Catalog', () => { |
| 91 | + beforeEach(() => { |
| 92 | + cy.login(); |
| 93 | + cy.menu(SERVICES_MENU_OPTION, CATALOGS_MENU_OPTION); |
| 94 | + |
| 95 | + // TODO: replace with better data setup approach |
| 96 | + // Adding a catalog item |
| 97 | + cy.accordion(CATALOG_ITEMS_ACCORDION_ITEM); |
| 98 | + cy.selectAccordionItem([ |
| 99 | + ALL_CATALOG_ITEMS_ACCORDION_ITEM, |
| 100 | + UNASSIGNED_ACCORDION_ITEM, |
| 101 | + ]); |
| 102 | + cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_CATALOG_ITEM_CONFIG_OPTION); |
| 103 | + cy.contains('button[data-id="st_prov_type"]', 'Choose').click(); |
| 104 | + cy.contains('.form-group ul.dropdown-menu li a', 'Generic').click(); |
| 105 | + cy.get('input#name').type(CATALOG_ITEM_NAME); |
| 106 | + cy.contains('#form_buttons_div button', ADD_BUTTON_TEXT).click(); |
| 107 | + cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_ADDED); |
| 108 | + |
| 109 | + cy.selectAccordionItem([ |
| 110 | + ALL_CATALOG_ITEMS_ACCORDION_ITEM, |
| 111 | + UNASSIGNED_ACCORDION_ITEM, |
| 112 | + CATALOG_ITEM_NAME, |
| 113 | + ]); |
| 114 | + cy.toolbar(CONFIG_TOOLBAR_BUTTON, COPY_CONFIG_OPTION); |
| 115 | + }); |
| 116 | + |
| 117 | + describe('Verify form elements, validate cancel button and validate name related error messages', () => { |
| 118 | + it('Verify form elements and validate cancel button', () => { |
| 119 | + // Verifying elements |
| 120 | + cy.expect_explorer_title(FORM_HEADER); |
| 121 | + cy.expect_flash(flashClassMap.info, FLASH_MESSAGE_INFO_TEXT); |
| 122 | + cy.validateFormLabels([ |
| 123 | + { |
| 124 | + [LABEL_CONFIG_KEYS.FOR_VALUE]: 'name', |
| 125 | + [LABEL_CONFIG_KEYS.EXPECTED_TEXT]: NAME_FIELD_LABEL, |
| 126 | + }, |
| 127 | + { |
| 128 | + [LABEL_CONFIG_KEYS.FOR_VALUE]: 'copy_tags', |
| 129 | + [LABEL_CONFIG_KEYS.EXPECTED_TEXT]: COPY_TAGS_FIELD_LABEL, |
| 130 | + }, |
| 131 | + ]); |
| 132 | + cy.validateFormFields([ |
| 133 | + { |
| 134 | + [FIELD_CONFIG_KEYS.ID]: 'name', |
| 135 | + [FIELD_CONFIG_KEYS.EXPECTED_VALUE]: COPIED_CATALOG_ITEM_NAME, |
| 136 | + }, |
| 137 | + { |
| 138 | + [FIELD_CONFIG_KEYS.ID]: 'copy_tags', |
| 139 | + [FIELD_CONFIG_KEYS.INPUT_FIELD_TYPE]: 'checkbox', |
| 140 | + }, |
| 141 | + ]); |
| 142 | + cy.validateFormFooterButtons([ |
| 143 | + { |
| 144 | + [BUTTON_CONFIG_KEYS.BUTTON_TEXT]: ADD_BUTTON_TEXT, |
| 145 | + [BUTTON_CONFIG_KEYS.BUTTON_TYPE]: 'submit', |
| 146 | + }, |
| 147 | + { |
| 148 | + [BUTTON_CONFIG_KEYS.BUTTON_TEXT]: CANCEL_BUTTON_TEXT, |
| 149 | + }, |
| 150 | + ]); |
| 151 | + // Cancel |
| 152 | + cy.getFormFooterButtonByTypeWithText({ |
| 153 | + buttonText: CANCEL_BUTTON_TEXT, |
| 154 | + }).click(); |
| 155 | + cy.expect_flash(flashClassMap.warning, FLASH_MESSAGE_CANCELLED); |
| 156 | + }); |
| 157 | + |
| 158 | + it('Validate error messages for blank or already-used names', () => { |
| 159 | + // Blank name |
| 160 | + cy.getFormInputFieldByIdAndType({ inputId: 'name' }).clear(); |
| 161 | + // TODO: Replace with expect_inline_field_errors once #9653 is merged |
| 162 | + cy.contains('#name-error-msg', 'blank'); |
| 163 | + // cy.expect_inline_field_errors({ containsText: 'blank' }); |
| 164 | + // Duplicate name |
| 165 | + cy.getFormInputFieldByIdAndType({ inputId: 'name' }) |
| 166 | + .clear() |
| 167 | + .type(CATALOG_ITEM_NAME); |
| 168 | + // TODO: Replace with expect_inline_field_errors once #9653 is merged |
| 169 | + cy.contains('#name-error-msg', 'taken'); |
| 170 | + // cy.expect_inline_field_errors({ containsText: 'taken' }); |
| 171 | + }); |
| 172 | + }); |
| 173 | + |
| 174 | + describe('Validate copy functionality', () => { |
| 175 | + it('Verify add operation from copy catalog form', () => { |
| 176 | + cy.getFormLabelByForAttribute({ |
| 177 | + forValue: 'copy_tags', |
| 178 | + }).click(); |
| 179 | + cy.getFormFooterButtonByTypeWithText({ |
| 180 | + buttonText: ADD_BUTTON_TEXT, |
| 181 | + buttonType: 'submit', |
| 182 | + }).click(); |
| 183 | + cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_SAVED); |
| 184 | + }); |
| 185 | + |
| 186 | + afterEach(() => { |
| 187 | + // TODO: Replace with better cleanup approach |
| 188 | + cleanUp(COPIED_CATALOG_ITEM_NAME); |
| 189 | + }); |
| 190 | + }); |
| 191 | + |
| 192 | + afterEach(() => { |
| 193 | + // TODO: Replace with better cleanup approach |
| 194 | + cleanUp(CATALOG_ITEM_NAME); |
| 195 | + }); |
| 196 | +}); |
0 commit comments