Skip to content

Commit b39c4f0

Browse files
authored
Merge pull request #9531 from asirvadAbrahamVarghese/enhance-select-accordion-item
Scope accordion-item search to expanded panel only
2 parents 0f1de19 + bf15ecf commit b39c4f0

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

cypress/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ManageIQ implements the following cypress extensions:
3333

3434
* `cy.accordion(title)` - open an accordion panel. `title`: String for the accordion title for the accordion panel to open.
3535
* `cy.accordionItem(name)` - click on a record in the accordion panel. `name`: String for the record to click in the accordion panel.
36+
* `cy.selectAccordionItem(accordionPath)` - navigates the expanded accordion panel(use cy.accordion to expand an accordion panel) and then expand the nodes along the given path and click the final target item. `accordionPath`: A mixed array of strings and/or regex patterns that represent the path to the intended target node. e.g. Simple string path: `cy.selectAccordionItem(['Datastore', 'My-Domain', 'My-Namespace']);`, Path with regular expressions: `cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/, /^Server:/]);`, Mixed path with strings and regular expressions: `cy.selectAccordionItem([/^ManageIQ Region:/, 'Zones', /^Zone:/]);`
3637

3738
##### gtl
3839

cypress/e2e/ui/validate-select-accordion-item.cy.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
/* eslint-disable no-undef */
22

3-
describe('Validate clickItem', () => {
3+
/* @RemoveLater: Remove this test suite once the command is confirmed to be stable */
4+
describe('Validate select accordion item', () => {
45
beforeEach(() => {
56
cy.login();
67
cy.menu('Settings', 'Application Settings');
78
});
89

9-
it('should fail when an invalid node label is passed', (done) => {
10+
it('should search nodes only within expanded tree', () => {
11+
// expand Diagnostics tree
12+
cy.accordion('Diagnostics');
13+
// should open the path under Diagnostics even if
14+
// an identical one exists under Settings
15+
cy.selectAccordionItem([
16+
/^ManageIQ Region:/,
17+
/^Zone:/,
18+
/^Server:/,
19+
]);
20+
});
21+
22+
it('should fail when an invalid target node label is passed', (done) => {
1023
cy.accordion('Access Control');
1124

1225
cy.on('fail', (err) => {
@@ -17,7 +30,22 @@ describe('Validate clickItem', () => {
1730
cy.selectAccordionItem([
1831
'ManageIQ Region: Region 0 [0]',
1932
'Tenants',
20-
'No Company', // This label does not exist
33+
'No Company', // This target node is not valid
34+
]);
35+
});
36+
37+
it('should fail when an invalid intermediate node label is passed', (done) => {
38+
cy.accordion('Access Control');
39+
40+
cy.on('fail', (err) => {
41+
expect(err.message).to.include('not found');
42+
done();
43+
});
44+
45+
cy.selectAccordionItem([
46+
'ManageIQ Region: Region 0 [0]',
47+
'Tenants Section', // This intermediate node is not valid
48+
'My Company',
2149
]);
2250
});
2351

cypress/support/commands/explorer.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Cypress.Commands.add('accordionItem', (name) => {
3333
* If the path is not found, it will throw an error.
3434
*/
3535
Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
36-
cy.get('li.list-group-item').then(($items) => {
36+
cy.get('div.panel-collapse.collapse.in li.list-group-item').then(($items) => {
3737
// Converting jQuery collection to an array for easier manipulation
3838
const listItems = [...$items];
3939

@@ -49,7 +49,7 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
4949
const isClickableNode = accordionPathIndex === accordionPath.length - 1;
5050

5151
for (let i = searchStartIndex; i < listItems.length; i++) {
52-
/* To remove */
52+
/* @RemoveLater: Remove logger once the command is confirmed to be stable */
5353
Cypress.log({
5454
name: 'selectAccordionItem',
5555
message: `Loop index: ${i} & Searching for label: ${accordionLabel}`,
@@ -66,7 +66,7 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
6666
}
6767

6868
if (isMatch) {
69-
/* To remove */
69+
/* @RemoveLater: Remove logger once the command is confirmed to be stable */
7070
Cypress.log({
7171
name: 'selectAccordionItem',
7272
message: `Matched "${liText}" at index ${i}`,
@@ -106,7 +106,15 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
106106
}
107107
}
108108
// If we reach here, it means the label was not found
109-
throw new Error(`Accordion item: "${accordionLabel}" not found`);
109+
const errorMessage = `${
110+
isClickableNode ? 'Target' : 'Intermediate'
111+
} node - "${accordionLabel}" was not found`;
112+
Cypress.log({
113+
name: 'error',
114+
displayName: '❗ CypressError:',
115+
message: errorMessage,
116+
});
117+
throw new Error(errorMessage);
110118
};
111119

112120
// Start the recursive call from the first label in the given path

0 commit comments

Comments
 (0)