Commit 45d94bcf authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '356627-task-specific-work-item-url' into 'master'

GraphQL IssueType returns work item path if task

See merge request gitlab-org/gitlab!83791
parents 51e115a2 feb7a3aa
......@@ -4,7 +4,9 @@ class IssuePresenter < Gitlab::View::Presenter::Delegated
presents ::Issue, as: :issue
def issue_path
url_builder.build(issue, only_path: true)
return url_builder.build(issue, only_path: true) unless use_work_items_path?
project_work_items_path(issue.project, work_items_path: issue.id)
end
delegator_override :subscribed?
......@@ -15,6 +17,18 @@ class IssuePresenter < Gitlab::View::Presenter::Delegated
def project_emails_disabled?
issue.project.emails_disabled?
end
def web_url
return super unless use_work_items_path?
project_work_items_url(issue.project, work_items_path: issue.id)
end
private
def use_work_items_path?
issue.issue_type == 'task' && issue.project.work_items_feature_flag_enabled?
end
end
IssuePresenter.prepend_mod_with('IssuePresenter')
......@@ -3,6 +3,7 @@
module EE
module IssuePresenter
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
def sla_due_at
return unless sla_available?
......@@ -10,6 +11,7 @@ module EE
issuable_sla&.due_at
end
override :web_url
def web_url
return super unless issue.issue_type == 'test_case'
......
......@@ -58,6 +58,11 @@ FactoryBot.define do
end
end
trait :task do
issue_type { :task }
association :work_item_type, :default, :task
end
factory :incident do
issue_type { :incident }
association :work_item_type, :default, :incident
......
......@@ -37,5 +37,10 @@ FactoryBot.define do
base_type { WorkItems::Type.base_types[:requirement] }
icon_name { 'issue-type-requirements' }
end
trait :task do
base_type { WorkItems::Type.base_types[:task] }
icon_name { 'issue-type-task' }
end
end
end
......@@ -5,19 +5,42 @@ require 'spec_helper'
RSpec.describe IssuePresenter do
include Gitlab::Routing.url_helpers
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
let(:issue) { create(:issue, project: project) }
let(:presenter) { described_class.new(issue, current_user: user) }
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:issue) { create(:issue, project: project) }
let_it_be(:task) { create(:issue, :task, project: project) }
before do
let(:presented_issue) { issue }
let(:presenter) { described_class.new(presented_issue, current_user: user) }
before_all do
group.add_developer(user)
end
describe '#web_url' do
it 'returns correct path' do
expect(presenter.web_url).to eq("http://localhost/#{group.name}/#{project.name}/-/issues/#{issue.iid}")
expect(presenter.web_url).to eq("http://localhost/#{group.name}/#{project.name}/-/issues/#{presented_issue.iid}")
end
context 'when issue type is task' do
let(:presented_issue) { task }
context 'when work_items feature flag is enabled' do
it 'returns a work item url for the task' do
expect(presenter.web_url).to eq(project_work_items_url(project, work_items_path: presented_issue.id))
end
end
context 'when work_items feature flag is disabled' do
before do
stub_feature_flags(work_items: false)
end
it 'returns an issue url for the task' do
expect(presenter.web_url).to eq("http://localhost/#{group.name}/#{project.name}/-/issues/#{presented_issue.iid}")
end
end
end
end
......@@ -29,7 +52,7 @@ RSpec.describe IssuePresenter do
end
it 'returns subscribed' do
create(:subscription, user: user, project: project, subscribable: issue, subscribed: true)
create(:subscription, user: user, project: project, subscribable: presented_issue, subscribed: true)
is_expected.to be(true)
end
......@@ -37,7 +60,27 @@ RSpec.describe IssuePresenter do
describe '#issue_path' do
it 'returns correct path' do
expect(presenter.issue_path).to eq("/#{group.name}/#{project.name}/-/issues/#{issue.iid}")
expect(presenter.issue_path).to eq("/#{group.name}/#{project.name}/-/issues/#{presented_issue.iid}")
end
context 'when issue type is task' do
let(:presented_issue) { task }
context 'when work_items feature flag is enabled' do
it 'returns a work item path for the task' do
expect(presenter.issue_path).to eq(project_work_items_path(project, work_items_path: presented_issue.id))
end
end
context 'when work_items feature flag is disabled' do
before do
stub_feature_flags(work_items: false)
end
it 'returns an issue path for the task' do
expect(presenter.issue_path).to eq("/#{group.name}/#{project.name}/-/issues/#{presented_issue.iid}")
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment