-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
open-mode.cy.ts
226 lines (184 loc) · 8.34 KB
/
open-mode.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
import type { SinonStub } from 'sinon'
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'
describe('Launchpad: Open Mode', () => {
describe('global mode', () => {
beforeEach(() => {
cy.openGlobalMode()
cy.visitLaunchpad()
})
it('shows Add Project when no projects have been added', () => {
cy.get('h1').should('contain', defaultMessages.globalPage.empty.title)
})
it('shows the projects page when a project is not specified', () => {
cy.addProject('todos')
cy.visitLaunchpad()
cy.contains(defaultMessages.globalPage.recentProjectsHeader)
})
})
it('goes directly to e2e tests when launched with --e2e', () => {
cy.scaffoldProject('todos')
cy.openProject('todos', ['--e2e'])
cy.visitLaunchpad()
cy.get('[data-cy=header-bar-content]').contains('e2e testing', { matchCase: false })
// e2e testing is configured for the todo project, so we don't expect an error.
cy.get('h1').should('contain', 'Choose a Browser')
})
it('goes to component test onboarding when launched with --component and not configured', () => {
cy.scaffoldProject('launchpad')
cy.openProject('launchpad', ['--component'])
cy.visitLaunchpad()
cy.get('[data-cy=header-bar-content]').contains('component testing', { matchCase: false })
// Component testing is not configured for the todo project
cy.get('h1').should('contain', 'Project Setup')
})
// since circle cannot have firefox installed by default,
// we need to skip this test relying on it
// It is very unlikely that it would only fail on Windows though
// (tested manually on Windows and it works fine)
if (Cypress.platform !== 'win32') {
it('auto-selects the browser when launched with --browser', () => {
cy.scaffoldProject('launchpad')
cy.openProject('launchpad', ['--browser', 'firefox'])
cy.withCtx((ctx, o) => {
o.sinon.stub(ctx._apis.projectApi, 'launchProject').rejects(new Error('should not launch project'))
})
// Need to visit after args have been configured, todo: fix in #18776
cy.visitLaunchpad()
cy.contains('E2E Testing').click()
cy.get('h1').should('contain', 'Choose a Browser')
cy.get('[data-cy-browser=firefox]').should('have.attr', 'aria-checked', 'true')
cy.get('button[data-cy=launch-button]').invoke('text').should('include', 'Start E2E Testing in Firefox')
})
it('auto-launches the browser when launched with --browser --testingType --project', () => {
cy.scaffoldProject('launchpad')
cy.openProject('launchpad', ['--browser', 'firefox', '--e2e'])
cy.withCtx((ctx, o) => {
o.sinon.stub(ctx._apis.projectApi, 'launchProject').resolves()
})
// Need to visit after args have been configured, todo: fix in #18776
cy.visitLaunchpad()
cy.get('h1').should('contain', 'Choose a Browser')
cy.get('[data-cy-browser=firefox]').should('have.attr', 'aria-checked', 'true')
cy.get('button[data-cy=launch-button]').invoke('text').should('include', 'Start E2E Testing in Firefox')
cy.withRetryableCtx((ctx) => {
expect(ctx._apis.projectApi.launchProject).to.be.calledOnce
})
})
}
describe('when there is a list of projects', () => {
it('goes to an active project if one is added', () => {
cy.scaffoldProject('todos')
cy.openProject('todos')
cy.visitLaunchpad()
cy.withCtx(async (ctx, o) => {
ctx.emitter.toLaunchpad()
})
cy.get('h1').should('contain', 'Welcome to Cypress!')
})
})
describe('when a user interacts with the header', () => {
it('the Docs menu opens when clicked', () => {
cy.scaffoldProject('todos')
cy.openProject('todos')
cy.visitLaunchpad()
cy.contains('Projects').should('be.visible')
cy.contains('button', 'Docs').click()
cy.contains(defaultMessages.topNav.docsMenu.gettingStartedTitle).should('be.visible')
})
it('updates the breadcrumb when navigating forward and back', () => {
const getBreadcrumbLink = (name: string, options: { disabled: boolean } = { disabled: false }) => {
return cy.findByRole('link', { name }).should('have.attr', 'aria-disabled', options.disabled ? 'true' : 'false')
}
cy.scaffoldProject('todos')
cy.openProject('todos')
cy.visitLaunchpad()
cy.contains('h1', 'Welcome to Cypress!')
getBreadcrumbLink('Projects', { disabled: true })
getBreadcrumbLink('todos', { disabled: true })
cy.get('[data-cy-testingtype="e2e"]').click()
cy.contains('h1', 'Choose a Browser')
cy.contains('li', 'e2e testing', { matchCase: false }).should('not.have.attr', 'href')
getBreadcrumbLink('Projects', { disabled: true })
cy.withCtx((ctx, { sinon }) => {
sinon.spy(ctx.lifecycleManager, 'setAndLoadCurrentTestingType')
})
getBreadcrumbLink('todos').click()
cy.contains('h1', 'Welcome to Cypress!')
getBreadcrumbLink('Projects', { disabled: true })
getBreadcrumbLink('todos', { disabled: true })
cy.withCtx((ctx) => {
expect(ctx.lifecycleManager.setAndLoadCurrentTestingType).to.have.been.calledWith(null)
})
})
})
describe('open in ide', () => {
beforeEach(() => {
cy.scaffoldProject('todos')
cy.openGlobalMode()
})
it('configures an editor if one is not configured', () => {
cy.withCtx(async (ctx, o) => {
ctx.coreData.localSettings.preferences.preferredEditorBinary = undefined
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',
},
]
ctx.coreData.app.projects = [{ projectRoot: '/some/project' }]
})
cy.visitLaunchpad()
cy.get('a').contains('Projects').click()
cy.findByTestId('project-card')
cy.get('[aria-label="Project Actions"]').click()
cy.get('button').contains('Open In IDE').click()
cy.get('[data-cy="choose-editor-modal"]').as('modal')
cy.get('@modal').contains('Cancel').click()
cy.get('@modal').should('not.exist')
cy.findByTestId('project-card')
cy.get('[aria-label="Project Actions"]').click()
cy.get('button').contains('Open In IDE').click()
cy.intercept('POST', 'mutation-ChooseExternalEditorModal_SetPreferredEditorBinary').as('SetPreferred')
cy.get('@modal').contains('Choose your editor...').click()
cy.get('@modal').contains('Well known editor').click()
cy.get('@modal').contains('Save Changes').click()
cy.wait('@SetPreferred').its('request.body.variables.value').should('include', '/usr/bin/well-known')
})
it('opens using finder', () => {
cy.withCtx(async (ctx, o) => {
ctx.coreData.app.projects = [{ projectRoot: '/some/project' }]
})
cy.visitLaunchpad()
cy.get('a').contains('Projects').click()
cy.findByTestId('project-card')
cy.get('[aria-label="Project Actions"]').click()
cy.intercept('POST', 'mutation-GlobalPage_OpenInFinder').as('OpenInFinder')
cy.get('button').contains('Open In Finder').click()
cy.wait('@OpenInFinder')
cy.withCtx((ctx, o) => {
expect((ctx.actions.electron.showItemInFolder as SinonStub).lastCall.lastArg).to.eql('/some/project')
})
})
})
it('opens an e2e project without a supportFile', () => {
cy.scaffoldProject('no-support-file')
cy.openProject('no-support-file', ['--e2e'])
cy.visitLaunchpad()
cy.contains(cy.i18n.launchpadErrors.generic.configErrorTitle)
cy.contains('Your project does not contain a default supportFile.')
cy.contains('If a support file is not necessary for your project, set supportFile to false.')
})
// Assert that we do not glob the absolute projectRoot
// and fail supportFile lookups during project initialization.
// https://github.com/cypress-io/cypress/issues/22040
it('opens projects with paths that contain glob syntax', () => {
cy.scaffoldProject('project-with-(glob)-[chars]')
cy.openProject('project-with-(glob)-[chars]', ['--e2e'])
cy.visitLaunchpad()
cy.get('body').should('not.contain.text', 'Your project does not contain a default supportFile.')
cy.get('h1').should('contain', 'Choose a Browser')
})
})