From 3d3d5afcb6794facbe54a4f8d3917f963409424d Mon Sep 17 00:00:00 2001 From: josemigallas Date: Tue, 15 Oct 2024 18:42:02 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=8B=F0=9F=A5=92=20updates=20provider?= =?UTF-8?q?=20account=20Invitations=20index=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/account/invitations_controller.rb | 17 +-- app/helpers/buttons_helper.rb | 3 +- app/helpers/invitations_helper.rb | 8 +- .../account/invitations_index_presenter.rb | 56 +++++++++ .../admin/account/invitations/index.html.erb | 47 ++++---- config/locales/en.yml | 8 +- features/old/accounts/invitations.feature | 98 ---------------- .../old/buyers/invitations/for_admins.feature | 12 +- features/old/providers/invitations.feature | 15 --- .../admin/account/invitations.feature | 108 ++++++++++++++++++ features/step_definitions/custom_web_steps.rb | 1 + .../step_definitions/invitations_steps.rb | 27 ++++- features/step_definitions/signup_steps.rb | 12 -- features/step_definitions/table_steps.rb | 5 + features/support/helpers/capybara_helpers.rb | 18 ++- features/support/paths.rb | 9 +- test/factories/invitations.rb | 12 +- 17 files changed, 272 insertions(+), 184 deletions(-) create mode 100644 app/presenters/provider/admin/account/invitations_index_presenter.rb delete mode 100644 features/old/providers/invitations.feature create mode 100644 features/provider/admin/account/invitations.feature diff --git a/app/controllers/provider/admin/account/invitations_controller.rb b/app/controllers/provider/admin/account/invitations_controller.rb index 8e12220d72..6dac5f2c73 100644 --- a/app/controllers/provider/admin/account/invitations_controller.rb +++ b/app/controllers/provider/admin/account/invitations_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Provider::Admin::Account::InvitationsController < Provider::Admin::Account::BaseController before_action :authorize_multiple_users before_action :set_resource @@ -6,12 +8,8 @@ class Provider::Admin::Account::InvitationsController < Provider::Admin::Account inherit_resources belongs_to :account - create! do |success, failure| - success.html do - redirect_to provider_admin_account_invitations_path, - notice: 'Invitation will be sent soon.' - end + success.html { redirect_to provider_admin_account_invitations_path, notice: t('.success') } end destroy! do |success, failure| @@ -23,11 +21,8 @@ def resend @invitation.resend respond_to do |format| - format.html do - flash[:success] = 'Invitation will be resent soon.' - redirect_to provider_admin_account_invitations_path - end - format.xml { head :ok } + format.html { redirect_to provider_admin_account_invitations_path, notice: t('.success') } + format.xml { head :ok } # TODO: figure out if this is still used or it needs to be cleaned up end end @@ -38,7 +33,7 @@ def authorize_multiple_users end def collection - @invitations ||= end_of_association_chain.paginate(:page => params[:page]) + @collection ||= end_of_association_chain end def set_resource diff --git a/app/helpers/buttons_helper.rb b/app/helpers/buttons_helper.rb index 71b363ec4a..04e134d014 100644 --- a/app/helpers/buttons_helper.rb +++ b/app/helpers/buttons_helper.rb @@ -145,7 +145,8 @@ def dropdown_link(*args) end def pf_link_to(label, url, options = {}) - options[:class] = join_dom_classes('pf-c-button pf-m-link', options[:class]) + variant = options.delete(:variant) || :link + options[:class] = join_dom_classes("pf-c-button pf-m-#{variant}", options[:class]) link_to label, url, options end diff --git a/app/helpers/invitations_helper.rb b/app/helpers/invitations_helper.rb index d20155614e..da33275210 100644 --- a/app/helpers/invitations_helper.rb +++ b/app/helpers/invitations_helper.rb @@ -1,3 +1,6 @@ +# frozen_string_literal: true + +# TODO: remove and use presenter module InvitationsHelper def invitation_sent_date(invitation) invitation.sent_at&.to_s(:long) || 'Not sent yet' @@ -10,9 +13,4 @@ def invitation_status(invitation) "no" end end - - def button_to_resend_buyer_invitation(invitation) - fancy_link_to('Resend', resend_provider_admin_account_invitation_path(invitation.account,invitation), - { :id => "resend-invitation-#{invitation.id}", :method => :put }) - end end diff --git a/app/presenters/provider/admin/account/invitations_index_presenter.rb b/app/presenters/provider/admin/account/invitations_index_presenter.rb new file mode 100644 index 0000000000..41f85a5a98 --- /dev/null +++ b/app/presenters/provider/admin/account/invitations_index_presenter.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +class Provider::Admin::Account::InvitationsIndexPresenter + include System::UrlHelpers.system_url_helpers + include InvitationsHelper + + alias status invitation_status + alias sent_date invitation_sent_date + + def initialize(invitations, user, params) + @ability = Ability.new(user) + pagination_params = { page: params[:page] || 1, per_page: params[:per_page] || 20 } + sorting_params = "#{params[:sort].presence || 'sent_at'} #{params[:direction].presence || 'desc'}" + @invitations = invitations.paginate(pagination_params) + .reorder(sorting_params) + end + + attr_reader :invitations + + def empty_state? + @invitations.total_entries.zero? + end + + def can_send_invitations? + @ability.can?(:create, Invitation) && @ability.can?(:see, :multiple_users) + end + + # def sent_date(invitation) + # invitation.sent_at&.to_s(:long) || 'Not sent yet' + # end + + # def status(invitation) + # invitation_status(invitation) + # # if invitation.accepted? + # # "yes, on #{invitation.accepted_at.to_s(:short)}" + # # else + # # 'no' + # # end + # end + + def can_manage_invitation?(invitation) + @can_manage_invitation ||= @ability.can?(:manage, invitation) + end + + def toolbar_props + { + totalEntries: @invitations.total_entries, + actions: [{ + variant: :primary, + label: I18n.t('provider.admin.account.invitations.index.send_invitation_title'), + href: new_provider_admin_account_invitation_path + }] + } + end + +end diff --git a/app/views/provider/admin/account/invitations/index.html.erb b/app/views/provider/admin/account/invitations/index.html.erb index 838f9dc004..11379f0ee2 100644 --- a/app/views/provider/admin/account/invitations/index.html.erb +++ b/app/views/provider/admin/account/invitations/index.html.erb @@ -1,52 +1,53 @@ <% content_for :page_header_title, 'Invitations' %> <% content_for :javascripts do %> - <%# HACK: temporary reuse css of existing pack "table_toolbar". Once toolbar is implemented, - import the whole pack with "javascript_packs_with_chunks_tag" %> - <%= stylesheet_packs_chunks_tag 'table_toolbar' %> + <%= javascript_packs_with_chunks_tag 'table_toolbar' %> <% end %> -<% if @invitations.total_entries.zero? %> +<% presenter = Provider::Admin::Account::InvitationsIndexPresenter.new(collection, current_user, params) %> + +<% if presenter.empty_state? %> <%= render partial: 'shared/empty_state', locals: { icon: 'plus-circle', title: t('.empty_state_title'), body: t('.empty_state_body'), primary: { title: t('.empty_state_primary_title'), href: new_provider_admin_account_invitation_path } } %> <% else %> - +
- - - + <%= th_sortable 'sent_at', 'Sent' %> + <%= th_sortable 'accepted_at', 'Accepted?' %> + - <% @invitations.each do |invitation| %> + <% presenter.invitations.each do |invitation| %> - - + +
RecipientSentAccepted? - <% if can?(:create, Invitation) and can?(:see, :multiple_users) %> - <%= link_to_unless_current 'Invite a New Team Member', new_provider_admin_account_invitation_path, :class => 'action add' %> - <% end %> -
<%= h invitation.email %><%= invitation_sent_date(invitation) %><%= invitation_status(invitation) %><%= presenter.sent_date(invitation) %><%= presenter.status(invitation) %>
- <% if can? :manage, invitation %> + <% if presenter.can_manage_invitation?(invitation) %>
- <% unless invitation.accepted? -%> - <%= fancy_link_to("Resend", resend_provider_admin_account_invitation_path(invitation), {:method => :put, :class => 'refresh', "data-id" => invitation.id}) %> - <% end -%> + <%= pf_link_to 'Resend', resend_provider_admin_account_invitation_path(invitation), + method: :put, + variant: invitation.accepted? ? :disabled : :primary, + class: 'refresh', + data: { id: invitation.id } %>
- <% end -%> - <% if can? :manage, invitation %> + <% end %> + <% if presenter.can_manage_invitation?(invitation) %>
- <%= delete_link_for provider_admin_account_invitation_path(invitation), data: { confirm: 'Are you sure you want to delete this invitation?' } %> + <%= pf_link_to 'Delete', provider_admin_account_invitation_path(invitation), + data: { confirm: t('.delete_confirm') }, + variant: :danger, + method: :delete %>
<% end %>
@@ -57,6 +58,4 @@ <% end %>
- - <%= will_paginate @invitations %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 15e0755f78..e7814d9d8b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -404,10 +404,16 @@ en: admin: account: invitations: + create: + success: Invitation will be sent soon. index: + delete_confirm: Are you sure you want to delete this invitation? empty_state_title: No invitations empty_state_body: To add new members to your team, send them an invitation to join. - empty_state_primary_title: Invite a team member + empty_state_primary_title: Invite a new team member + send_invitation_title: Invite a new team member + resend: + success: Invitation will be resent soon. users: form: submit_button_label: 'Update User' diff --git a/features/old/accounts/invitations.feature b/features/old/accounts/invitations.feature index 4ec727af99..4722f5d52d 100644 --- a/features/old/accounts/invitations.feature +++ b/features/old/accounts/invitations.feature @@ -9,16 +9,6 @@ Feature: Invitations And provider "foo.3scale.localhost" has multiple applications enabled And provider "foo.3scale.localhost" has "multiple_users" switch allowed - @javascript - Scenario: When switch is denied as provider - Given current domain is the admin domain of provider "foo.3scale.localhost" - And provider "foo.3scale.localhost" has "multiple_users" switch denied - When I log in as provider "foo.3scale.localhost" - And I go to the provider users page - Then I should not see "Invite a New Team Member" - - When I request the url of the provider new invitation page then I should see an exception - Scenario: When switch is denied as buyer Given a buyer "apininja" signed up to provider "foo.3scale.localhost" And provider "foo.3scale.localhost" has "multiple_users" switch denied @@ -37,91 +27,3 @@ Feature: Invitations And I fill in "Send invitation to" with "alice@foo.3scale.localhost" And I press "Invite User" Then invitation from account "apininja" should be sent to "alice@foo.3scale.localhost" - - @javascript - Scenario: Attempt to send invitation to an email of already existing user - Given an user "alice" of account "foo.3scale.localhost" - And user "alice" has email "alice@foo.3scale.localhost" - And current domain is the admin domain of provider "foo.3scale.localhost" - When I log in as provider "foo.3scale.localhost" - And I go to the provider new invitation page - And I fill in "Send invitation to" with "alice@foo.3scale.localhost" - And I press "Send" - Then I should see error "has been taken by another user" for field "Send invitation to" - And no invitation should be sent to "alice@foo.3scale.localhost" - - @javascript - Scenario: Invitation to an email of already existing pending invitation - Given an invitation from account "foo.3scale.localhost" sent to "alice@foo.3scale.localhost" - And a clear email queue - And current domain is the admin domain of provider "foo.3scale.localhost" - When I log in as provider "foo.3scale.localhost" - And I go to the provider new invitation page - And I fill in "Send invitation to" with "alice@foo.3scale.localhost" - And I press "Send" - Then I should see "This invitation has already been sent." - - @javascript - Scenario: Deleted user from invitation with changed email - Given an invitation from account "foo.3scale.localhost" sent to "ubuntu@foo.3scale.localhost" - When I follow the link to signup provider "foo.3scale.localhost" in the invitation sent to "ubuntu@foo.3scale.localhost" - And I fill in the invitation signup with email "gentoo@foo.3scale.localhost" - When I log in as provider "foo.3scale.localhost" - And I go to the provider users page - Then I should see "gentoo@foo.3scale.localhost" - And I should not see "ubuntu@foo.3scale.localhost" - Then I press "Delete" for user "gentoo@foo.3scale.localhost" and confirm the dialog - And I go to the provider sent invitations page - Then I should not see "ubuntu@foo.3scale.localhost" - - @javascript - Scenario: Accepting an invitation - Given an invitation from account "foo.3scale.localhost" sent to "alice@foo.3scale.localhost" - And all the rolling updates features are off - And current domain is the admin domain of provider "foo.3scale.localhost" - When I follow the link to signup in the invitation sent to "alice@foo.3scale.localhost" - And I fill in the invitation signup as "alice" - And current domain is the admin domain of provider "foo.3scale.localhost" - When I try to log in as provider "alice" - Then I should be logged in as "alice" - And follow "API" - And I should see "Analytics" - - @javascript - Scenario: Managing sent invitations - Given the following invitations from account "foo.3scale.localhost" exist: - | Email | State | - | alice@foo.3scale.localhost | pending | - | bob@foo.3scale.localhost | accepted | - And current domain is the admin domain of provider "foo.3scale.localhost" - When I log in as provider "foo.3scale.localhost" - And I go to the provider users page - And I follow "Invitations" - Then I should see "Invitations" in a header - And I should see pending invitation for "alice@foo.3scale.localhost" - And I should see accepted invitation for "bob@foo.3scale.localhost" - - @javascript - Scenario: Deleting an invitation - Given an invitation from account "foo.3scale.localhost" sent to "alice@foo.3scale.localhost" - And current domain is the admin domain of provider "foo.3scale.localhost" - When I log in as provider "foo.3scale.localhost" - And I go to the provider sent invitations page - And I press "Delete" for an invitation from account "foo.3scale.localhost" for "alice@foo.3scale.localhost" and confirm the dialog - Then I should not see invitation for "alice@foo.3scale.localhost" - - @javascript - Scenario: Managing sent invitations disabled when multiple_users switch denied - Given provider "foo.3scale.localhost" has "multiple_users" switch denied - And current domain is the admin domain of provider "foo.3scale.localhost" - When I log in as provider "foo.3scale.localhost" - And I go to the provider users page - Then I should not see "Invitations" - - @security @allow-rescue @javascript - Scenario: Only admins can send invitations - Given an active user "alice" of account "foo.3scale.localhost" - And current domain is the admin domain of provider "foo.3scale.localhost" - When I log in as provider "alice" - And I go to the provider new invitation page - Then I should be denied the access diff --git a/features/old/buyers/invitations/for_admins.feature b/features/old/buyers/invitations/for_admins.feature index 72c39d2c87..5503bdf94f 100644 --- a/features/old/buyers/invitations/for_admins.feature +++ b/features/old/buyers/invitations/for_admins.feature @@ -1,7 +1,7 @@ @javascript -Feature: Invitations on partner accounts for admins - In order to allow provider account admins to administer their partner accounts - As an admin I want to manage the invitations of users to the partner accounts +Feature: Buyer Account Invitations + + TODO: update as part of THREESCALE-9876 in the same way as features/provider/admin/account/invitations.feature Background: Given the default product of provider "master" has name "Master API" @@ -41,12 +41,14 @@ Feature: Invitations on partner accounts for admins Given an invitation sent to "alice@lolcats.com" to join account "lol cats" was accepted And an invitation sent to "bob@lolcats.com" to join account "lol cats" When I navigate to the page of the invitations of the partner "lol cats" - Then I should see accepted invitation for "alice@lolcats.com" - And I should see pending invitation for "bob@lolcats.com" + Then the table should contain an accepted invitation from "alice@lolcats.com" + And the table should contain a pending invitation from "bob@lolcats.com" Scenario: Destroying invitations Given an invitation sent to "alice@lolcats.com" to join account "lol cats" When I navigate to the page of the invitations of the partner "lol cats" + # And select action "Delete" of "alice@example.org" + # And confirm the dialog And I press "Delete" for an invitation from account "lol cats" for "alice@lolcats.com" and confirm the dialog Then I should not see invitation for "alice@lolcats.com" diff --git a/features/old/providers/invitations.feature b/features/old/providers/invitations.feature deleted file mode 100644 index 4a2635c322..0000000000 --- a/features/old/providers/invitations.feature +++ /dev/null @@ -1,15 +0,0 @@ -@emails -Feature: Invitations - In order to allow more people to be users of a provider account - As an account admin - I want to invite them - - Background: - Given a provider is logged in - And the provider has multiple applications enabled - And the provider has "multiple_users" switch allowed - - @javascript - Scenario: Sending an invitation as provider - And I send a provider invitation to "alice@foo.3scale.localhost" - Then an invitation with the admin domain of account "foo.3scale.localhost" should be sent to "alice@foo.3scale.localhost" diff --git a/features/provider/admin/account/invitations.feature b/features/provider/admin/account/invitations.feature new file mode 100644 index 0000000000..e9dbda36d9 --- /dev/null +++ b/features/provider/admin/account/invitations.feature @@ -0,0 +1,108 @@ +@javascript +Feature: Provider Account Settings User Invitations + + Background: + Given a provider is logged in + + Rule: User is a member + Background: + Given a member user "alice" of the provider + And the user logs in + + Scenario: Inviting new users is not allowed + When they go to the provider users page + Then there should not be a link to "Invite a New User" + And they should see an error when going to the provider new invitation page + + Scenario: Navigation to invitations page is not possible + When they select "Account Settings" from the context selector + Then they should not see "Users" within the main menu + + @security @allow-rescue + Scenario: Only admins can send invitations + When they go to the provider new invitation page + Then I should be denied the access + + Rule: No multiple users permissions + Background: + Given the provider has "multiple_users" switch denied + + Scenario: Inviting new users is not allowed + When they go to the provider users page + Then there should not be a link to "Invite a New User" + And they should see an error when going to the provider new invitation page + + Scenario: Navigation to invitations page is not possible + When they select "Account Settings" from the context selector + And press "Users" within the main menu + And they should not see "Invitations" within the main menu's section Users + + @security @allow-rescue + Scenario: Only admins can send invitations + When they go to the provider new invitation page + Then I should be denied the access + + Rule: Multiple users permission + Background: + Given the provider has "multiple_users" switch allowed + + Scenario: Navigation + When they select "Account Settings" from the context selector + And press "Users" within the main menu + And follow "Invitations" within the main menu's section Users + Then the current page is the provider sent invitations page + + Scenario: Inviting new users is possible + When they go to the provider users page + And follow "Invite a New User" + Then the current page is the provider new invitation page + + Scenario: Inviting an existing user + Given a member user "Alice" of the provider + And the user has email "alice@example.org" + When they go to the provider sent invitations page + And follow "Invite a new team member" + And the form is submitted with: + | Send invitation to | alice@example.org | + Then field "Send invitation to" has inline error "Has been taken by another user" + And no invitation should be sent to "alice@example.org" + + Scenario: Inviting the same user twice + Given an invitation sent to "alice@example.org" to join account "foo.3scale.localhost" + And a clear email queue + When they go to the provider new invitation page + And the form is submitted with: + | Send invitation to | alice@example.org | + Then field "Send invitation to" has inline error "This invitation has already been sent." + And no invitation should be sent to "alice@example.org" + + Scenario: Accepting an invitation with different email + Given an invitation sent to "alice@example.org" to join account "foo.3scale.localhost" + And the invitee follows the link to sign up to the provider in the invitation sent to "alice@example.org" + And the form is submitted with: + | Email | peter@example.com | + | Username | peter | + | Password | 123456 | + | Password confirmation | 123456 | + When the provider logs in + And they go to the provider users page + Then the table has the following row: + | Name | Email | Role | + | peter | peter@example.com | member | + + Scenario: List of invitations + Given the following invitations from the provider: + | Email | State | + | alice@example.org | pending | + | bob@example.org | accepted | + When they go to the provider sent invitations page + Then the table should contain a pending invitation from "alice@example.org" + And the table should contain an accepted invitation from "bob@example.org" + + Scenario: Deleting an invitation + Given an invitation sent to "alice@example.org" to join account "foo.3scale.localhost" + When they go to the provider sent invitations page + And select action "Delete" of "alice@example.org" + And confirm the dialog + Then they should see the flash message "Invitation was successfully deleted" + And they should see "No invitations" diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 449ef5cbee..a1dfccb52e 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -67,6 +67,7 @@ def matches_path?(url, path) page.html.should match /#{table.rows.map(&:first).map(&:downcase).join(".*")}/mi end +# DEPRECATED: replace with field {string} has inline error {string} Then /^I should see error "([^"]*)" for field "([^"]*)"$/ do |error, field| # This assumes the error is in a

