forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnav.spec.ts
135 lines (127 loc) · 5.72 KB
/
nav.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
describe('Nav Test', () => {
it('Navigate to demo section', () => {
cy.visit('http://localhost:3000/nav-demo-nav-link');
});
it('Verify Default Nav', () => {
cy.get('#nav-primary-default .pf-c-nav__link').each((defaultNavLink: JQuery<HTMLAnchorElement>, index: number) => {
const isCurrent = defaultNavLink.hasClass('pf-m-current');
expect(isCurrent).to.be.equal(index === 0);
});
cy.get('#default-link3').then((defaultLink3: JQuery<HTMLAnchorElement>) => {
cy.wrap(defaultLink3).click();
cy.url().should('eq', 'http://localhost:3000/nav-demo-nav-link#default-link3');
cy.get('#nav-primary-default .pf-c-nav__link').each(
(defaultNavLink: JQuery<HTMLAnchorElement>, index: number) => {
const isCurrent = defaultNavLink.hasClass('pf-m-current');
expect(isCurrent).to.be.equal(index === 2);
}
);
});
cy.get('#default-no-navigate-link').then((noNavigateLink: JQuery<HTMLAnchorElement>) => {
cy.wrap(noNavigateLink).click();
cy.url().should('eq', 'http://localhost:3000/nav-demo-nav-link#default-link3');
cy.get('#nav-primary-default .pf-c-nav__link').each(
(defaultNavLink: JQuery<HTMLAnchorElement>, index: number) => {
const isCurrent = defaultNavLink.hasClass('pf-m-current');
expect(isCurrent).to.be.equal(index === 4);
}
);
});
});
it('Verify Expandable Nav', () => {
// All groups start open
cy.get('#nav-primary-expandable .pf-c-nav__link[id="grp-1"]').each((expandableGroup: JQuery<HTMLAnchorElement>) => {
expect(expandableGroup.attr('aria-expanded')).to.be.equal('true');
});
// button props get spread
cy.get('#grp-2.pf-c-nav__link').should('have.attr', 'aria-label', 'group 2');
// Verify close and open of group 1
cy.get('#grp-1').then((group1Link: JQuery<HTMLAnchorElement>) => {
cy.wrap(group1Link).click();
cy.get('#grp-1').then((updatedGroup1Link: JQuery<HTMLAnchorElement>) => {
expect(updatedGroup1Link.attr('aria-expanded')).to.be.equal('false');
});
cy.get('#grp-2').then((group2Link: JQuery<HTMLAnchorElement>) => {
expect(group2Link.attr('aria-expanded')).to.be.equal('true');
});
cy.wrap(group1Link).click();
cy.get('#grp-1').then((updatedGroup1Link: JQuery<HTMLAnchorElement>) => {
expect(updatedGroup1Link.attr('aria-expanded')).to.be.equal('true');
});
});
// Verify sub-nav selections
cy.get('#grp-1').then((group1Link: JQuery<HTMLAnchorElement>) => {
const parent = group1Link.parent();
expect(parent.hasClass('pf-m-current')).to.be.equal(true);
});
cy.get('#itm-1-1').then((item1Link: JQuery<HTMLAnchorElement>) => {
expect(item1Link.hasClass('pf-m-current')).to.be.equal(true);
});
cy.get('#itm-1-2').then((item2Link: JQuery<HTMLAnchorElement>) => {
cy.wrap(item2Link).click();
cy.get('#itm-1-1').then((item1Link: JQuery<HTMLAnchorElement>) => {
expect(item1Link.hasClass('pf-m-current')).to.be.equal(false);
});
cy.get('#itm-1-2').then((updatedItem2Link: JQuery<HTMLAnchorElement>) => {
expect(updatedItem2Link.hasClass('pf-m-current')).to.be.equal(true);
});
});
cy.get('#itm-2-2').then((item2Link: JQuery<HTMLAnchorElement>) => {
cy.wrap(item2Link).click();
cy.get('#itm-1-2').then((updatedItem2Link: JQuery<HTMLAnchorElement>) => {
expect(updatedItem2Link.hasClass('pf-m-current')).to.be.equal(false);
});
cy.get('#grp-1').then((group1Link: JQuery<HTMLAnchorElement>) => {
const parent = group1Link.parent();
expect(parent.hasClass('pf-m-current')).to.be.equal(false);
});
cy.get('#grp-2').then((group2Link: JQuery<HTMLAnchorElement>) => {
const parent = group2Link.parent();
expect(parent.hasClass('pf-m-current')).to.be.equal(true);
});
});
});
it('Verify Horizontal Nav', () => {
cy.get('#nav-primary-horizontal .pf-c-nav__link').each(
(horizontalLink: JQuery<HTMLAnchorElement>, index: number) => {
const isCurrent = horizontalLink.hasClass('pf-m-current');
expect(isCurrent).to.be.equal(index === 0);
}
);
cy.get('#nav-primary-horizontal #horizontal-link2').then((horizontalLink2: JQuery<HTMLAnchorElement>) => {
cy.wrap(horizontalLink2).click();
cy.get('#nav-primary-horizontal .pf-c-nav__link').each(
(horizontalNavLink: JQuery<HTMLAnchorElement>, index: number) => {
const isCurrent = horizontalNavLink.hasClass('pf-m-current');
expect(isCurrent).to.be.equal(index === 1);
}
);
});
});
it('Verify Tertiary Nav', () => {
cy.get('#nav-primary-tertiary .pf-c-nav__link').each((tertiaryLink: JQuery<HTMLAnchorElement>, index: number) => {
const isCurrent = tertiaryLink.hasClass('pf-m-current');
expect(isCurrent).to.be.equal(index === 0);
});
cy.get('#nav-primary-tertiary #tertiary-link2').then((tertiaryLink2: JQuery<HTMLAnchorElement>) => {
cy.wrap(tertiaryLink2).click();
cy.get('#nav-primary-tertiary .pf-c-nav__link').each(
(tertiaryNavLink: JQuery<HTMLAnchorElement>, index: number) => {
const isCurrent = tertiaryNavLink.hasClass('pf-m-current');
expect(isCurrent).to.be.equal(index === 1);
}
);
});
});
it('Verify Flyout Nav', () => {
cy.get('#3-child').should('not.exist');
cy.get('#flyout-link3').trigger('mouseover');
cy.get('#3-child').should('exist');
cy.get('#2-child').should('not.exist');
cy.get('#next-menu-3').trigger('mouseover');
cy.get('#2-child').should('exist');
cy.get('#flyout-link2').trigger('mouseover');
cy.get('#3-child').should('not.exist');
cy.get('#2-child').should('not.exist');
});
});