16029: Completes the basic set of login tests.
[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         cy.resetDB();
8     })
9
10     beforeEach(function() {
11         cy.arvadosFixture('users').as('users')
12         cy.arvadosFixture('api_client_authorizations').as('client_auth')
13         cy.clearCookies()
14         cy.clearLocalStorage()
15     })
16
17     it('logs in successfully with correct token', function() {
18         const active_user = this.users['active']
19         const active_token = this.client_auth['active']['api_token']
20         cy.visit('/token/?api_token='+active_token)
21         cy.url().should('contain', '/projects/')
22         cy.get('button[title="Account Management"]').click()
23         cy.get('ul[role=menu] > li[role=menuitem]').contains(`${active_user['first_name']} ${active_user['last_name']}`)
24     })
25
26     it('fails to log in with expired token', function() {
27         const expired_token = this.client_auth['expired']['api_token']
28         cy.visit('/token/?api_token='+expired_token)
29         cy.contains('Please log in')
30         cy.url().should('not.contain', '/projects/')
31     })
32
33     it('fails to log in with no token', function() {
34         cy.visit('/token/?api_token=')
35         cy.contains('Please log in')
36         cy.url().should('not.contain', '/projects/')
37     })
38
39     it('shows login page on first visit', function() {
40         cy.visit('/')
41         cy.contains('Please log in')
42         cy.url().should('not.contain', '/projects/')
43     })
44 })