Skip to content

Commit a803026

Browse files
committed
Convert tests to use appDbState capture/restore and factories
1 parent e4d2344 commit a803026

File tree

4 files changed

+26
-148
lines changed

4 files changed

+26
-148
lines changed

cypress/e2e/ui/Automation/Embedded-Automate/Explorer/class.cy.js

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,23 @@
11
/* eslint-disable no-undef */
22

33
describe('Automation > Embedded Automate > Explorer', () => {
4-
before(() => {
5-
// Create a Domain and Namespace before all the tests
4+
beforeEach(() => {
5+
cy.appFactories([
6+
['create', 'miq_ae_domain', {name: 'TestDomain'}],
7+
]).then((results) => {
8+
cy.appFactories([
9+
['create', 'miq_ae_namespace', {name: 'TestNameSpace', domain_id: results[0].id}]
10+
])
11+
});
12+
613
cy.login();
714
cy.intercept('POST', '/ops/accordion_select?id=rbac_accord').as('accordion');
815
cy.menu('Automation', 'Embedded Automate', 'Explorer');
916
cy.get('#explorer_title_text');
10-
11-
// Creates a Domain
12-
cy.get('[title="Datastore"]').click();
13-
cy.get('[title="Configuration"]').click();
14-
cy.get('[title="Add a New Domain"]').click();
15-
cy.get('[name="name"]').type('TestDomain', {force: true});
16-
cy.get('[name="description"]').type('This is a test domain');
17-
cy.get('#enabled').check();
18-
cy.get('[class="bx--btn bx--btn--primary"]').contains('Add').click();
19-
20-
// Check for the success message
21-
cy.get('div.alert.alert-success.alert-dismissable').should('exist').and('contain', 'Automate Domain "TestDomain" was added').find('button.close').should('exist');
22-
23-
// Creates a Namespace
24-
cy.get('[title="Datastore"]').click();
25-
cy.get('[title="Automate Domain: TestDomain"]').click(); // Click on Domain
26-
cy.get('[title="Configuration"]').click();
27-
cy.get('[title="Add a New Namespace"]').click();
28-
cy.get('[name="name"]').type('TestNameSpace', {force: true});
29-
cy.get('[name="description"]').type('This is a test NameSpace');
30-
cy.get('.bx--btn--primary').contains('Add').click();
31-
32-
// Wait for namespace to be visible
33-
cy.get('[title="Automate Namespace: TestNameSpace"]', {timeout: 1000}).should('be.visible')
3417
});
3518

36-
beforeEach(() => {
37-
cy.login();
38-
cy.intercept('POST', '/ops/accordion_select?id=rbac_accord').as('accordion');
39-
cy.menu('Automation', 'Embedded Automate', 'Explorer');
40-
cy.get('#explorer_title_text');
19+
afterEach(() => {
20+
cy.appDbState('restore');
4121
});
4222

4323
describe('Class Form', () => {
@@ -268,15 +248,4 @@ describe('Automation > Embedded Automate > Explorer', () => {
268248
cy.get('#ns_details_div > .alert').contains('The selected Namespace is empty');
269249
});
270250
});
271-
272-
after(() => {
273-
// Remove the Domain after all the tests
274-
cy.menu('Automation', 'Embedded Automate', 'Explorer');
275-
cy.get('[title="Datastore"]').click({force: true});
276-
cy.get('[title="Automate Domain: TestDomain"]').click({force: true});
277-
cy.get('[title="Configuration"]').click({force: true});
278-
cy.get('[title="Remove this Domain"]').click({force: true});
279-
280-
cy.get('.bx--data-table-content tbody tr').should('not.contain', 'Automate Domain: TestDomain');
281-
});
282251
});

cypress/e2e/ui/Automation/Embedded-Automate/Explorer/namespace.cy.js

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,23 @@ function createNamespaceAndOpenEditForm() {
122122

123123
describe('Automate operations on Namespaces: Automation -> Embedded Automate -> Explorer -> {Any-created-domain} -> Namespace form', () => {
124124
beforeEach(() => {
125+
cy.appFactories([
126+
['create', 'miq_ae_domain', {name: DOMAIN_NAME}],
127+
]);
128+
125129
cy.login();
126130
cy.menu(
127131
AUTOMATION_MENU_OPTION,
128132
EMBEDDED_AUTOMATION_MENU_OPTION,
129133
EXPLORER_MENU_OPTION
130134
);
131-
cy.accordion(DATA_STORE_ACCORDION_LABEL);
132-
/* TODO: DATA_SETUP - Refactor to use API for domain data setup */
133-
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_ADD_NEW_DOMAIN);
134-
addDomainOrNamespace({
135-
nameFieldValue: DOMAIN_NAME,
136-
});
137-
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_ADD_SUCCESS);
138135
cy.selectAccordionItem([DATA_STORE_ACCORDION_LABEL, DOMAIN_NAME]);
139136
});
140137

138+
afterEach(() => {
139+
cy.appDbState('restore');
140+
});
141+
141142
it('Validate Add Namespace form fields', () => {
142143
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_ADD_NEW_NAMESPACE);
143144
validateNamespaceFormFields();
@@ -245,34 +246,4 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
245246
}).click();
246247
cy.expect_flash(flashClassMap.warning, FLASH_MESSAGE_CANCELLED);
247248
});
248-
249-
afterEach(() => {
250-
cy.url()
251-
.then((url) => {
252-
// Ensures navigation to Automation -> Embedded Automate -> Explorer in the UI
253-
if (!url.endsWith(COMPONENT_ROUTE_URL)) {
254-
cy.visit(COMPONENT_ROUTE_URL);
255-
}
256-
cy.accordion(DATA_STORE_ACCORDION_LABEL);
257-
})
258-
.then(() => {
259-
cy.get('div.panel-collapse.collapse.in li.list-group-item').each(
260-
(item) => {
261-
const text = item.text().trim();
262-
if (text === DOMAIN_NAME) {
263-
if (!item.hasClass('node-selected')) {
264-
cy.wrap(item).click();
265-
}
266-
cy.expect_browser_confirm_with_text({
267-
confirmTriggerFn: () =>
268-
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_REMOVE_DOMAIN),
269-
containsText: BROWSER_CONFIRM_REMOVE_MESSAGE,
270-
});
271-
return false; // exit iteration
272-
}
273-
return null; // has no impact, just to get rid of eslint warning
274-
}
275-
);
276-
});
277-
});
278249
});

