-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
login_spec.js
304 lines (245 loc) · 9.2 KB
/
login_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
describe('Login', function () {
beforeEach(function () {
cy.fixture('user').as('user')
return cy.visitIndex().then(function (win) {
let start = win.App.start
this.win = win
this.ipc = win.App.ipc
cy.stub(this.ipc, 'onMenuClicked')
cy.stub(this.ipc, 'onFocusTests')
cy.stub(this.ipc, 'getOptions').resolves({})
cy.stub(this.ipc, 'getCurrentUser').resolves(null)
cy.stub(this.ipc, 'updaterCheck').resolves(false)
cy.stub(this.ipc, 'getProjects').resolves([])
cy.stub(this.ipc, 'getProjectStatuses').resolves([])
cy.stub(this.ipc, 'openProject').resolves(this.config)
cy.stub(this.ipc, 'getSpecs').yields(null, this.specs)
cy.stub(this.ipc, 'externalOpen')
cy.stub(this.ipc, 'logOut').resolves()
cy.stub(this.ipc, 'onAuthMessage').callsFake((function (_this) {
return function (cb) {
return _this.onAuthMessageCb = cb
}
})(this))
this.pingApiServer = this.util.deferred()
cy.stub(this.ipc, 'pingApiServer').returns(this.pingApiServer.promise)
this.beginAuth = this.util.deferred()
cy.stub(this.ipc, 'beginAuth').returns(this.beginAuth.promise)
start()
cy.contains('Log In').click()
})
})
it('pings api server', function () {
expect(this.ipc.pingApiServer).to.be.called
cy.get('.loader')
})
describe('when connected to api server', function () {
beforeEach(function () {
this.pingApiServer.resolve()
})
it('has dashboard login button', function () {
cy.get('.login').contains('button', 'Log In to Dashboard')
})
it('opens dashboard on clicking \'Cypress Dashboard\'', () => {
cy.contains('Cypress Dashboard').click().then(function () {
expect(this.ipc.externalOpen).to.be.calledWith('https://on.cypress.io/dashboard')
})
})
describe('click Log In to Dashboard', function () {
beforeEach(function () {
cy.get('.login').contains('button', 'Log In to Dashboard').as('loginBtn').click()
})
it('triggers ipc \'begin:auth\' on click', function () {
cy.then(function () {
expect(this.ipc.beginAuth).to.be.calledOnce
})
})
it('disables login button', () => {
cy.get('@loginBtn').should('be.disabled')
})
it('shows spinner with Opening browser', () => {
cy.get('@loginBtn').invoke('text').should('contain', 'Opening browser...')
})
context('on begin:auth', function () {
beforeEach(function () {
cy.get('@loginBtn')
})
it('displays spinner with Opening browser... and disables button', function () {
cy.contains('Opening browser...').should('be.disabled')
})
describe('on ipc begin:auth success', function () {
beforeEach(function () {
this.beginAuth.resolve(this.user)
})
it('goes to previous view', () => {
cy.shouldBeOnIntro()
})
it('displays username in UI', function () {
cy.get('nav a').should(function ($a) {
expect($a).to.contain(this.user.name)
})
})
it('displays username in success dialog', () => {
cy.get('.modal').contains('Jane Lane')
})
it('can close modal by clicking Continue', () => {
cy.get('.modal .btn:contains(Continue)').click()
cy.get('.modal').should('not.be.visible')
})
context('after clicking Continue', function () {
beforeEach(function () {
cy.get('.modal .btn:contains(Continue)').click()
})
context('log out', function () {
it('displays login button on logout', () => {
cy.get('nav a').contains('Jane').click()
cy.contains('Log Out').click()
cy.get('.nav').contains('Log In')
})
it('calls log:out', function () {
cy.get('nav a').contains('Jane').click()
cy.contains('Log Out').click().then(function () {
expect(this.ipc.logOut).to.be.called
})
})
it('has login button enabled when returning to login after logout', function () {
cy.get('nav a').contains('Jane').click()
cy.contains('Log Out').click()
cy.contains('Log In').click()
cy.get('.login button').eq(1)
.should('not.be.disabled').invoke('text')
.should('include', 'Log In to Dashboard')
})
})
})
})
describe('on ipc begin:auth error', function () {
beforeEach(function () {
this.beginAuth.reject({
name: 'foo',
message: 'There\'s an error',
})
})
it('displays error in ui', () => {
cy.get('.alert-danger').should('be.visible')
.contains('There\'s an error')
})
it('login button should be enabled', () => {
cy.get('@loginBtn').should('not.be.disabled')
})
})
describe('on ipc on:auth:message', function () {
beforeEach(function () {
this.onAuthMessageCb(null, {
message: 'some warning here',
type: 'warning',
})
})
it('displays warning in ui', () => {
cy.get('.warning').should('be.visible')
.contains('some warning here')
})
it('login button should be disabled', () => {
cy.get('@loginBtn').should('be.disabled')
})
it('on AUTH_COULD_NOT_LAUNCH_BROWSER login button changes', function () {
this.onAuthMessageCb(null, {
name: 'AUTH_COULD_NOT_LAUNCH_BROWSER',
type: 'warning',
message: 'foo',
})
cy.get('.login-content .btn-login')
.should('be.disabled')
.should('have.text', ' Could not open browser.')
})
it('<pre> can be click-selected', function () {
this.onAuthMessageCb(null, {
message: 'foo\n```\nbar\n```',
type: 'warning',
})
cy.get('.login-content .message pre').click()
cy.document().then(function ($doc) {
const selection = $doc.getSelection().toString()
expect(selection).to.eq('bar')
})
})
})
})
})
describe('Dashboard link in message', function () {
it('opens link to Dashboard Service on click', function () {
cy.contains('a', 'Cypress Dashboard Service')
.click().then(function () {
expect(this.ipc.externalOpen).to.be.calledWith('https://on.cypress.io/dashboard')
})
})
})
describe('terms and privacy message', () => {
it('opens links to terms and privacy on click', function () {
cy.contains('a', 'Terms of Use')
.click().then(function () {
expect(this.ipc.externalOpen).to.be.calledWith('https://on.cypress.io/terms-of-use')
})
cy.contains('a', 'Privacy Policy')
.click().then(function () {
expect(this.ipc.externalOpen).to.be.calledWith('https://on.cypress.io/privacy-policy')
})
})
})
})
describe('when not connected to api server', function () {
beforeEach(function () {
this.pingApiServerAgain = this.util.deferred()
this.ipc.pingApiServer.onCall(1).returns(this.pingApiServerAgain.promise)
this.pingApiServer.reject({
apiUrl: 'http://api.server',
message: 'ECONNREFUSED',
})
})
it('shows cannot connect to api server message', function () {
cy.contains('Cannot connect to API server')
cy.contains('http://api.server')
cy.contains('ECONNREFUSED')
})
describe('trying again', function () {
beforeEach(() => {
cy.contains('Try again').click()
})
it('pings again', () => {
cy.get('.loader').then(function () {
expect(this.ipc.pingApiServer).to.be.calledTwice
})
})
it('shows new error on failure', function () {
this.pingApiServerAgain.reject({
apiUrl: 'http://api.server',
message: 'WHADJAEXPECT',
})
cy.contains('Cannot connect to API server')
cy.contains('http://api.server')
cy.contains('WHADJAEXPECT')
})
it('shows login on success', function () {
this.pingApiServerAgain.resolve()
cy.get('.login').contains('button', 'Log In to Dashboard')
})
})
describe('api help link', () => {
it('goes to external api help link', () => {
cy.contains('Learn more').click().then(function () {
expect(this.ipc.externalOpen).to.be.calledWith('https://on.cypress.io/help-connect-to-api')
})
})
})
describe('closing login', function () {
beforeEach(() => {
cy.get('.login .close').click()
})
it('shows log in if connected and opened again', function () {
this.pingApiServerAgain.resolve()
cy.contains('Log In').click()
cy.get('.login').contains('button', 'Log In to Dashboard')
})
})
})
})