1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 describe('Login tests', 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;
20 cy.getUser('active', 'Active', 'User', false, true)
21 .as('activeUser').then(function() {
22 activeUser = this.activeUser;
25 cy.getUser('inactive', 'Inactive', 'User', false, false)
26 .as('inactiveUser').then(function() {
27 inactiveUser = this.inactiveUser;
32 beforeEach(function() {
34 cy.clearLocalStorage()
37 it('shows login page on first visit', function() {
39 cy.get('div#root').should('contain', 'Please log in')
40 cy.url().should('not.contain', '/projects/')
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/')
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');
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/')
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}`);
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')
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}`);