-
-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathNavigation.cy.res
More file actions
213 lines (181 loc) · 6.19 KB
/
Navigation.cy.res
File metadata and controls
213 lines (181 loc) · 6.19 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
open Cy
// Wait for the app to fully hydrate before interacting with links.
// The production build is pre-rendered so React must attach event
// handlers before client-side navigation works.
let waitForHydration = () => {
getByTestId("navbar-primary")->shouldBeVisible->ignore
cyWindow()->its("document.readyState")->shouldWithValue("eq", "complete")->ignore
wait(2000)
}
// Use short, re-queryable selectors to avoid detached DOM issues.
// When React re-renders during navigation, long chains can hold
// references to stale elements. Separate cy.get() calls let Cypress
// re-query from the DOM root on each retry.
let clickNavLink = (~testId, ~text) => {
get(`[data-testid="${testId}"] a:visible`)
->containsChainable(text)
->click
->ignore
}
let clickMobileNavLink = text => {
get(`[data-testid="mobile-nav"] a:visible`)
->containsChainable(text)
->click
->ignore
}
let openMobileMenu = () => {
get(`[data-testid="toggle-mobile-overlay"]`)->should("be.visible")->click->ignore
get("#mobile-overlay")->should("be.visible")->ignore
}
// -- Desktop (1280x720) -------------------------------------------------------
describe("Desktop Navigation", () => {
beforeEach(() => {
viewport(1280, 720)
visit("/")
waitForHydration()
})
describe("Primary navbar", () => {
it(
"should navigate to Docs via navbar link",
() => {
clickNavLink(~testId="navbar-primary-left-content", ~text="Docs")
url()->shouldInclude("/docs/manual/introduction")->ignore
get("h1")->shouldBeVisible->ignore
},
)
it(
"should navigate to Playground via navbar link",
() => {
clickNavLink(~testId="navbar-primary-left-content", ~text="Playground")
url()->shouldInclude("/try")->ignore
},
)
it(
"should navigate to Blog via navbar link",
() => {
clickNavLink(~testId="navbar-primary-left-content", ~text="Blog")
url()->shouldInclude("/blog")->ignore
},
)
it(
"should navigate to Community via navbar link",
() => {
clickNavLink(~testId="navbar-primary-left-content", ~text="Community")
url()->shouldInclude("/community")->ignore
get("h1")->shouldBeVisible->ignore
},
)
it(
"should navigate home via logo after clicking away",
() => {
clickNavLink(~testId="navbar-primary-left-content", ~text="Blog")
url()->shouldInclude("/blog")->ignore
get("a[aria-label='homepage']")->should("be.visible")->first->click->ignore
cyLocation("pathname")->shouldWithValue("eq", "/")->ignore
},
)
})
describe("Secondary navbar", () => {
it(
"should navigate through all secondary nav links from Docs",
() => {
// Click Docs in primary nav to reveal the secondary nav
clickNavLink(~testId="navbar-primary-left-content", ~text="Docs")
url()->shouldInclude("/docs/manual/introduction")->ignore
// Language Manual
clickNavLink(~testId="navbar-secondary", ~text="Language Manual")
url()->shouldInclude("/docs/manual/introduction")->ignore
// API
clickNavLink(~testId="navbar-secondary", ~text="API")
url()->shouldInclude("/docs/manual/api")->ignore
// Syntax Lookup
clickNavLink(~testId="navbar-secondary", ~text="Syntax Lookup")
url()->shouldInclude("/syntax-lookup")->ignore
// React
clickNavLink(~testId="navbar-secondary", ~text="React")
url()->shouldInclude("/docs/react/introduction")->ignore
},
)
})
})
// -- Mobile (375x667) ---------------------------------------------------------
describe("Mobile Navigation", () => {
beforeEach(() => {
viewport(375, 667)
visit("/")
waitForHydration()
})
describe("Primary navbar", () => {
it(
"should navigate to Docs via navbar link",
() => {
clickNavLink(~testId="navbar-primary-left-content", ~text="Docs")
url()->shouldInclude("/docs/manual/introduction")->ignore
get("h1")->shouldBeVisible->ignore
},
)
it(
"should navigate home via logo after clicking away",
() => {
clickNavLink(~testId="navbar-primary-left-content", ~text="Docs")
url()->shouldInclude("/docs/manual/introduction")->ignore
get("a[aria-label='homepage']")->should("be.visible")->first->click->ignore
cyLocation("pathname")->shouldWithValue("eq", "/")->ignore
},
)
})
describe("Mobile overlay navigation", () => {
it(
"should navigate to Playground via mobile menu",
() => {
openMobileMenu()
clickMobileNavLink("Playground")
url()->shouldInclude("/try")->ignore
},
)
it(
"should navigate to Blog via mobile menu",
() => {
openMobileMenu()
clickMobileNavLink("Blog")
url()->shouldInclude("/blog")->ignore
},
)
it(
"should navigate to Community via mobile menu",
() => {
openMobileMenu()
clickMobileNavLink("Community")
url()->shouldInclude("/community")->ignore
get("h1")->shouldBeVisible->ignore
},
)
})
describe("Secondary navbar", () => {
it(
"should navigate through all secondary nav links from Docs",
() => {
// Click Docs in primary nav to reveal the secondary nav
clickNavLink(~testId="navbar-primary-left-content", ~text="Docs")
url()->shouldInclude("/docs/manual/introduction")->ignore
// Scroll to top so the secondary nav is visible
cyScrollTo("top")
// Language Manual
clickNavLink(~testId="navbar-secondary", ~text="Language Manual")
url()->shouldInclude("/docs/manual/introduction")->ignore
// API
cyScrollTo("top")
clickNavLink(~testId="navbar-secondary", ~text="API")
url()->shouldInclude("/docs/manual/api")->ignore
// Syntax Lookup
cyScrollTo("top")
clickNavLink(~testId="navbar-secondary", ~text="Syntax Lookup")
url()->shouldInclude("/syntax-lookup")->ignore
// React
cyScrollTo("top")
clickNavLink(~testId="navbar-secondary", ~text="React")
url()->shouldInclude("/docs/react/introduction")->ignore
},
)
})
})