diff --git a/src/api/spec/components/bs_request_action_description_component_spec.rb b/src/api/spec/components/bs_request_action_description_component_spec.rb new file mode 100644 index 000000000000..7f5d7345102c --- /dev/null +++ b/src/api/spec/components/bs_request_action_description_component_spec.rb @@ -0,0 +1,32 @@ +RSpec.describe BsRequestActionDescriptionComponent, type: :component do + context 'when testing the previews' do + let(:user) { create(:confirmed_user, :with_home) } + let(:creator) { create(:confirmed_user, login: 'creator', realname: 'Creator') } + let(:source_prj) { create(:project) } + let(:source_pkg) { create(:package, project: source_prj) } + let(:target_prj) { user.home_project } + let(:target_pkg) { create(:package, project: target_prj) } + + context 'when previewing the submit' do + let!(:bs_request) do + create(:bs_request, type: 'submit', source_package: source_pkg, source_project: source_prj, target_project: target_prj, target_package: target_pkg, creator: user) + end + + it 'renders the preview' do + render_preview(:submit_preview) + + expect(rendered_content).to have_text("Submit package #{source_prj} / #{source_pkg} to package #{target_prj} / #{target_pkg}") + end + end + + context 'when previewing the add role' do + let!(:bs_request) { create(:bs_request, type: :add_role, target_project: user.home_project, role: 'maintainer', person_name: user.login, creator: creator) } + + it 'renders the preview' do + render_preview(:add_role_preview) + + expect(rendered_content).to have_text("Creator (creator) wants the user #{user.name} (#{user.login}) to get the role maintainer for project #{user.home_project}") + end + end + end +end diff --git a/src/api/spec/components/previews/bs_request_action_description_component_preview.rb b/src/api/spec/components/previews/bs_request_action_description_component_preview.rb index 1831838fe5a6..14162ef696ad 100644 --- a/src/api/spec/components/previews/bs_request_action_description_component_preview.rb +++ b/src/api/spec/components/previews/bs_request_action_description_component_preview.rb @@ -7,6 +7,6 @@ def submit_preview def add_role_preview bs_request = BsRequest.joins(:bs_request_actions).where(bs_request_actions: { type: :add_role }).last - render(BsRequestActionDescriptionComponent.new(action: bs_request.webui_actions.find { |a| a[:type] == :add_role }, creator: bs_request.creator)) + render(BsRequestActionDescriptionComponent.new(action: bs_request.bs_request_actions.first { |a| a[:type] == 'add_role' })) end end