github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/cypress/integration/auth/settings.ts (about)

     1  // few tests just to quickly validate the endpoints are working
     2  describe('Settings page', () => {
     3    it('should display error when log in with random creds', () => {
     4      cy.visit('/login');
     5  
     6      cy.get('input#username').focus().type('random');
     7      cy.get('input#password').focus().type('user');
     8      cy.get('button.sign-in-button').click();
     9      cy.get('#error').should('contain.text', 'invalid credentials');
    10      // Expect it not to be redirected to main page
    11      cy.url().should('contain', '/login');
    12    });
    13  
    14    it('should be able to log in with default creds', () => {
    15      cy.visit('/login');
    16  
    17      cy.get('input#username').focus().type('admin');
    18      cy.get('input#password').focus().type('admin');
    19      cy.get('button.sign-in-button').click();
    20  
    21      // Expect it to be redirected to main page
    22      cy.url().should('contain', '/?query=');
    23  
    24      cy.visit('/logout');
    25    });
    26  
    27    it.only('should be able to see correct settings page', () => {
    28      cy.visit('/login');
    29  
    30      cy.get('input#username').focus().type('admin');
    31      cy.get('input#password').focus().type('admin');
    32      cy.findByTestId('sign-in-button').click();
    33  
    34      cy.findByTestId('sidebar-settings').click();
    35      cy.url().should('contain', '/settings');
    36  
    37      cy.findByTestId('settings-userstab').click();
    38  
    39      cy.url().should('contain', '/settings/users');
    40  
    41      // Two users should be displayed
    42      cy.findByTestId('table-ui').get('tbody>tr').should('have.length', 2);
    43      cy.findByTestId('table-ui')
    44        .get('tbody > tr:nth-child(1)')
    45        .should('contain.text', 'admin@localhost');
    46  
    47      cy.findByTestId('settings-adduser').click();
    48      cy.url().should('contain', '/settings/users/add');
    49  
    50      cy.get('#userAddName').type('user');
    51      cy.get('#userAddPassword').type('user');
    52      cy.get('#userAddEmail').type('user@domain.com');
    53      cy.get('#userAddFullName').type('Readonly User');
    54      cy.findByTestId('settings-useradd').click();
    55  
    56      cy.url().should('contain', '/settings/users');
    57  
    58      // Two users should be displayed
    59      cy.findByTestId('table-ui').get('tbody>tr').should('have.length', 3);
    60      cy.findByTestId('table-ui')
    61        .get('tbody>tr:nth-child(3)')
    62        .should('contain.text', 'user@domain.com');
    63  
    64      cy.visit('/logout');
    65      cy.visit('/login');
    66  
    67      cy.get('input#username').focus().type('user');
    68      cy.get('input#password').focus().type('user');
    69      cy.findByTestId('sign-in-button').click();
    70  
    71      // Expect it to be redirected to main page
    72      cy.url().should('contain', '/?query=');
    73  
    74      cy.visit('/logout');
    75    });
    76  
    77    it.only('should be able to change password', () => {
    78      cy.visit('/login');
    79  
    80      cy.get('input#username').focus().type('user');
    81      cy.get('input#password').focus().type('user');
    82      cy.findByTestId('sign-in-button').click();
    83  
    84      cy.findByTestId('sidebar-settings').click();
    85      cy.url().should('contain', '/settings');
    86  
    87      cy.findByText('Change Password').click();
    88      cy.url().should('contain', '/settings/security');
    89  
    90      cy.get('input[name="oldPassword"]').focus().type('user');
    91      cy.get('input[name="password"]').focus().type('pass');
    92      cy.get('input[name="passwordAgain"]').focus().type('pass');
    93  
    94      cy.get('button').findByText('Save').click();
    95  
    96      cy.findByText('Password has been successfully changed').should(
    97        'be.visible'
    98      );
    99  
   100      cy.visit('/logout');
   101      cy.visit('/login');
   102  
   103      cy.get('input#username').focus().type('user');
   104      cy.get('input#password').focus().type('pass');
   105      cy.findByTestId('sign-in-button').click();
   106  
   107      cy.findByTestId('sidebar-settings').click();
   108      cy.url().should('contain', '/settings');
   109    });
   110  });