Skip to content

Commit bf47dcc

Browse files
authored
Merge pull request #9616 from asirvadAbrahamVarghese/enhance-select-accordion-item
Enhance select accordion item
2 parents 2146e07 + d3de9c5 commit bf47dcc

File tree

3 files changed

+30
-48
lines changed

3 files changed

+30
-48
lines changed

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,10 @@ describe('Automate Collect logs Edit form operations', () => {
226226
describe('Settings > Application Settings > Diagnostics > Manage IQ Region > Zone > Collect logs > Edit', () => {
227227
beforeEach(() => {
228228
// Select "Zone:" accordion item
229-
cy.interceptApi({
230-
alias: 'treeSelectApi',
231-
urlPattern:
232-
/ops\/tree_select\?id=.*&text=.*Zone.*Default.*Zone.*(current).*/,
233-
triggerFn: () =>
234-
cy.selectAccordionItem([
235-
MANAGEIQ_REGION_ACCORDION_ITEM,
236-
ZONE_ACCORDION_ITEM,
237-
]),
238-
});
229+
cy.selectAccordionItem([
230+
MANAGEIQ_REGION_ACCORDION_ITEM,
231+
ZONE_ACCORDION_ITEM,
232+
]);
239233
// Select collect logs tab and open edit form
240234
goToCollectLogsTabAndOpenEditForm();
241235
});

cypress/e2e/ui/validate-intercept-api-command.cy.js

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,11 @@ describe('Validate intercept command', () => {
1010

1111
it('Should register the alias, intercept, wait & validate response status code when an API is fired', () => {
1212
cy.accordion('Diagnostics');
13-
cy.interceptApi({
14-
alias: 'treeSelectApi',
15-
urlPattern: /\/ops\/tree_select\?id=.*&text=.*/,
16-
triggerFn: () => cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]),
17-
onApiResponse: (interception) => {
18-
expect(interception.response.statusCode).to.equal(200);
19-
},
20-
}).then(() => {
21-
// verifies that the alias is set and the request is intercepted & awaited
22-
cy.getInterceptedApiAliases().then((interceptedAliasesObject) => {
23-
expect(interceptedAliasesObject).to.have.property('post-treeSelectApi');
24-
});
13+
// Tree select api wait is handled from selectAccordionItem with alias 'treeSelectApi'
14+
cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]);
15+
// verifies that the alias is set and the request is intercepted & awaited
16+
cy.getInterceptedApiAliases().then((interceptedAliasesObject) => {
17+
expect(interceptedAliasesObject).to.have.property('post-treeSelectApi');
2518
});
2619
});
2720

@@ -32,19 +25,14 @@ describe('Validate intercept command', () => {
3225
urlPattern: /\/ops\/accordion_select\?id=.*/,
3326
triggerFn: () => cy.accordion('Diagnostics'),
3427
});
35-
// second api with alias 'treeSelectApi'
36-
cy.interceptApi({
37-
alias: 'treeSelectApi',
38-
urlPattern: /\/ops\/tree_select\?id=.*&text=.*/,
39-
triggerFn: () => cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]),
40-
}).then(() => {
41-
// verifies that both the aliases are set and the request is intercepted & awaited
42-
cy.getInterceptedApiAliases().then((interceptedAliasesObject) => {
43-
expect(interceptedAliasesObject).to.include.all.keys(
44-
'post-accordionSelectApi',
45-
'post-treeSelectApi'
46-
);
47-
});
28+
// second api with alias 'treeSelectApi'(Tree select api wait is handled from selectAccordionItem with alias 'treeSelectApi')
29+
cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]);
30+
// verifies that both the aliases are set and the request is intercepted & awaited
31+
cy.getInterceptedApiAliases().then((interceptedAliasesObject) => {
32+
expect(interceptedAliasesObject).to.include.all.keys(
33+
'post-accordionSelectApi',
34+
'post-treeSelectApi'
35+
);
4836
});
4937
});
5038

@@ -59,15 +47,10 @@ describe('Validate intercept command', () => {
5947
expect(Object.keys(interceptedAliasesObject).length).to.equal(1);
6048
});
6149
});
62-
// second first api with alias 'treeSelectApi'
63-
cy.interceptApi({
64-
alias: 'treeSelectApi',
65-
urlPattern: /\/ops\/tree_select\?id=.*&text=.*/,
66-
triggerFn: () => cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]),
67-
}).then(() => {
68-
cy.getInterceptedApiAliases().then((interceptedAliasesObject) => {
69-
expect(Object.keys(interceptedAliasesObject).length).to.equal(2);
70-
});
50+
// second api with alias 'treeSelectApi'(Tree select api wait is handled from selectAccordionItem with alias 'treeSelectApi')
51+
cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]);
52+
cy.getInterceptedApiAliases().then((interceptedAliasesObject) => {
53+
expect(Object.keys(interceptedAliasesObject).length).to.equal(2);
7154
});
7255
// third api with a duplicate alias as above 'accordionSelectApi'
7356
cy.interceptApi({

cypress/support/commands/explorer.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
4848
const isClickableNode = accordionPathIndex === accordionPath.length - 1;
4949

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

6767
if (isMatch) {
68-
/* @RemoveLater: Remove logger once the command is confirmed to be stable */
68+
/* TODO: Remove logger once the command is confirmed to be stable */
6969
Cypress.log({
7070
name: 'selectAccordionItem',
7171
message: `Matched "${liText}" at index ${i}`,
@@ -75,8 +75,13 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
7575
const currentLiElement = Cypress.$(listItems[i]);
7676
// If it's the last label in the path, then that is the desired item to click
7777
if (isClickableNode) {
78-
// Click the node corresponding to the last label in the given path and terminate
79-
cy.wrap(currentLiElement).click();
78+
// Click the node corresponding to the last label in the given path,
79+
// intercept & wait for the Tree-Select api and then terminate
80+
cy.interceptApi({
81+
alias: 'treeSelectApi',
82+
urlPattern: /\/[^\/]+\/tree_select\?id=.*&text=.*/,
83+
triggerFn: () => cy.wrap(currentLiElement).click(),
84+
});
8085
return;
8186
}
8287

0 commit comments

Comments
 (0)