cypress/e2e/ui/Settings/Application-Settings/schedule.cy.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -534,36 +534,6 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
534534
});
535535

536536
afterEach(() => {
537-
cy.url()
538-
.then((url) => {
539-
// Ensures navigation to Settings -> Application-Settings in the UI
540-
if (!url.endsWith(COMPONENT_ROUTE_URL)) {
541-
cy.visit(COMPONENT_ROUTE_URL);
542-
}
543-
cy.accordion(SETTINGS_OPTION);
544-
})
545-
.then(() => {
546-
// Iterate and clean up any leftover schedules created during the test
547-
cy.get('div.panel-collapse.collapse.in li.list-group-item').each(
548-
(item) => {
549-
const text = item.text().trim();
550-
if (
551-
text === INITIAL_SCHEDULE_NAME ||
552-
text === EDITED_SCHEDULE_NAME
553-
) {
554-
if (!item.hasClass('node-selected')) {
555-
cy.wrap(item).click();
556-
}
557-
cy.expect_browser_confirm_with_text({
558-
confirmTriggerFn: () =>
559-
selectConfigMenu(DELETE_SCHEDULE_CONFIG_OPTION),
560-
containsText: BROWSER_ALERT_DELETE_CONFIRM_TEXT,
561-
});
562-
return false; // exit iteration
563-
}
564-
return null; // has no impact, just to get rid of eslint warning
565-
}
566-
);
567-
});
537+
cy.appDbState('restore');
568538
});
569539
});

