16029: Removes the need to use pre-existing fixtures.
[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     let activeUser;
7     let inactiveUser;
8     let adminUser;
9
10     before(function() {
11         // Only set up common users once. These aren't set up as aliases because
12         // aliases are cleaned up after every test. Also it doesn't make sense
13         // to set the same users on beforeEach() over and over again, so we
14         // separate a little from Cypress' 'Best Practices' here.
15         cy.getUser('admin', 'Admin', 'User', true, true)
16             .as('adminUser').then(function() {
17                 adminUser = this.adminUser;
18             }
19         );
20         cy.getUser('active', 'Active', 'User', false, true)
21             .as('activeUser').then(function() {
22                 activeUser = this.activeUser;
23             }
24         );
25         cy.getUser('inactive', 'Inactive', 'User', false, false)
26             .as('inactiveUser').then(function() {
27                 inactiveUser = this.inactiveUser;
28             }
29         );
30     })
31
32     beforeEach(function() {
33         cy.clearCookies()
34         cy.clearLocalStorage()
35     })
36
37     it('shows login page on first visit', function() {
38         cy.visit('/')
39         cy.get('div#root').should('contain', 'Please log in')
40         cy.url().should('not.contain', '/projects/')
41     })
42
43     it('shows login page with no token', function() {
44         cy.visit('/token/?api_token=')
45         cy.get('div#root').should('contain', 'Please log in')
46         cy.url().should('not.contain', '/projects/')
47     })
48
49     it('shows inactive page to inactive user', function() {
50         cy.visit(`/token/?api_token=${inactiveUser.token}`)
51         cy.get('div#root').should('contain', 'Your account is inactive');
52     })
53
54     it('shows login page with invalid token', function() {
55         cy.visit('/token/?api_token=nope')
56         cy.get('div#root').should('contain', 'Please log in')
57         cy.url().should('not.contain', '/projects/')
58     })
59
60     it('logs in successfully with valid user token', function() {
61         cy.visit(`/token/?api_token=${activeUser.token}`);
62         cy.url().should('contain', '/projects/');
63         cy.get('div#root').should('not.contain', 'Your account is inactive');
64         cy.get('button[title="Account Management"]').click();
65         cy.get('ul[role=menu] > li[role=menuitem]').contains(
66             `${activeUser.user.first_name} ${activeUser.user.last_name}`);
67     })
68
69     it('logs in successfully with valid admin token', function() {
70         cy.visit(`/token/?api_token=${adminUser.token}`);
71         cy.url().should('contain', '/projects/');
72         cy.get('div#root').should('not.contain', 'Your account is inactive');
73         cy.get('button[title="Admin Panel"]').click();
74         cy.get('ul[role=menu] > li[role=menuitem]')
75             .contains('Repositories')
76             .type('{esc}');
77         cy.get('button[title="Account Management"]').click();
78         cy.get('ul[role=menu] > li[role=menuitem]').contains(
79             `${adminUser.user.first_name} ${adminUser.user.last_name}`);
80     })
81 })