Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/work_items')
-rw-r--r--spec/models/work_items/parent_link_spec.rb66
-rw-r--r--spec/models/work_items/type_spec.rb11
-rw-r--r--spec/models/work_items/widgets/base_spec.rb19
-rw-r--r--spec/models/work_items/widgets/description_spec.rb25
-rw-r--r--spec/models/work_items/widgets/hierarchy_spec.rb52
5 files changed, 172 insertions, 1 deletions
diff --git a/spec/models/work_items/parent_link_spec.rb b/spec/models/work_items/parent_link_spec.rb
new file mode 100644
index 00000000000..9516baa7340
--- /dev/null
+++ b/spec/models/work_items/parent_link_spec.rb
@@ -0,0 +1,66 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe WorkItems::ParentLink do
+ describe 'associations' do
+ it { is_expected.to belong_to(:work_item) }
+ it { is_expected.to belong_to(:work_item_parent).class_name('WorkItem') }
+ end
+
+ describe 'validations' do
+ it { is_expected.to validate_presence_of(:work_item) }
+ it { is_expected.to validate_presence_of(:work_item_parent) }
+
+ describe 'hierarchy' do
+ let_it_be(:project) { create(:project) }
+ let_it_be(:issue) { build(:work_item, project: project) }
+ let_it_be(:task1) { build(:work_item, :task, project: project) }
+ let_it_be(:task2) { build(:work_item, :task, project: project) }
+
+ it 'is valid if not-task parent has task child' do
+ expect(build(:parent_link, work_item: task1, work_item_parent: issue)).to be_valid
+ end
+
+ it 'is not valid if child is not task' do
+ link = build(:parent_link, work_item: issue)
+
+ expect(link).not_to be_valid
+ expect(link.errors[:work_item]).to include('Only Task can be assigned as a child in hierarchy.')
+ end
+
+ it 'is not valid if parent is task' do
+ link = build(:parent_link, work_item_parent: task1)
+
+ expect(link).not_to be_valid
+ expect(link.errors[:work_item_parent]).to include('Only Issue can be parent of Task.')
+ end
+
+ it 'is not valid if parent is in other project' do
+ link = build(:parent_link, work_item_parent: task1, work_item: build(:work_item))
+
+ expect(link).not_to be_valid
+ expect(link.errors[:work_item_parent]).to include('Parent must be in the same project as child.')
+ end
+
+ context 'when parent already has maximum number of links' do
+ let_it_be(:link1) { create(:parent_link, work_item_parent: issue, work_item: task1) }
+
+ before do
+ stub_const("#{described_class}::MAX_CHILDREN", 1)
+ end
+
+ it 'is not valid when another link is added' do
+ link2 = build(:parent_link, work_item_parent: issue, work_item: task2)
+
+ expect(link2).not_to be_valid
+ expect(link2.errors[:work_item_parent]).to include('Parent already has maximum number of children.')
+ end
+
+ it 'existing link is still valid' do
+ expect(link1).to be_valid
+ end
+ end
+ end
+ end
+end
diff --git a/spec/models/work_items/type_spec.rb b/spec/models/work_items/type_spec.rb
index 6e9f3210e65..81663d0eb41 100644
--- a/spec/models/work_items/type_spec.rb
+++ b/spec/models/work_items/type_spec.rb
@@ -60,7 +60,16 @@ RSpec.describe WorkItems::Type do
it { is_expected.not_to allow_value('s' * 256).for(:icon_name) }
end
- describe 'default?' do
+ describe '.available_widgets' do
+ subject { described_class.available_widgets }
+
+ it 'returns list of all possible widgets' do
+ is_expected.to match_array([::WorkItems::Widgets::Description,
+ ::WorkItems::Widgets::Hierarchy])
+ end
+ end
+
+ describe '#default?' do
subject { build(:work_item_type, namespace: namespace).default? }
context 'when namespace is nil' do
diff --git a/spec/models/work_items/widgets/base_spec.rb b/spec/models/work_items/widgets/base_spec.rb
new file mode 100644
index 00000000000..9b4b4d9e98f
--- /dev/null
+++ b/spec/models/work_items/widgets/base_spec.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe WorkItems::Widgets::Base do
+ let_it_be(:work_item) { create(:work_item, description: '# Title') }
+
+ describe '.type' do
+ subject { described_class.type }
+
+ it { is_expected.to eq(:base) }
+ end
+
+ describe '#type' do
+ subject { described_class.new(work_item).type }
+
+ it { is_expected.to eq(:base) }
+ end
+end
diff --git a/spec/models/work_items/widgets/description_spec.rb b/spec/models/work_items/widgets/description_spec.rb
new file mode 100644
index 00000000000..8359db31bff
--- /dev/null
+++ b/spec/models/work_items/widgets/description_spec.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe WorkItems::Widgets::Description do
+ let_it_be(:work_item) { create(:work_item, description: '# Title') }
+
+ describe '.type' do
+ subject { described_class.type }
+
+ it { is_expected.to eq(:description) }
+ end
+
+ describe '#type' do
+ subject { described_class.new(work_item).type }
+
+ it { is_expected.to eq(:description) }
+ end
+
+ describe '#description' do
+ subject { described_class.new(work_item).description }
+
+ it { is_expected.to eq(work_item.description) }
+ end
+end
diff --git a/spec/models/work_items/widgets/hierarchy_spec.rb b/spec/models/work_items/widgets/hierarchy_spec.rb
new file mode 100644
index 00000000000..0141731529b
--- /dev/null
+++ b/spec/models/work_items/widgets/hierarchy_spec.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe WorkItems::Widgets::Hierarchy do
+ let_it_be(:work_item) { create(:work_item) }
+
+ describe '.type' do
+ subject { described_class.type }
+
+ it { is_expected.to eq(:hierarchy) }
+ end
+
+ describe '#type' do
+ subject { described_class.new(work_item).type }
+
+ it { is_expected.to eq(:hierarchy) }
+ end
+
+ describe '#parent' do
+ let_it_be(:parent_link) { create(:parent_link) }
+
+ subject { described_class.new(parent_link.work_item).parent }
+
+ it { is_expected.to eq parent_link.work_item_parent }
+
+ context 'when work_items_hierarchy flag is disabled' do
+ before do
+ stub_feature_flags(work_items_hierarchy: false)
+ end
+
+ it { is_expected.to be_nil }
+ end
+ end
+
+ describe '#children' do
+ let_it_be(:parent_link1) { create(:parent_link, work_item_parent: work_item) }
+ let_it_be(:parent_link2) { create(:parent_link, work_item_parent: work_item) }
+
+ subject { described_class.new(work_item).children }
+
+ it { is_expected.to match_array([parent_link1.work_item, parent_link2.work_item]) }
+
+ context 'when work_items_hierarchy flag is disabled' do
+ before do
+ stub_feature_flags(work_items_hierarchy: false)
+ end
+
+ it { is_expected.to be_empty }
+ end
+ end
+end