2022-02-01 00:14:06 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe WorkItem do
|
2022-05-25 00:09:46 +00:00
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to have_one(:work_item_parent).class_name('WorkItem') }
|
|
|
|
|
|
|
|
it 'has one `parent_link`' do
|
|
|
|
is_expected.to have_one(:parent_link)
|
|
|
|
.class_name('::WorkItems::ParentLink')
|
|
|
|
.with_foreign_key('work_item_id')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has many `work_item_children`' do
|
|
|
|
is_expected.to have_many(:work_item_children)
|
|
|
|
.class_name('WorkItem')
|
|
|
|
.with_foreign_key('work_item_id')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has many `child_links`' do
|
|
|
|
is_expected.to have_many(:child_links)
|
|
|
|
.class_name('::WorkItems::ParentLink')
|
|
|
|
.with_foreign_key('work_item_parent_id')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-01 00:14:06 +00:00
|
|
|
describe '#noteable_target_type_name' do
|
|
|
|
it 'returns `issue` as the target name' do
|
|
|
|
work_item = build(:work_item)
|
|
|
|
|
|
|
|
expect(work_item.noteable_target_type_name).to eq('issue')
|
|
|
|
end
|
|
|
|
end
|
2022-02-24 18:19:04 +00:00
|
|
|
|
2022-05-26 09:08:11 +00:00
|
|
|
describe '#widgets' do
|
|
|
|
subject { build(:work_item).widgets }
|
|
|
|
|
2022-06-03 09:08:43 +00:00
|
|
|
it 'returns instances of supported widgets' do
|
|
|
|
is_expected.to match_array([instance_of(WorkItems::Widgets::Description),
|
2022-06-29 18:08:50 +00:00
|
|
|
instance_of(WorkItems::Widgets::Hierarchy),
|
2022-06-30 15:09:03 +00:00
|
|
|
instance_of(WorkItems::Widgets::Assignees),
|
|
|
|
instance_of(WorkItems::Widgets::Weight)])
|
2022-06-03 09:08:43 +00:00
|
|
|
end
|
2022-05-26 09:08:11 +00:00
|
|
|
end
|
|
|
|
|
2022-02-24 18:19:04 +00:00
|
|
|
describe 'callbacks' do
|
|
|
|
describe 'record_create_action' do
|
|
|
|
it 'records the creation action after saving' do
|
|
|
|
expect(Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter).to receive(:track_work_item_created_action)
|
|
|
|
# During the work item transition we also want to track work items as issues
|
|
|
|
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_created_action)
|
|
|
|
|
|
|
|
create(:work_item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-02-01 00:14:06 +00:00
|
|
|
end
|