Skip to content

Commit af93f3e

Browse files
Add tests for interceptApi command
1 parent 033862c commit af93f3e

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* eslint-disable no-undef */
2+
3+
// TODO: Remove this test once interceptApi command becomes stable
4+
describe('Validate intercept command', () => {
5+
beforeEach(() => {
6+
cy.login();
7+
// Navigate to Application settings
8+
cy.menu('Settings', 'Application Settings');
9+
});
10+
11+
it('Should register the alias, intercept & wait when API fired', () => {
12+
cy.accordion('Diagnostics');
13+
cy.interceptApi({
14+
alias: 'treeSelectApi',
15+
urlPattern: /\/ops\/tree_select\?id=.*&text=.*/,
16+
triggerFn: () => cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]),
17+
}).then(() => {
18+
// verifies that the alias is set and the request is intercepted & awaited
19+
expect(Cypress.env('interceptedAliases')).to.have.property(
20+
'treeSelectApi'
21+
);
22+
});
23+
});
24+
25+
it('Should register multiple unique aliases', () => {
26+
// first api with alias 'accordionSelectApi'
27+
cy.interceptApi({
28+
alias: 'accordionSelectApi',
29+
urlPattern: /\/ops\/accordion_select\?id=.*/,
30+
triggerFn: () => cy.accordion('Diagnostics'),
31+
});
32+
// second api with alias 'treeSelectApi'
33+
cy.interceptApi({
34+
alias: 'treeSelectApi',
35+
urlPattern: /\/ops\/tree_select\?id=.*&text=.*/,
36+
triggerFn: () => cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]),
37+
}).then(() => {
38+
// verifies that both the aliases are set and the request is intercepted & awaited
39+
expect(Cypress.env('interceptedAliases')).to.include.all.keys(
40+
'accordionSelectApi',
41+
'treeSelectApi'
42+
);
43+
});
44+
});
45+
46+
it('Should not register duplicate alias', () => {
47+
// add first api with alias 'accordionSelectApi'
48+
cy.interceptApi({
49+
alias: 'accordionSelectApi',
50+
urlPattern: /\/ops\/accordion_select\?id=.*/,
51+
triggerFn: () => cy.accordion('Diagnostics'),
52+
}).then(() => {
53+
expect(Object.keys(Cypress.env('interceptedAliases')).length).to.equal(1);
54+
});
55+
// second first api with alias 'treeSelectApi'
56+
cy.interceptApi({
57+
alias: 'treeSelectApi',
58+
urlPattern: /\/ops\/tree_select\?id=.*&text=.*/,
59+
triggerFn: () => cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]),
60+
}).then(() => {
61+
expect(Object.keys(Cypress.env('interceptedAliases')).length).to.equal(2);
62+
});
63+
// third api with a duplicate alias as above 'accordionSelectApi'
64+
cy.interceptApi({
65+
alias: 'accordionSelectApi',
66+
urlPattern: /\/ops\/accordion_select\?id=.*/,
67+
triggerFn: () => cy.accordion('Access Control'),
68+
}).then(() => {
69+
// assert that the alias is not overwritten
70+
expect(Object.keys(Cypress.env('interceptedAliases')).length).to.equal(2);
71+
});
72+
});
73+
});

0 commit comments

Comments
 (0)