Skip to content

Commit c550a0e

Browse files
authored
Merge pull request #9699 from jrafanie/replace-cypress-manual-ui-catalog-setup-with-factories
Replace cypress manual UI catalog setup with factories
2 parents 350d2ac + f8ffebb commit c550a0e

File tree

2 files changed

+27
-38
lines changed

2 files changed

+27
-38
lines changed

cypress/e2e/ui/Services/Catalogs/catalog.cy.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const TEST_DESCRIPTION = 'Test-Description';
2727

2828
// Config options
2929
const CONFIG_TOOLBAR_BUTTON = 'Configuration';
30-
const ADD_CATALOG_ITEM_CONFIG_OPTION = 'Add a New Catalog Item';
3130
const ADD_CATALOG_CONFIG_OPTION = 'Add a New Catalog';
3231
const EDIT_CATALOG_CONFIG_OPTION = 'Edit this Item';
3332
const REMOVE_CATALOG_CONFIG_OPTION = 'Remove Catalog';
@@ -39,7 +38,6 @@ const CANCEL_BUTTON_TEXT = 'Cancel';
3938
const RESET_BUTTON_TEXT = 'Reset';
4039

4140
// Flash message text snippets
42-
const FLASH_MESSAGE_ADDED = 'added';
4341
const FLASH_MESSAGE_SAVED = 'saved';
4442
const FLASH_MESSAGE_CANCELLED = 'cancelled';
4543
const FLASH_MESSAGE_DELETED = 'delete';
@@ -50,19 +48,7 @@ const BROWSER_ALERT_REMOVE_CONFIRM_TEXT = 'removed';
5048

5149
// Accordion items
5250
const CATALOGS_ACCORDION_ITEM = 'Catalogs';
53-
const CATALOG_ITEMS_ACCORDION_ITEM = 'Catalog Items';
5451
const ALL_CATALOGS_ACCORDION_ITEM = 'All Catalogs';
55-
const ALL_CATALOG_ITEMS_ACCORDION_ITEM = 'All Catalog Items';
56-
const UNASSIGNED_ACCORDION_ITEM = 'Unassigned';
57-
58-
function addCatalogItem(catalogItemName) {
59-
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_CATALOG_ITEM_CONFIG_OPTION);
60-
cy.contains('button[data-id="st_prov_type"]', 'Choose').click();
61-
cy.contains('.form-group ul.dropdown-menu li a', 'Generic').click();
62-
cy.get('input#name').type(catalogItemName);
63-
cy.contains('#form_buttons_div button', ADD_BUTTON_TEXT).click();
64-
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_ADDED);
65-
}
6652

