Skip to content

Commit 9fb9287

Browse files
authored
Merge pull request #9697 from jrafanie/replace-cypress-manual-cleanup-with-db-state-restore
Cypress: Replace UI driven cleanup with db state restore
2 parents 40eba6e + 2b14c93 commit 9fb9287

File tree

2 files changed

+8
-102
lines changed

2 files changed

+8
-102
lines changed

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

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import {
77
DUAL_LIST_ACTION_TYPE,
88
} from '../../../../support/commands/constants/command_constants.js';
99

10-
// Component route url
11-
const COMPONENT_ROUTE_URL = '/catalog/explorer';
12-
1310
// Menu options
1411
const SERVICES_MENU_OPTION = 'Services';
1512
const CATALOGS_MENU_OPTION = 'Catalogs';
@@ -21,7 +18,6 @@ const DESCRIPTION_FIELD_LABEL = 'Description';
2118
const CATALOG_ITEMS_HEADER = 'Catalog Items';
2219
const DUAL_LIST_AVAILABLE_ITEMS_HEADER = 'Unassigned';
2320
const DUAL_LIST_SELECTED_ITEMS_HEADER = 'Selected';
24-
const REMOVE_CATALOG_MODAL_HEADER_TEXT = 'Delete';
2521

2622
// Field values
2723
const CATALOG_ITEM_NAME_1 = 'Test-Catalog-Item-1';
@@ -35,14 +31,12 @@ const ADD_CATALOG_ITEM_CONFIG_OPTION = 'Add a New Catalog Item';
3531
const ADD_CATALOG_CONFIG_OPTION = 'Add a New Catalog';
3632
const EDIT_CATALOG_CONFIG_OPTION = 'Edit this Item';
3733
const REMOVE_CATALOG_CONFIG_OPTION = 'Remove Catalog';
38-
const DELETE_CATALOG_ITEMS_CONFIG_OPTION = 'Delete Catalog Items';
3934

4035
// Buttons
4136
const ADD_BUTTON_TEXT = 'Add';
4237
const SAVE_BUTTON_TEXT = 'Save';
4338
const CANCEL_BUTTON_TEXT = 'Cancel';
4439
const RESET_BUTTON_TEXT = 'Reset';
45-
const DELETE_BUTTON_TEXT = 'Delete';
4640

4741
// Flash message text snippets
4842
const FLASH_MESSAGE_ADDED = 'added';
@@ -149,6 +143,10 @@ describe('Automate Catalog form operations: Services > Catalogs > Catalogs > Con
149143
cy.selectAccordionItem([ALL_CATALOGS_ACCORDION_ITEM]);
150144
});
151145

146+
afterEach(() => {
147+
cy.appDbState('restore');
148+
});
149+
152150
describe('Validate add form fields and verify add, edit, and delete operations', () => {
153151
beforeEach(() => {
154152
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_CATALOG_CONFIG_OPTION);
@@ -254,59 +252,5 @@ describe('Automate Catalog form operations: Services > Catalogs > Catalogs > Con
254252
);
255253
cy.expect_inline_field_errors({ containsText: 'taken' });
256254
});
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-
});
311255
});
312256
});

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

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import {
66
BUTTON_CONFIG_KEYS,
77
} from '../../../../support/commands/constants/command_constants';
88

9-
// Component route url
10-
const COMPONENT_ROUTE_URL = '/catalog/explorer';
11-
129
// Menu options
1310
const SERVICES_MENU_OPTION = 'Services';
1411
const CATALOGS_MENU_OPTION = 'Catalogs';
@@ -22,13 +19,11 @@ const UNASSIGNED_ACCORDION_ITEM = 'Unassigned';
2219
const CONFIG_TOOLBAR_BUTTON = 'Configuration';
2320
const ADD_CATALOG_ITEM_CONFIG_OPTION = 'Add a New Catalog Item';
2421
const COPY_CONFIG_OPTION = 'Copy Selected Item';
25-
const DELETE_CATALOG_ITEMS_CONFIG_OPTION = 'Delete Catalog Items';
2622

2723
// Field labels
2824
const FORM_HEADER = 'Catalog';
2925
const NAME_FIELD_LABEL = 'Name';
3026
const COPY_TAGS_FIELD_LABEL = 'Copy Tags';
31-
const REMOVE_CATALOG_MODAL_HEADER_TEXT = 'Delete';
3227

3328
// Field values
3429
const CATALOG_ITEM_NAME = 'Test-Catalog-Item';
@@ -43,33 +38,6 @@ const FLASH_MESSAGE_SAVED = 'saved';
4338
// Buttons
4439
const ADD_BUTTON_TEXT = 'Add';
4540
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-
cy.expect_modal({
67-
modalHeaderText: REMOVE_CATALOG_MODAL_HEADER_TEXT,
68-
modalContentExpectedTexts: ['delete', catalogItemToDelete],
69-
targetFooterButtonText: DELETE_BUTTON_TEXT,
70-
});
71-
});
72-
}
7341

7442
describe('Automate Catalog form operations: Services > Catalogs > Catalogs > Configuration > Add a New Catalog', () => {
7543
beforeEach(() => {
@@ -98,6 +66,10 @@ describe('Automate Catalog form operations: Services > Catalogs > Catalogs > Con
9866
cy.toolbar(CONFIG_TOOLBAR_BUTTON, COPY_CONFIG_OPTION);
9967
});
10068

69+
afterEach(() => {
70+
cy.appDbState('restore');
71+
});
72+
10173
describe('Verify form elements, validate cancel button and validate name related error messages', () => {
10274
it('Verify form elements and validate cancel button', () => {
10375
// Verifying elements
@@ -162,15 +134,5 @@ describe('Automate Catalog form operations: Services > Catalogs > Catalogs > Con
162134
}).click();
163135
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_SAVED);
164136
});
165-
166-
afterEach(() => {
167-
// TODO: Replace with better cleanup approach
168-
cleanUp(COPIED_CATALOG_ITEM_NAME);
169-
});
170-
});
171-
172-
afterEach(() => {
173-
// TODO: Replace with better cleanup approach
174-
cleanUp(CATALOG_ITEM_NAME);
175137
});
176138
});

0 commit comments

Comments
 (0)