From 379a5fd3dd62dbf23abf69c30e1c263fa1701c1e Mon Sep 17 00:00:00 2001 From: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> Date: Tue, 14 Jun 2022 08:31:51 -0600 Subject: [PATCH] Member Index View Actions: "Add Organization" (#17879) * Adds an Add Organization modal and e2e tests for the modal * Conditionally redirects to the correct view upon adding org * Combines modal tests within userIndexView.spec.js * Removes redundant code and switches assign role and add org button positions * Updates RSpec tests to account for conditional redirection * Lowercases the o in organization within _user_actions_dropdown.html.erb * Fixes failing e2e tests --- .../organization_memberships_controller.rb | 6 +- app/views/admin/users/index.html.erb | 1 + .../index/_user_actions_dropdown.html.erb | 13 +- .../adminFlows/users/userIndexView.spec.js | 122 ++++++++++++------ .../admin/organization_memberships_spec.rb | 6 +- 5 files changed, 104 insertions(+), 44 deletions(-) diff --git a/app/controllers/admin/organization_memberships_controller.rb b/app/controllers/admin/organization_memberships_controller.rb index 77b949e67..b0ad53e68 100644 --- a/app/controllers/admin/organization_memberships_controller.rb +++ b/app/controllers/admin/organization_memberships_controller.rb @@ -51,7 +51,11 @@ module Admin flash[:danger] = organization_membership.errors_as_sentence end - redirect_to admin_user_path(organization_membership.user_id) + if request.referer&.include?(admin_user_path(organization_membership.user_id)) + redirect_to admin_user_path(organization_membership.user_id) + else + redirect_to admin_users_path + end end format.js do diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb index e88dab750..d31f7443a 100644 --- a/app/views/admin/users/index.html.erb +++ b/app/views/admin/users/index.html.erb @@ -133,5 +133,6 @@ <% if FeatureFlag.enabled?(:member_index_view) %> <%= render "admin/users/index/filters_modal" %> + <%= render "admin/users/modals/add_organization_modal" %> <%= render "admin/users/modals/add_role_modal" %> <% end %> diff --git a/app/views/admin/users/index/_user_actions_dropdown.html.erb b/app/views/admin/users/index/_user_actions_dropdown.html.erb index 9e0dfeca5..6b0825a56 100644 --- a/app/views/admin/users/index/_user_actions_dropdown.html.erb +++ b/app/views/admin/users/index/_user_actions_dropdown.html.erb @@ -16,7 +16,18 @@ Assign role -
  • +
  • + +

  • <% end %>
  • diff --git a/cypress/integration/seededFlows/adminFlows/users/userIndexView.spec.js b/cypress/integration/seededFlows/adminFlows/users/userIndexView.spec.js index cf492fa7e..aa82e5153 100644 --- a/cypress/integration/seededFlows/adminFlows/users/userIndexView.spec.js +++ b/cypress/integration/seededFlows/adminFlows/users/userIndexView.spec.js @@ -339,45 +339,9 @@ describe('User index view', () => { }); }); }); - }); - describe('User index view with the member_index_view feature flag enabled', () => { - describe('small screens', () => { - beforeEach(() => { - cy.testSetup(); - cy.fixture('users/adminUser.json').as('user'); - cy.enableFeatureFlag('member_index_view') - .then(() => cy.get('@user')) - .then((user) => - cy.loginAndVisit(user, '/admin/member_manager/users'), - ); - cy.viewport('iphone-x'); - }); - - describe('User actions', () => { - it('Opens the assign role modal', () => { - cy.enableFeatureFlag('member_index_view'); - // Helper function for cypress-pipe - const click = (el) => el.click(); - - cy.findByRole('button', { name: 'User actions: Admin McAdmin' }) - .as('userActionsButton') - .pipe(click) - .should('have.attr', 'aria-expanded', 'true'); - - cy.findByRole('button', { name: 'Assign role' }).click(); - - cy.getModal().within(() => { - cy.findByText('Add role').should('be.visible'); - cy.findByText('Add a note to this action:').should('be.visible'); - cy.findByRole('button', { - name: 'Add', - }).should('exist'); - }); - }); - }); - - describe('large screens', () => { + describe('User index view with the member_index_view feature flag enabled', () => { + describe('small screens', () => { beforeEach(() => { cy.testSetup(); cy.fixture('users/adminUser.json').as('user'); @@ -386,7 +350,7 @@ describe('User index view', () => { .then((user) => cy.loginAndVisit(user, '/admin/member_manager/users'), ); - cy.viewport('macbook-16'); + cy.viewport('iphone-x'); }); describe('User actions', () => { @@ -410,6 +374,86 @@ describe('User index view', () => { }).should('exist'); }); }); + + it('Opens the add organization modal', () => { + cy.enableFeatureFlag('member_index_view'); + // Helper function for cypress-pipe + const click = (el) => el.click(); + + cy.findByRole('button', { name: 'User actions: Admin McAdmin' }) + .as('userActionsButton') + .pipe(click) + .should('have.attr', 'aria-expanded', 'true'); + + cy.findByRole('button', { name: 'Add organization' }).click(); + + cy.getModal().within(() => { + cy.findByText('Organization ID').should('be.visible'); + cy.findByText('Role').should('be.visible'); + cy.findByRole('button', { + name: 'Add organization', + }).should('exist'); + }); + }); + }); + + describe('large screens', () => { + beforeEach(() => { + cy.testSetup(); + cy.fixture('users/adminUser.json').as('user'); + cy.enableFeatureFlag('member_index_view') + .then(() => cy.get('@user')) + .then((user) => + cy.loginAndVisit(user, '/admin/member_manager/users'), + ); + cy.viewport('macbook-16'); + }); + + describe('User actions', () => { + it('Opens the assign role modal', () => { + cy.enableFeatureFlag('member_index_view'); + // Helper function for cypress-pipe + const click = (el) => el.click(); + + cy.findByRole('button', { name: 'User actions: Admin McAdmin' }) + .as('userActionsButton') + .pipe(click) + .should('have.attr', 'aria-expanded', 'true'); + + cy.findByRole('button', { name: 'Assign role' }).click(); + + cy.getModal().within(() => { + cy.findByText('Add role').should('be.visible'); + cy.findByText('Add a note to this action:').should( + 'be.visible', + ); + cy.findByRole('button', { + name: 'Add', + }).should('exist'); + }); + }); + + it('Opens the add organization modal', () => { + cy.enableFeatureFlag('member_index_view'); + // Helper function for cypress-pipe + const click = (el) => el.click(); + + cy.findByRole('button', { name: 'User actions: Admin McAdmin' }) + .as('userActionsButton') + .pipe(click) + .should('have.attr', 'aria-expanded', 'true'); + + cy.findByRole('button', { name: 'Add organization' }).click(); + + cy.getModal().within(() => { + cy.findByText('Organization ID').should('be.visible'); + cy.findByText('Role').should('be.visible'); + cy.findByRole('button', { + name: 'Add organization', + }).should('exist'); + }); + }); + }); }); }); }); diff --git a/spec/requests/admin/organization_memberships_spec.rb b/spec/requests/admin/organization_memberships_spec.rb index 3440c3a9f..3495fc8ad 100644 --- a/spec/requests/admin/organization_memberships_spec.rb +++ b/spec/requests/admin/organization_memberships_spec.rb @@ -21,7 +21,7 @@ RSpec.describe "/admin/organization_memberships", type: :request do } end.to not_change(user.organizations, :count) - expect(response).to redirect_to(admin_user_path(user.id)) + expect(response).to redirect_to(admin_users_path) expect(flash[:danger]).to include("does not exist") end @@ -36,7 +36,7 @@ RSpec.describe "/admin/organization_memberships", type: :request do } end.to not_change(user.organizations, :count) - expect(response).to redirect_to(admin_user_path(user.id)) + expect(response).to redirect_to(admin_users_path) expect(flash[:danger]).to include("not included in the list") end @@ -51,7 +51,7 @@ RSpec.describe "/admin/organization_memberships", type: :request do } end.to change(user.organizations, :count).by(1) - expect(response).to redirect_to(admin_user_path(user.id)) + expect(response).to redirect_to(admin_users_path) expect(flash[:success]).to include("successfully added") end end