X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/46b878b9773789f7a953f58f3de2cc4bf370e153..92bab47864916d852ef1c8f9579dafe8ae40f124:/cypress/integration/user-profile.spec.js diff --git a/cypress/integration/user-profile.spec.js b/cypress/integration/user-profile.spec.js index 325f38c7..7d21249c 100644 --- a/cypress/integration/user-profile.spec.js +++ b/cypress/integration/user-profile.spec.js @@ -35,8 +35,8 @@ describe('User profile tests', function() { role, website, }) { - cy.get('[data-cy=profile-form] [data-cy=firstName] [data-cy=value]').contains(firstName); - cy.get('[data-cy=profile-form] [data-cy=lastName] [data-cy=value]').contains(lastName); + cy.get('[data-cy=profile-form] input[name="firstName"]').invoke('val').should('equal', firstName); + cy.get('[data-cy=profile-form] input[name="lastName"]').invoke('val').should('equal', lastName); cy.get('[data-cy=profile-form] [data-cy=email] [data-cy=value]').contains(email); cy.get('[data-cy=profile-form] [data-cy=username] [data-cy=value]').contains(username); @@ -67,25 +67,47 @@ describe('User profile tests', function() { } } - beforeEach(function() { - cy.loginAs(adminUser); - cy.goToPath('/my-account'); - enterProfileValues({ - org: '', - org_email: '', - role: '', - website: '', + function assertContextMenuItems({ + account, + activate, + deactivate, + login, + setup + }) { + cy.get('[data-cy=user-profile-panel-options-btn]').click(); + cy.get('[data-cy=context-menu]').within(() => { + cy.get('[role=button]').contains('Advanced'); + + cy.get('[role=button]').should(account ? 'contain' : 'not.contain', 'Account Settings'); + cy.get('[role=button]').should(activate ? 'contain' : 'not.contain', 'Activate User'); + cy.get('[role=button]').should(deactivate ? 'contain' : 'not.contain', 'Deactivate User'); + cy.get('[role=button]').should(login ? 'contain' : 'not.contain', 'Login As User'); + cy.get('[role=button]').should(setup ? 'contain' : 'not.contain', 'Setup User'); }); - cy.get('[data-cy=profile-form] button[type="submit"]').click({force: true}); + cy.get('div[role=presentation]').click(); + } - cy.goToPath('/user/' + activeUser.user.uuid); - enterProfileValues({ - org: '', - org_email: '', - role: '', - website: '', + beforeEach(function() { + cy.updateResource(adminUser.token, 'users', adminUser.user.uuid, { + prefs: { + profile: { + organization: '', + organization_email: '', + role: '', + website_url: '', + }, + }, + }); + cy.updateResource(adminUser.token, 'users', activeUser.user.uuid, { + prefs: { + profile: { + organization: '', + organization_email: '', + role: '', + website_url: '', + }, + }, }); - cy.get('[data-cy=profile-form] button[type="submit"]').click({force: true}); }); it('non-admin can edit own profile', function() { @@ -94,8 +116,14 @@ describe('User profile tests', function() { cy.get('header button[title="Account Management"]').click(); cy.get('#account-menu').contains('My account').click(); - // Admin tab should be hidden - cy.get('div [role="tab"]').should('not.contain', 'ADMIN'); + // Admin actions should be hidden, no account menu + assertContextMenuItems({ + account: false, + activate: false, + deactivate: false, + login: false, + setup: false, + }); // Check initial values assertProfileValues({ @@ -157,8 +185,14 @@ describe('User profile tests', function() { // Submit should be disabled cy.get('[data-cy=profile-form] button[type="submit"]').should('be.disabled'); - // Admin tab should be hidden - cy.get('div [role="tab"]').should('not.contain', 'ADMIN'); + // Admin actions should be hidden, no account menu + assertContextMenuItems({ + account: false, + activate: false, + deactivate: false, + login: false, + setup: false, + }); }); it('admin can edit own profile', function() { @@ -167,8 +201,14 @@ describe('User profile tests', function() { cy.get('header button[title="Account Management"]').click(); cy.get('#account-menu').contains('My account').click(); - // Admin tab should be visible - cy.get('div [role="tab"]').should('contain', 'ADMIN'); + // Admin actions should be visible, no account menu + assertContextMenuItems({ + account: false, + activate: false, + deactivate: true, + login: false, + setup: false, + }); // Check initial values assertProfileValues({ @@ -239,6 +279,15 @@ describe('User profile tests', function() { role: 'Researcher', website: 'changed.local', }); + + // Admin actions should be visible, no account menu + assertContextMenuItems({ + account: false, + activate: false, + deactivate: true, + login: true, + setup: false, + }); }); it('displays role groups on user profile', function() { @@ -291,4 +340,110 @@ describe('User profile tests', function() { cy.get('[data-cy=user-profile-groups-data-explorer]').should('not.contain', projectGroupName); }); + it('allows performing admin functions', function() { + cy.loginAs(adminUser); + cy.goToPath('/user/' + activeUser.user.uuid); + + // Check that user is active + cy.get('[data-cy=account-status]').contains('Active'); + cy.get('div [role="tab"]').contains('GROUPS').click(); + cy.get('[data-cy=user-profile-groups-data-explorer]').should('contain', 'All users'); + cy.get('div [role="tab"]').contains('PROFILE').click(); + assertContextMenuItems({ + account: false, + activate: false, + deactivate: true, + login: true, + setup: false, + }); + + // Deactivate user + cy.get('[data-cy=user-profile-panel-options-btn]').click(); + cy.get('[data-cy=context-menu]').contains('Deactivate User').click(); + cy.get('[data-cy=confirmation-dialog-ok-btn]').click(); + + // Check that user is deactivated + cy.get('[data-cy=account-status]').contains('Inactive'); + cy.get('div [role="tab"]').contains('GROUPS').click(); + cy.get('[data-cy=user-profile-groups-data-explorer]').should('not.contain', 'All users'); + cy.get('div [role="tab"]').contains('PROFILE').click(); + assertContextMenuItems({ + account: false, + activate: true, + deactivate: false, + login: true, + setup: true, + }); + + // Setup user + cy.get('[data-cy=user-profile-panel-options-btn]').click(); + cy.get('[data-cy=context-menu]').contains('Setup User').click(); + cy.get('[data-cy=confirmation-dialog-ok-btn]').click(); + + // Check that user is setup + cy.get('[data-cy=account-status]').contains('Setup'); + cy.get('div [role="tab"]').contains('GROUPS').click(); + cy.get('[data-cy=user-profile-groups-data-explorer]').should('contain', 'All users'); + cy.get('div [role="tab"]').contains('PROFILE').click(); + assertContextMenuItems({ + account: false, + activate: true, + deactivate: true, + login: true, + setup: false, + }); + + // Activate user + cy.get('[data-cy=user-profile-panel-options-btn]').click(); + cy.get('[data-cy=context-menu]').contains('Activate User').click(); + cy.get('[data-cy=confirmation-dialog-ok-btn]').click(); + + // Check that user is active + cy.get('[data-cy=account-status]').contains('Active'); + cy.get('div [role="tab"]').contains('GROUPS').click(); + cy.get('[data-cy=user-profile-groups-data-explorer]').should('contain', 'All users'); + cy.get('div [role="tab"]').contains('PROFILE').click(); + assertContextMenuItems({ + account: false, + activate: false, + deactivate: true, + login: true, + setup: false, + }); + + // Deactivate and activate user skipping setup + cy.get('[data-cy=user-profile-panel-options-btn]').click(); + cy.get('[data-cy=context-menu]').contains('Deactivate User').click(); + cy.get('[data-cy=confirmation-dialog-ok-btn]').click(); + // Check + cy.get('[data-cy=account-status]').contains('Inactive'); + cy.get('div [role="tab"]').contains('GROUPS').click(); + cy.get('[data-cy=user-profile-groups-data-explorer]').should('not.contain', 'All users'); + cy.get('div [role="tab"]').contains('PROFILE').click(); + assertContextMenuItems({ + account: false, + activate: true, + deactivate: false, + login: true, + setup: true, + }); + // reactivate + cy.get('[data-cy=user-profile-panel-options-btn]').click(); + cy.get('[data-cy=context-menu]').contains('Activate User').click(); + cy.get('[data-cy=confirmation-dialog-ok-btn]').click(); + + // Check that user is active + cy.get('[data-cy=account-status]').contains('Active'); + cy.get('div [role="tab"]').contains('GROUPS').click(); + cy.get('[data-cy=user-profile-groups-data-explorer]').should('contain', 'All users'); + cy.get('div [role="tab"]').contains('PROFILE').click(); + assertContextMenuItems({ + account: false, + activate: false, + deactivate: true, + login: true, + setup: false, + }); + }); + });