element next to (sibling of) the input field. # Not sure if this will work in the general case. diff --git a/features/step_definitions/invitations_steps.rb b/features/step_definitions/invitations_steps.rb index 2f76b8d1f0..5a143a6090 100644 --- a/features/step_definitions/invitations_steps.rb +++ b/features/step_definitions/invitations_steps.rb @@ -9,10 +9,25 @@ FactoryBot.create(:invitation, account: account, email: address) end -Given "the following invitations from {account} exist:" do |account, table| +# Given the following invitations from the provider exists: +# | Email | State | +# | alice@example.org | pending | +# | bob@example.org | accepted | +# +Given "the following invitation(s) from {provider_or_buyer}:" do |account, table| + parameterize_headers(table) table.hashes.each do |row| - invitation = FactoryBot.create(:invitation, account: account, email: row['Email']) - invitation.accept! if row['State'] == 'accepted' + email = row.delete('email') + accepted = case state = row.delete('state') + when 'accepted' then true + when 'pending' then false + else + raise ArgumentError, "Invitations are either 'accepted' or 'pending', not #{state}" + end + + FactoryBot.create(:invitation, account: account, + email: email, + accepted: accepted) end end @@ -27,9 +42,9 @@ click_first_link_in_email end -When(/^I follow the link to signup provider "(.*?)" in the invitation sent to "(.*?)"$/) do |provider, address| +When "the invitee follows the link to sign up to {provider} in the invitation sent to {string}" do |provider, address| open_email(address) - set_current_domain(Account.find_by(org_name: provider).external_admin_domain) + set_current_domain(provider.external_admin_domain) click_first_link_in_email end @@ -108,7 +123,7 @@ assert has_content?("Sent invitations for #{org_name}") end -Then(/^I should see (accepted|pending) invitation for "([^\"]*)"$/) do |state, email| +Then /^the table should contain an? (accepted|pending) invitation from "(.*)"$/ do |state, email| accepted = state == 'accepted' assert(all('tr').any? do |tr| diff --git a/features/step_definitions/signup_steps.rb b/features/step_definitions/signup_steps.rb index 724e9015d1..e1c69db7b6 100644 --- a/features/step_definitions/signup_steps.rb +++ b/features/step_definitions/signup_steps.rb @@ -4,11 +4,6 @@ create_plan(:application, name: 'application_plan', issuer: provider, published: true, default: true) end -When /^I fill in the invitation signup with email "([^"]*)"$/ do | email | - fill_in("Email", :with => email) - fill_in_invitation_signup(email) -end - When /^I fill in the invitation signup as "([^"]*)"$/ do |username| fill_in("Username", :with => username) fill_in("Password", :with => "supersecret") @@ -16,13 +11,6 @@ click_button "Sign up" end -def fill_in_invitation_signup(username) - fill_in("Username", :with => username) - fill_in("Password", :with => "supersecret") - fill_in("Password confirmation", :with => "supersecret") - click_button "Sign up" -end - When /^I fill in the signup fields as "([^"]*)"$/ do |name| fill_in_signup_fields_as(name) end diff --git a/features/step_definitions/table_steps.rb b/features/step_definitions/table_steps.rb index 2e70d61b21..78e45f9d37 100644 --- a/features/step_definitions/table_steps.rb +++ b/features/step_definitions/table_steps.rb @@ -10,6 +10,11 @@ end end +# Select an action for a given row in a Patternfly table. +# +# When they select action "Hide" of "Public Plan" +# And select action "Delete" of "alice@example.org" +# When "(they )select action {string} of (row ){string}" do |action, row| find_inline_actions_of_row(row).find { |node| node.text == action } .click diff --git a/features/support/helpers/capybara_helpers.rb b/features/support/helpers/capybara_helpers.rb index 97a299d543..80550bb0f6 100644 --- a/features/support/helpers/capybara_helpers.rb +++ b/features/support/helpers/capybara_helpers.rb @@ -47,15 +47,27 @@ def assert_current_domain(domain) def find_inline_actions_of_row(row) if has_css?('td', text: row, wait: 0) - dropdown = find('tr', text: row).find('.pf-c-table__action .pf-c-dropdown') + overflow_menu = find('tr', text: row).find('.pf-c-table__action') + + if overflow_menu.has_css?('.pf-c-dropdown', wait: 0) # collapsed overflow menu + dropdown = overflow_menu.find('.pf-c-dropdown') + elsif overflow_menu.has_css?('.pf-c-overflow-menu', wait: 0) # desktop overflow menu + desktop = overflow_menu.find('.pf-c-overflow-menu__content') + end elsif has_css?('.pf-c-data-list__cell', text: row, wait: 0) dropdown = find('.pf-c-data-list__item-row', text: row).find('.pf-c-data-list__item-action .pf-c-dropdown') else raise "No table or datalist row found with text: #{row}" end - dropdown.find('.pf-c-dropdown__toggle').click if dropdown[:class].exclude?('pf-m-expanded') - dropdown.all('.pf-c-dropdown__menu-item') + if dropdown + dropdown.find('.pf-c-dropdown__toggle').click if dropdown[:class].exclude?('pf-m-expanded') + dropdown.all('.pf-c-dropdown__menu-item') + elsif desktop + desktop.all('.pf-c-overflow-menu__item') + else + raise "Can't find table actions" + end end def select_attribute_filter(label) diff --git a/features/support/paths.rb b/features/support/paths.rb index 69de82d2f7..defa25820b 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -207,8 +207,7 @@ def path_to(page_name, *args) # rubocop:disable Metrics/AbcSize, Metrics/Cycloma edit_admin_account_user_path(user) when 'the new invitation page' new_admin_account_invitation_path - when 'the sent invitations page' - admin_account_invitations_path + when 'the provider new invitation page' new_provider_admin_account_invitation_path when 'the provider sent invitations page' @@ -230,6 +229,12 @@ def path_to(page_name, *args) # rubocop:disable Metrics/AbcSize, Metrics/Cycloma access_token = AccessToken.find_by(name: $2) || @access_token edit_provider_admin_user_access_token_path(access_token) + # + # Account management (Dev portal) + # + when 'the sent invitations page' + admin_account_invitations_path + # # SSO Integrations (Admin portal) # diff --git a/test/factories/invitations.rb b/test/factories/invitations.rb index b8485139d1..29dfeb0b9d 100644 --- a/test/factories/invitations.rb +++ b/test/factories/invitations.rb @@ -1,6 +1,16 @@ +# frozen_string_literal: true + FactoryBot.define do factory(:invitation) do email { "john@example.com" } - account {|a| a.association(:provider_account)} + account { |a| a.association(:provider_account) } + + transient do + accepted { false } + end + + after(:create) do |invitation, evaluator| + invitation.accept! if evaluator.accepted + end end end