6753
function validateElements({ isEditForm }) {
6854
cy.expect_explorer_title(FORM_HEADER);
@@ -126,19 +112,27 @@ function validateElements({ isEditForm }) {
126112

127113
describe('Automate Catalog form operations: Services > Catalogs > Catalogs > Configuration > Add a New Catalog', () => {
128114
beforeEach(() => {
115+
cy.appFactories([
116+
['create', 'service_template', {name: CATALOG_ITEM_NAME_1, generic_subtype: 'custom', prov_type: 'generic', display: true}],
117+
]).then((results) => {
118+
cy.appFactories([
119+
['create', 'resource_action', {action: 'Provision', resource_id: results[0].id, resource_type: 'ServiceTemplate'}],
120+
['create', 'resource_action', {action: 'Retirement', resource_id: results[0].id, resource_type: 'ServiceTemplate'}]
121+
])
122+
});
123+
124+
cy.appFactories([
125+
['create', 'service_template', {name: CATALOG_ITEM_NAME_2, generic_subtype: 'custom', prov_type: 'generic', display: true}],
126+
]).then((results) => {
127+
cy.appFactories([
128+
['create', 'resource_action', {action: 'Provision', resource_id: results[0].id, resource_type: 'ServiceTemplate'}],
129+
['create', 'resource_action', {action: 'Retirement', resource_id: results[0].id, resource_type: 'ServiceTemplate'}]
130+
])
131+
});
132+
129133
cy.login();
130134
cy.menu(SERVICES_MENU_OPTION, CATALOGS_MENU_OPTION);
131135

132-
// TODO: replace with better data setup approach
133-
// Adding 2 catalog items first before validating Catalog form
134-
cy.accordion(CATALOG_ITEMS_ACCORDION_ITEM);
135-
cy.selectAccordionItem([
136-
ALL_CATALOG_ITEMS_ACCORDION_ITEM,
137-
UNASSIGNED_ACCORDION_ITEM,
138-
]);
139-
addCatalogItem(CATALOG_ITEM_NAME_1);
140-
addCatalogItem(CATALOG_ITEM_NAME_2);
141-
142136
cy.accordion(CATALOGS_ACCORDION_ITEM);
143137
cy.selectAccordionItem([ALL_CATALOGS_ACCORDION_ITEM]);
144138
});

cypress/e2e/ui/Services/Catalogs/copy_catalog.cy.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const UNASSIGNED_ACCORDION_ITEM = 'Unassigned';
1717

1818
// Config options
1919
const CONFIG_TOOLBAR_BUTTON = 'Configuration';
20-
const ADD_CATALOG_ITEM_CONFIG_OPTION = 'Add a New Catalog Item';
2120
const COPY_CONFIG_OPTION = 'Copy Selected Item';
2221

2322
// Field labels
@@ -31,7 +30,6 @@ const COPIED_CATALOG_ITEM_NAME = `Copy of ${CATALOG_ITEM_NAME}`;
3130

3231
// Flash message text snippets
3332
const FLASH_MESSAGE_INFO_TEXT = 'will not be displayed';
34-
const FLASH_MESSAGE_ADDED = 'added';
3533
const FLASH_MESSAGE_CANCELLED = 'cancelled';
3634
const FLASH_MESSAGE_SAVED = 'saved';
3735

@@ -41,22 +39,19 @@ const CANCEL_BUTTON_TEXT = 'Cancel';
4139

4240
describe('Automate Catalog form operations: Services > Catalogs > Catalogs > Configuration > Add a New Catalog', () => {
4341
beforeEach(() => {
42+
cy.appFactories([
43+
['create', 'service_template', {name: CATALOG_ITEM_NAME, generic_subtype: 'custom', prov_type: 'generic', display: true}],
44+
]).then((results) => {
45+
cy.appFactories([
46+
['create', 'resource_action', {action: 'Provision', resource_id: results[0].id, resource_type: 'ServiceTemplate'}],
47+
['create', 'resource_action', {action: 'Retirement', resource_id: results[0].id, resource_type: 'ServiceTemplate'}]
48+
])
49+
});
50+
4451
cy.login();
4552
cy.menu(SERVICES_MENU_OPTION, CATALOGS_MENU_OPTION);
4653

47-
// TODO: replace with better data setup approach
48-
// Adding a catalog item
4954
cy.accordion(CATALOG_ITEMS_ACCORDION_ITEM);
50-
cy.selectAccordionItem([
51-
ALL_CATALOG_ITEMS_ACCORDION_ITEM,
52-
UNASSIGNED_ACCORDION_ITEM,
53-
]);
54-
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_CATALOG_ITEM_CONFIG_OPTION);
55-
cy.contains('button[data-id="st_prov_type"]', 'Choose').click();
56-
cy.contains('.form-group ul.dropdown-menu li a', 'Generic').click();
57-
cy.get('input#name').type(CATALOG_ITEM_NAME);
58-
cy.contains('#form_buttons_div button', ADD_BUTTON_TEXT).click();
59-
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_ADDED);
6055

6156
cy.selectAccordionItem([
6257
ALL_CATALOG_ITEMS_ACCORDION_ITEM,

0 commit comments

Comments
 (0)