-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
project_nav_spec.js
483 lines (386 loc) · 15.1 KB
/
project_nav_spec.js
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
describe('Project Nav', function () {
const _ = Cypress._
const edgeRe = /^edge/
const firefoxRe = /^firefox/
beforeEach(function () {
cy.fixture('user').as('user')
cy.fixture('config').as('config')
cy.fixture('runs').as('runs')
cy.fixture('specs').as('specs')
cy.visitIndex().then(function (win) {
let start = win.App.start
this.win = win
this.ipc = win.App.ipc
cy.stub(this.ipc, 'getOptions').resolves({ projectRoot: '/foo/bar' })
cy.stub(this.ipc, 'updaterCheck').resolves(false)
cy.stub(this.ipc, 'getCurrentUser').resolves(this.user)
cy.stub(this.ipc, 'getRuns').resolves(this.runs)
cy.stub(this.ipc, 'getSpecs').yields(null, this.specs)
cy.stub(this.ipc, 'getRecordKeys').resolves([])
cy.stub(this.ipc, 'launchBrowser')
cy.stub(this.ipc, 'closeBrowser').resolves(null)
cy.stub(this.ipc, 'pingApiServer').resolves()
cy.stub(this.ipc, 'closeProject')
cy.stub(this.ipc, 'externalOpen')
cy.stub(this.ipc, 'offOpenProject')
cy.stub(this.ipc, 'offGetSpecs')
cy.stub(this.ipc, 'offOnFocusTests')
this.openProject = this.util.deferred()
cy.stub(this.ipc, 'openProject').returns(this.openProject.promise)
start()
})
})
context('project nav', function () {
beforeEach(function () {
this.openProject.resolve(this.config)
})
it('displays projects nav', function () {
cy.get('.empty').should('not.be.visible')
cy.get('.navbar-default')
})
it('displays "Tests" nav as active', () => {
cy.get('.navbar-default').contains('a', 'Tests')
.should('have.class', 'active')
})
it('displays "Tests" page when project loads', () => {
cy.contains('integration')
cy.get('.list-as-table').should('be.visible')
cy.percySnapshot()
})
it('displays "Tests" page when switching to a beta browser', () => {
cy.get('.browsers .dropdown-chosen').click()
cy.contains('.browsers', 'beta').first().click()
cy.get('.list-as-table').should('be.visible')
cy.percySnapshot()
})
describe('runs page', function () {
beforeEach(function () {
cy.fixture('runs').as('runs')
cy.get('.navbar-default')
.contains('a', 'Runs').as('runsNav').click()
})
it('highlights runs on click', () => {
cy.get('@runsNav')
.should('have.class', 'active')
})
it('displays runs page', function () {
cy.get('.runs-container li')
.should('have.length', this.runs.length)
})
})
describe('settings page', function () {
beforeEach(() => {
cy.get('.navbar-default')
.contains('a', 'Settings').as('settingsNav').click()
})
it('highlights config on click', () => {
cy.get('@settingsNav')
.should('have.class', 'active')
})
it('displays settings page', () => {
cy.contains('Configuration')
})
})
})
context('browsers dropdown', function () {
describe('browsers available', function () {
beforeEach(function () {
this.openProject.resolve(this.config)
})
context('normal browser list behavior', function () {
it('lists browsers', function () {
const { browsers } = this.config
cy.get('.browsers li')
.should('have.length', browsers.length)
.each(function ($li, i) {
expect($li).to.contain(browsers[i].displayName)
})
})
it('displays browsers icons', function () {
cy.get('.browsers .browser-icon')
.each(function ($icon, i) {
const name = _.camelCase(this.config.browsers[i].name)
if (name === 'custom') {
expect($icon).to.have.class('fa-globe')
return
}
const imgName = () => {
if (name === 'canary') {
return 'chrome-canary'
}
if (edgeRe.test(name)) {
return 'edge'
}
if (firefoxRe.test(name)) {
return 'firefox'
}
return name
}
cy.wrap($icon).should('have.attr', 'src').and('include', `./img/${imgName()}`)
})
})
it('shows beta text for firefox', function () {
cy.get('.browsers li').contains('Firefox')
.contains('beta')
})
it('shows info icon with tooltip for browsder with info', function () {
const browserWithInfo = _.find(this.config.browsers, (b) => !!b.info)
cy.get('.browsers-list .dropdown-chosen').click()
cy.get('.browsers .fa-info-circle').trigger('mouseover')
cy.get('.cy-tooltip')
.should('contain', browserWithInfo.info)
})
it('does not display stop button', () => {
cy.get('.close-browser').should('not.exist')
})
describe('default browser', function () {
it('displays default browser name in chosen', () => {
cy.get('.browsers-list .dropdown-chosen')
.should('contain', 'Chrome')
})
it('displays default browser icon if chosen', () => {
cy.get('.browsers-list .dropdown-chosen')
.find('.browser-icon')
.should('have.attr', 'src')
.and('include', './img/chrome')
})
})
})
context('switch browser', function () {
beforeEach(function () {
cy.get('.browsers-list .dropdown-chosen').click()
cy.get('.browsers-list').find('.dropdown-menu')
.contains('Chromium').click()
})
afterEach(() => {
cy.clearLocalStorage()
})
it('switches text in button on switching browser', () => {
cy.get('.browsers-list .dropdown-chosen').contains('Chromium')
})
it('swaps the chosen browser into the dropdown', function () {
cy.get('.browsers-list').find('.dropdown-menu')
.find('li').should('have.length', this.config.browsers.length - 1)
.each(function ($li, i) {
const dropdownBrowsers = Cypress._.filter(this.config.browsers, (b) => {
// Chromium is shown in selection, so skip it
return b.displayName !== 'Chromium'
})
expect($li).to.contain(dropdownBrowsers[i].displayName)
})
})
it('saves chosen browser in local storage', () => {
expect(localStorage.getItem('chosenBrowser')).to.eq(JSON.stringify({ name: 'chromium', channel: 'stable' }))
})
})
context('opening browser by choosing spec', function () {
beforeEach(() => {
cy.contains('.file', 'app_spec').click()
})
it('displays browser icon as spinner', () => {
cy.get('.browsers-list .dropdown-chosen').find('i')
.should('have.class', 'fas fa-sync-alt fa-spin')
})
it('disables browser dropdown', () => {
cy.get('.browsers-list .dropdown-chosen')
.should('have.class', 'disabled')
})
})
context('browser opened after choosing spec', function () {
beforeEach(function () {
this.ipc.launchBrowser.yields(null, { browserOpened: true })
cy.contains('.file', 'app_spec').click()
})
it('displays browser icon as opened', () => {
cy.get('.browsers-list .dropdown-chosen').find('i')
.should('have.class', 'fas fa-check-circle')
})
it('disables browser dropdown', () => {
cy.get('.browsers-list .dropdown-chosen')
.should('have.class', 'disabled')
})
it('displays stop browser button', () => {
cy.get('.close-browser').should('be.visible')
cy.percySnapshot()
})
it('sends the required parameters to launch a browser', function () {
const browserArg = this.ipc.launchBrowser.getCall(0).args[0].browser
expect(browserArg).to.have.keys([
'family', 'name', 'path', 'profilePath', 'version', 'majorVersion', 'displayName', 'info', 'isChosen', 'custom', 'warning', 'channel',
])
expect(browserArg.path).to.include('/')
expect(browserArg.family).to.equal('chromium')
})
describe('stop browser', function () {
beforeEach(() => {
cy.get('.close-browser').click()
})
it('calls close:browser on click of stop button', function () {
expect(this.ipc.closeBrowser).to.be.called
})
it('hides close button on click of stop', () => {
cy.get('.close-browser').should('not.exist')
})
it('re-enables browser dropdown', () => {
cy.get('.browsers-list .dropdown-chosen')
.should('not.have.class', 'disabled')
})
it('displays default browser icon', () => {
cy.get('.browsers-list .dropdown-chosen')
.find('.browser-icon')
.should('have.attr', 'src')
.and('include', './img/chrome')
})
})
describe('browser is closed manually', function () {
beforeEach(function () {
this.ipc.launchBrowser.yield(null, { browserClosed: true })
})
it('hides close browser button', () => {
cy.get('.close-browser').should('not.be.visible')
})
it('re-enables browser dropdown', () => {
cy.get('.browsers-list .dropdown-chosen')
.and('not.have.class', 'disabled')
})
it('displays default browser icon', () => {
cy.get('.browsers-list .dropdown-chosen .browser-icon')
.should('have.attr', 'src')
.and('include', './img/chrome')
})
})
})
})
describe('local storage saved browser', function () {
afterEach(() => {
cy.clearLocalStorage()
})
it('displays chosen browser in localStorage', function () {
// deliberately not the default 'chrome' browser
// @see https://github.com/cypress-io/cypress/issues/8281
localStorage.setItem('chosenBrowser', JSON.stringify({
name: 'chrome',
channel: 'canary',
}))
this.openProject.resolve(this.config)
cy.get('.browsers-list .dropdown-chosen')
.should('contain', 'Canary').and('not.contain', 'Edge')
.get('.dropdown-chosen .browser-icon')
.should('have.attr', 'src').and('include', './img/chrome-canary')
})
it('displays chosen browser with old string-style id in localStorage', function () {
localStorage.setItem('chosenBrowser', 'chrome')
this.openProject.resolve(this.config)
cy.get('.browsers-list .dropdown-chosen')
.should('contain', 'Chrome')
})
it('displays default browser with null localStorage', function () {
localStorage.removeItem('chosenBrowser')
this.openProject.resolve(this.config)
cy.get('.browsers-list .dropdown-chosen')
.should('contain', this.config.browsers[0].displayName)
})
})
describe('when browser saved in local storage no longer exists', function () {
beforeEach(function () {
localStorage.setItem('chosenBrowser', 'netscape-navigator')
this.openProject.resolve(this.config)
})
it('defaults to first browser', () => {
cy.get('.browsers-list .dropdown-chosen')
.should('contain', 'Chrome')
})
})
describe('only one browser available', function () {
beforeEach(function () {
this.config.browsers = [{
name: 'electron',
family: 'electron',
displayName: 'Electron',
version: '50.0.2661.86',
path: '',
majorVersion: '50',
}]
this.openProject.resolve(this.config)
})
it('displays no dropdown btn', () => {
cy.get('.browsers-list')
.find('.dropdown-toggle').should('not.be.visible')
})
})
describe('browser has a warning attached', function () {
beforeEach(function () {
this.config.browsers = [
{
'name': 'chromium',
'displayName': 'Chromium',
'family': 'chromium',
'version': '49.0.2609.0',
'path': '/Users/bmann/Downloads/chrome-mac/Chromium.app/Contents/MacOS/Chromium',
'majorVersion': '49',
'warning': 'Cypress detected policy settings on your computer that may cause issues with using this browser. For more information, see https://on.cypress.io/bad-browser-policy',
},
]
this.openProject.resolve(this.config)
})
it('shows warning icon with linkified tooltip', function () {
cy.get('.browsers .fa-exclamation-triangle').trigger('mouseover')
cy.get('.cy-tooltip').should('contain', 'Cypress detected policy settings on your computer that may cause issues with using this browser. For more information, see')
cy.get('.cy-tooltip a').click().then(function () {
expect(this.ipc.externalOpen).to.be.calledWith('https://on.cypress.io/bad-browser-policy')
})
})
})
describe('custom browser', function () {
beforeEach(function () {
this.config.browsers[this.config.browsers.length - 1].custom = true
this.openProject.resolve(this.config)
})
it('displays generic icon', () => {
cy.get('.browsers-list .dropdown-chosen .browser-icon')
.should('have.class', 'fa-globe')
})
it('pre-selects the custom browser', () => {
cy.get('.browsers-list .dropdown-chosen')
.should('contain', 'Custom')
})
it('pre-selects the custom browser if chosenBrowser saved locally', function () {
localStorage.setItem('chosenBrowser', 'Custom')
cy.get('.browsers-list .dropdown-chosen')
.should('contain', 'Custom')
cy.wrap(localStorage.getItem('chosenBrowser')).should('equal', 'Custom')
})
})
describe('browser with info', function () {
beforeEach(function () {
this.info = 'foo info bar [baz](http://example.com/)'
this.config.browsers = [{
name: 'electron',
family: 'electron',
displayName: 'Electron',
version: '50.0.2661.86',
path: '',
majorVersion: '50',
info: this.info,
}]
this.openProject.resolve(this.config)
})
it('shows info icon with linkified tooltip', function () {
cy.get('.browsers .fa-info-circle').trigger('mouseover')
cy.get('.cy-tooltip').should('contain', 'foo info bar baz')
cy.get('.cy-tooltip a').should('have.text', 'baz').click().then(function () {
expect(this.ipc.externalOpen).to.be.calledWith('http://example.com/')
})
})
})
})
context('issue #869 - nav responsiveness', function () {
beforeEach(function () {
this.openProject.resolve(this.config)
})
it('main nav does not block project nav when long project name pushes it to multiple lines', () => {
cy.viewport(400, 400)
cy.get('.project-nav').should('be.visible')
})
})
})