cypress/e2e/ui/Settings/Application-Settings/tenant.cy.js

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -261,28 +261,6 @@ function editQuotasTable(quotaName = ALLOCATED_STORAGE_QUOTA, quotaValue) {
261261
});
262262
}
263263

264-
function rollbackQuotas() {
265-
cy.toolbar(CONFIG_TOOLBAR_BUTTON, MANAGE_QUOTAS_CONFIG_OPTION);
266-
let quotaDisabled = false;
267-
cy.get('#rbac_details .miq-data-table table tbody tr').each((row) => {
268-
const quotaValueInputWrapper = row.find('div.bx--text-input-wrapper');
269-
const isEnabled = !quotaValueInputWrapper.hasClass(
270-
'bx--text-input-wrapper--readonly'
271-
);
272-
if (isEnabled) {
273-
quotaDisabled = true;
274-
cy.wrap(row).find('span.bx--toggle__switch').click();
275-
}
276-
});
277-
// Save the form only if any quotas are reverted to disabled.
278-
cy.then(() => {
279-
if (quotaDisabled) {
280-
// Saving the form
281-
saveFormWithOptionalFlashCheck({ assertFlashMessage: false });
282-
}
283-
});
284-
}
285-
286264
describe('Automate Tenant form operations: Settings > Application Settings > Access Control > Tenants', () => {
287265
beforeEach(() => {
288266
cy.login();
@@ -337,7 +315,7 @@ describe('Automate Tenant form operations: Settings > Application Settings > Acc
337315
});
338316

339317
afterEach(() => {
340-
confirmUiNavigation(() => deleteAccordionItems([PROJECT_NAME_VALUE]));
318+
cy.appDbState('restore');
341319
});
342320
});
343321

@@ -362,7 +340,7 @@ describe('Automate Tenant form operations: Settings > Application Settings > Acc
362340
});
363341

364342
afterEach(() => {
365-
confirmUiNavigation(() => rollbackQuotas());
343+
cy.appDbState('restore');
366344
});
367345
});
368346
});
@@ -417,9 +395,7 @@ describe('Automate Tenant form operations: Settings > Application Settings > Acc
417395
});
418396

419397
afterEach(() => {
420-
confirmUiNavigation(() =>
421-
deleteAccordionItems([INITIAL_CHILD_TENANT_NAME])
422-
);
398+
cy.appDbState('restore');
423399
});
424400
});
425401

@@ -456,10 +432,7 @@ describe('Automate Tenant form operations: Settings > Application Settings > Acc
456432
});
457433

458434
afterEach(() => {
459-
deleteAccordionItems([
460-
INITIAL_CHILD_TENANT_NAME,
461-
EDITED_TENANT_NAME_VALUE,
462-
]);
435+
cy.appDbState('restore');
463436
});
464437
});
465438

@@ -479,10 +452,7 @@ describe('Automate Tenant form operations: Settings > Application Settings > Acc
479452
});
480453

481454
afterEach(() => {
482-
confirmUiNavigation(() => {
483-
deleteAccordionItems([PROJECT_NAME_VALUE]);
484-
deleteAccordionItems([INITIAL_CHILD_TENANT_NAME]);
485-
});
455+
cy.appDbState('restore');
486456
});
487457
});
488458

@@ -508,9 +478,7 @@ describe('Automate Tenant form operations: Settings > Application Settings > Acc
508478
});
509479

510480
afterEach(() => {
511-
confirmUiNavigation(() => {
512-
deleteAccordionItems([INITIAL_CHILD_TENANT_NAME]);
513-
});
481+
cy.appDbState('restore');
514482
});
515483
});
516484
});

0 commit comments

Comments
 (0)