Skip to content

Commit

Permalink
Test the BsRequestActionDescriptionComponent preview
Browse files Browse the repository at this point in the history
  • Loading branch information
danidoni committed May 6, 2024
1 parent 2ad8fa1 commit 78fad39
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 78fad39

Please sign in to comment.