1082819c56295c314d84f2b7682428f85dadf34e
[arvados-workbench2.git] / cypress / integration / login.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Login tests', function() {
6     before(function() {
7         this.email = `account_${Math.random()}@example.com`
8         this.password = Math.random()
9         this.firstName = 'Test'
10         this.lastName = 'User'
11     })
12
13     beforeEach(function() {
14         cy.visit('/')
15         cy.contains('Please log in')
16         cy.get('button').contains('Log in').click()
17         cy.url().should('contain', "/users/sign_in")
18     })
19
20     it('register a new user', function() {
21         cy.get('a[role=button]').contains('Sign up for a new account').click()
22         cy.url().should('contain', '/users/sign_up')
23         cy.get('input[name="user[first_name]"]').type(this.firstName)
24         cy.get('input[name="user[last_name]"]').type(this.lastName)
25         cy.get('input[name="user[email]"]').type(this.email)
26         cy.get('input[name="user[password]"]').type(this.password)
27         cy.get('input[name="user[password_confirmation]"]').type(this.password)
28         cy.get('input[type=submit]').contains('Sign up').click()
29         cy.url().should('contain', '/projects/')
30         cy.get('button[title="Account Management"]').click()
31         cy.get('ul[role=menu] > li[role=menuitem]').contains(`${this.firstName} ${this.lastName}`)
32     })
33
34     it('logs in successfully', function() {
35         cy.get('input[type=email]').type(this.email)
36         cy.get('input[type=password]').type(this.password)
37         cy.get('input[type=submit]').contains('Sign in').click()
38         cy.url().should('contain', '/projects/')
39         cy.get('button[title="Account Management"]').click()
40         cy.get('ul[role=menu] > li[role=menuitem]').contains(`${this.firstName} ${this.lastName}`)
41     })
42
43     it('fails to log in with incorrect password', function() {
44         cy.get('input[type=email]').type(this.email)
45         cy.get('input[type=password]').type('incorrect')
46         cy.get('input[type=submit]').contains('Sign in').click()
47         cy.url().should('contain', "/users/sign_in")
48         cy.get('div.alert').contains('Invalid email or password')
49     })
50 })