2019-05-31 12:46:16 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe IssuePresenter do
|
2019-05-31 12:46:16 -04:00
|
|
|
include Gitlab::Routing.url_helpers
|
|
|
|
|
2022-03-30 17:09:29 -04:00
|
|
|
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) }
|
2019-05-31 12:46:16 -04:00
|
|
|
|
2022-03-30 17:09:29 -04:00
|
|
|
let(:presented_issue) { issue }
|
|
|
|
let(:presenter) { described_class.new(presented_issue, current_user: user) }
|
|
|
|
|
|
|
|
before_all do
|
2019-05-31 12:46:16 -04:00
|
|
|
group.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#web_url' do
|
|
|
|
it 'returns correct path' do
|
2022-03-30 17:09:29 -04:00
|
|
|
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
|
2019-10-01 20:06:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#subscribed?' do
|
|
|
|
subject { presenter.subscribed? }
|
|
|
|
|
|
|
|
it 'returns not subscribed' do
|
|
|
|
is_expected.to be(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns subscribed' do
|
2022-03-30 17:09:29 -04:00
|
|
|
create(:subscription, user: user, project: project, subscribable: presented_issue, subscribed: true)
|
2019-10-01 20:06:26 -04:00
|
|
|
|
|
|
|
is_expected.to be(true)
|
2019-05-31 12:46:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#issue_path' do
|
|
|
|
it 'returns correct path' do
|
2022-03-30 17:09:29 -04:00
|
|
|
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
|
2019-05-31 12:46:16 -04:00
|
|
|
end
|
|
|
|
end
|
2020-11-08 22:09:03 -05:00
|
|
|
|
|
|
|
describe '#project_emails_disabled?' do
|
|
|
|
subject { presenter.project_emails_disabled? }
|
|
|
|
|
|
|
|
it 'returns false when emails notifications is enabled for project' do
|
|
|
|
is_expected.to be(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when emails notifications is disabled for project' do
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:emails_disabled?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be(true) }
|
|
|
|
end
|
|
|
|
end
|
2019-05-31 12:46:16 -04:00
|
|
|
end
|