/
settings.cy.ts
453 lines (382 loc) · 16.2 KB
/
settings.cy.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
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
import type { SinonStub } from 'sinon'
const SidebarSettingsLinkSelector = '[data-cy="sidebar-link-settings-page"]'
describe('App: Settings', () => {
before(() => {
cy.scaffoldProject('todos', { timeout: 50 * 1000 })
})
beforeEach(() => {
cy.openProject('todos', ['--config', 'projectId=fromCli'])
})
it('visits settings page', () => {
cy.startAppServer('e2e')
cy.visitApp()
cy.get(SidebarSettingsLinkSelector).click()
cy.contains('[data-cy="app-header-bar"]', 'Settings')
cy.contains('[data-cy="app-header-bar"] button', 'Log In').should('be.visible')
cy.findByText('Device Settings').should('be.visible')
cy.findByText('Project Settings').should('be.visible')
cy.findByText('Dashboard Settings').should('be.visible')
})
describe('Cloud Settings', () => {
it('shows the projectId section when there is a projectId and shows override from CLI', () => {
cy.withCtx(async (ctx, o) => {
o.sinon.stub(ctx.electronApi, 'copyTextToClipboard')
})
cy.startAppServer('e2e')
cy.visitApp()
cy.get(SidebarSettingsLinkSelector).click()
cy.findByText('Dashboard Settings').click()
cy.findByText('Project ID').should('be.visible')
cy.get('[data-cy="code-box"]').should('contain', 'fromCli')
cy.findByText('Copy').click()
cy.findByText('Copied!').should('be.visible')
cy.withRetryableCtx((ctx) => {
expect(ctx.electronApi.copyTextToClipboard as SinonStub).to.have.been.calledWith('fromCli')
})
})
it('shows the Record Keys section', () => {
cy.startAppServer('e2e')
cy.loginUser()
cy.visitApp()
cy.get(SidebarSettingsLinkSelector).click()
cy.findByText('Dashboard Settings').click()
cy.findByText('Record Key').should('be.visible')
})
it('obfuscates each record key and has a button to reveal the key', () => {
cy.startAppServer('e2e')
cy.loginUser()
cy.visitApp()
cy.get(SidebarSettingsLinkSelector).click()
cy.findByText('Dashboard Settings').click()
cy.get('[data-cy="code-box"]').should('contain', '***')
cy.get('[aria-label="Record Key Visibility Toggle"]').click()
cy.get('[data-cy="code-box"]').should('contain', '2aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
})
it('opens cloud settings when clicking on "Manage Keys"', () => {
cy.startAppServer('e2e')
cy.loginUser()
cy.visitApp('settings')
cy.findByText('Dashboard Settings').click()
cy.findByText('Manage Keys').click()
cy.withRetryableCtx((ctx) => {
expect((ctx.actions.electron.openExternal as SinonStub).lastCall.lastArg).to.eq('http:/test.cloud/cloud-project/settings')
})
})
it('shows deferred remote cloud data after navigating from a run', { retries: 0 }, () => {
cy.remoteGraphQLIntercept(async (obj) => {
// Simulate a timeout so we don't resolve immediately, previously visiting the test runner
// and then leaving would cause this to fail, because it removed the event listeners
// for graphql-refetch. By namespacing the socket layer, we avoid the events of the
// runner from impacting the cloud behavior
await new Promise((resolve) => setTimeout(resolve, 500))
return obj.result
})
cy.startAppServer('e2e')
cy.loginUser()
cy.visitApp()
cy.get('.spec-list-container').scrollTo('bottom')
// Visit the test to trigger the ws.off() for the TR websockets
cy.contains('test1.js').click()
cy.waitForSpecToFinish()
// Wait for the test to pass, so the test is completed
cy.get('.passed > .num').should('contain', 1)
cy.get(SidebarSettingsLinkSelector).click()
cy.contains('Dashboard Settings').click()
// Assert the data is not there before it arrives
cy.contains('Record Key').should('not.exist')
cy.contains('Record Key')
})
it('clears nested cloud data (record key) upon logging out', () => {
cy.startAppServer('e2e')
cy.loginUser()
cy.visitApp()
cy.withCtx((ctx, o) => {
o.sinon.spy(ctx.actions.auth, 'logout')
})
cy.findByTestId('sidebar-link-settings-page').click()
cy.contains('Dashboard Settings').click()
cy.contains('Record Key').should('exist')
cy.findByTestId('sidebar-link-runs-page').click()
cy.findByTestId('user-avatar-title').click()
cy.findByRole('button', { name: 'Log Out' }).click()
cy.withRetryableCtx((ctx, o) => {
expect(ctx.actions.auth.logout).to.have.been.calledOnce
})
cy.findByTestId('sidebar-link-settings-page').click()
cy.contains('Dashboard Settings').click()
cy.contains('Record Key').should('not.exist')
})
})
describe('Project Settings', () => {
it('shows the Spec Patterns section (default specPattern value)', () => {
cy.scaffoldProject('simple-ct')
cy.openProject('simple-ct')
cy.startAppServer('component')
cy.loginUser()
cy.visitApp()
cy.findByTestId('sidebar-link-settings-page').click()
cy.findByText('Project Settings').click()
cy.get('[data-cy="file-match-indicator"]').contains('2 Matches')
cy.get('[data-cy="spec-pattern"]').contains('**/*.cy.{js,jsx,ts,tsx}')
cy.get('[data-cy="settings-specPatterns"').within(() => {
cy.validateExternalLink({
name: 'Learn more.',
href: 'https://on.cypress.io/test-type-options',
})
})
})
it('shows the Spec Patterns section (edited specPattern value)', () => {
cy.startAppServer('e2e')
cy.loginUser()
cy.visitApp()
cy.get(SidebarSettingsLinkSelector).click()
cy.findByText('Project Settings').click()
cy.get('[data-cy="file-match-indicator"]').contains('41 Matches')
cy.get('[data-cy="spec-pattern"]').contains('tests/**/*')
})
it('shows the Experiments section', () => {
cy.startAppServer('e2e')
cy.loginUser()
cy.visitApp()
cy.get(SidebarSettingsLinkSelector).click()
cy.findByText('Project Settings').click()
cy.get('[data-cy="settings-experiments"]').within(() => {
cy.validateExternalLink({
name: 'Learn more.',
href: 'https://on.cypress.io/experiments',
})
cy.get('[data-cy="experiment-experimentalFetchPolyfill"]').within(() => {
cy.validateExternalLink({
name: 'cy.intercept()',
href: 'https://on.cypress.io/intercept',
})
})
cy.get('[data-cy="experiment-experimentalInteractiveRunEvents"]').within(() => {
cy.validateExternalLink({
name: 'before:run',
href: 'https://on.cypress.io/before-run',
})
cy.validateExternalLink({
name: 'after:run',
href: 'https://on.cypress.io/after-run',
})
cy.validateExternalLink({
name: 'before:spec',
href: 'https://on.cypress.io/before-spec',
})
cy.validateExternalLink({
name: 'after:spec',
href: 'https://on.cypress.io/after-spec',
})
})
cy.get('[data-cy="experiment-experimentalSessionAndOrigin"]').within(() => {
cy.validateExternalLink({
name: 'cy.session()',
href: 'https://on.cypress.io/session',
})
cy.validateExternalLink({
name: 'cy.origin()',
href: 'https://on.cypress.io/origin',
})
})
cy.get('[data-cy="experiment-experimentalSourceRewriting"]').within(() => {
cy.validateExternalLink({
name: '#5273',
href: 'https://github.com/cypress-io/cypress/issues/5273',
})
})
})
})
it('shows the Resolved Configuration section', () => {
cy.startAppServer('e2e')
cy.loginUser()
cy.visitApp()
cy.get(SidebarSettingsLinkSelector).click()
cy.findByText('Project Settings').click()
cy.get('[data-cy="config-code"]').contains('{')
})
it('highlights values set via config file, envFile, env, or CLI in the appropriate color', () => {
cy.startAppServer('e2e')
cy.loginUser()
cy.visitApp()
cy.get(SidebarSettingsLinkSelector).click()
cy.findByText('Project Settings').click()
cy.get('[data-cy="config-legend"]').within(() => {
cy.get('.bg-gray-50').contains('default')
cy.get('.bg-teal-100').contains('config')
cy.get('.bg-orange-100').contains('env')
cy.get('.bg-red-50').contains('cli')
})
cy.get('[data-cy="config-code"]').within(() => {
cy.get('[data-cy-config="config"]').contains('tests/_fixtures')
cy.get('[data-cy-config="config"]').contains('tests/**/*')
cy.get('[data-cy-config="config"]').contains('tests/_support/spec_helper.js')
cy.get('[data-cy-config="env"]').contains('REMOTE_DEBUGGING_PORT')
cy.get('[data-cy-config="env"]').contains('INTERNAL_E2E_TESTING_SELF')
cy.get('[data-cy-config="env"]').contains('INTERNAL_GRAPHQL_PORT')
cy.get('[data-cy-config="cli"]').contains('fromCli')
cy.get('[data-cy-config="cli"]').contains('4455')
})
})
it('opens cypress.config.js file after clicking "Edit" button', () => {
cy.startAppServer('e2e')
cy.withCtx((ctx, o) => {
ctx.coreData.localSettings.preferences.preferredEditorBinary = 'computer'
o.sinon.stub(ctx.actions.file, 'openFile')
})
cy.visitApp('/settings')
cy.findByText('Project Settings').click()
cy.findByRole('button', { name: 'Edit' }).click()
cy.withRetryableCtx((ctx) => {
expect((ctx.actions.file.openFile as SinonStub).lastCall.args[0]).to.eq(ctx.lifecycleManager.configFilePath)
})
})
it('highlights values set via config file, envFile, env, or CLI in the appropriate color with default specPattern', () => {
cy.scaffoldProject('config-with-js')
cy.openProject('config-with-js')
cy.startAppServer('e2e')
cy.loginUser()
cy.visitApp()
cy.get(SidebarSettingsLinkSelector).click()
cy.findByText('Project Settings').click()
cy.get('[data-cy="config-legend"]').within(() => {
cy.get('.bg-gray-50').contains('default')
cy.get('.bg-teal-100').contains('config')
cy.get('.bg-orange-100').contains('env')
cy.get('.bg-red-50').contains('cli')
})
cy.get('[data-cy="config-code"]').within(() => {
cy.get('[data-cy-config="default"]').contains('cypress/e2e/**/*.cy.{js,jsx,ts,tsx}')
cy.get('[data-cy-config="config"]').contains('500')
cy.get('[data-cy-config="config"]').contains('10000')
cy.get('[data-cy-config="config"]').contains('false')
cy.get('[data-cy-config="config"]').contains('20')
cy.get('[data-cy-config="env"]').contains('REMOTE_DEBUGGING_PORT')
cy.get('[data-cy-config="env"]').contains('INTERNAL_E2E_TESTING_SELF')
cy.get('[data-cy-config="env"]').contains('INTERNAL_GRAPHQL_PORT')
cy.get('[data-cy-config="cli"]').contains('4455')
})
})
})
describe('external editor', () => {
beforeEach(() => {
cy.startAppServer('e2e')
cy.withCtx((ctx, o) => {
o.sinon.stub(ctx.actions.localSettings, 'setPreferences')
o.sinon.stub(ctx.actions.file, 'openFile')
ctx.coreData.localSettings.availableEditors = [
...ctx.coreData.localSettings.availableEditors,
// don't rely on CI machines to have specific editors installed
// so just adding one here
{
id: 'well-known-editor',
binary: '/usr/bin/well-known',
name: 'Well known editor',
},
{
id: 'null-binary-editor',
name: 'Null binary editor',
},
]
ctx.coreData.localSettings.preferences.preferredEditorBinary = undefined
})
cy.visitApp('settings')
cy.contains('Device Settings').click()
})
it('selects well known editor', () => {
cy.contains('Choose your editor...').click()
cy.contains('Well known editor').click()
cy.withRetryableCtx((ctx) => {
expect((ctx.actions.localSettings.setPreferences as SinonStub).lastCall.args[0]).to.include('/usr/bin/well-known')
})
// navigate away and come back
// preferred editor selected from dropdown should have been persisted
cy.visitApp()
cy.findByTestId('sidebar-link-settings-page').click()
cy.wait(200)
cy.get('[data-cy="Device Settings"]').click()
cy.get('[data-cy="custom-editor"]').should('not.exist')
})
it('allows custom editor', () => {
cy.contains('Choose your editor...').click()
cy.contains('Custom').click()
// doing invoke instead of `type` since `type` enters keys on-by-one, triggering a mutation
// for each keystroke, making it hard to intercept **only** the final request, which I want to
// assert contains `/usr/local/bin/vim'
cy.findByPlaceholderText('/path/to/editor').clear().invoke('val', '/usr/local/bin/vim').trigger('input').trigger('change')
cy.withRetryableCtx((ctx) => {
expect((ctx.actions.localSettings.setPreferences as SinonStub).lastCall.args[0]).to.include('/usr/local/bin/vim')
})
// navigate away and come back
// preferred editor entered from input should have been persisted
cy.findByTestId('sidebar-link-settings-page').click()
cy.wait(100)
cy.get('[data-cy="Device Settings"]').click()
cy.get('[data-cy="custom-editor"]').should('have.value', '/usr/local/bin/vim')
})
it('lists file browser as available editor', () => {
cy.contains('Choose your editor...').click()
cy.get('[data-cy="computer"]').click()
cy.withRetryableCtx((ctx) => {
expect((ctx.actions.localSettings.setPreferences as SinonStub).lastCall.args[0]).to.include('computer')
})
cy.get('[data-cy="custom-editor"]').should('not.exist')
})
it('handles null binary field in editor', () => {
cy.contains('Choose your editor...').click()
cy.contains('Null binary editor').click()
cy.withRetryableCtx((ctx) => {
expect((ctx.actions.localSettings.setPreferences as SinonStub).lastCall.args[0]).to.include('{"preferredEditorBinary":null')
})
// navigate away and come back
// preferred editor selected from dropdown should have been persisted
cy.visitApp()
cy.findByTestId('sidebar-link-settings-page').click()
cy.wait(200)
cy.get('[data-cy="Device Settings"]').click()
cy.get('[data-cy="custom-editor"]').should('not.exist')
})
})
})
describe('App: Settings without cloud', () => {
it('the projectId section shows a prompt to log in when there is no projectId, and uses correct UTM params', () => {
cy.scaffoldProject('simple-ct')
cy.openProject('simple-ct')
cy.startAppServer('component')
cy.visitApp()
cy.get(SidebarSettingsLinkSelector).click()
cy.findByText('Dashboard Settings').click()
cy.findByText('Project ID').should('exist')
cy.withCtx((ctx, o) => {
o.sinon.spy(ctx._apis.authApi, 'logIn')
})
cy.contains('button', 'Log in to the Cypress Dashboard').click()
cy.findByRole('dialog', { name: 'Log in to Cypress' }).within(() => {
cy.contains('button', 'Log In').click()
})
cy.withCtx((ctx, o) => {
// validate utmSource
expect((ctx._apis.authApi.logIn as SinonStub).lastCall.args[1]).to.eq('Binary: App')
// validate utmMedium
expect((ctx._apis.authApi.logIn as SinonStub).lastCall.args[2]).to.eq('Settings Tab')
})
})
it('have returned browsers', () => {
cy.scaffoldProject('simple-ct')
cy.openProject('simple-ct')
cy.startAppServer('component')
cy.visitApp()
cy.get(SidebarSettingsLinkSelector).click()
cy.findByText('Project Settings').click()
cy.get('[data-cy=config-code]').within(() => {
const { browsers } = Cypress.config()
expect(browsers).to.have.length.greaterThan(1)
cy.contains(`browsers: [`)
cy.contains(`name: 'chrome',`)
cy.contains(`family: 'chromium',`)
cy.contains(`channel: 'stable',`)
cy.contains(`displayName: 'Chrome',`)
// cy.percySnapshot() // TODO: restore when Percy CSS is fixed. See https://github.com/cypress-io/cypress/issues/23435
})
})
})