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/support/shared_contexts/requests/api/graphql/work_items/work_item_types_shared_context.rb')
-rw-r--r--spec/support/shared_contexts/requests/api/graphql/work_items/work_item_types_shared_context.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/support/shared_contexts/requests/api/graphql/work_items/work_item_types_shared_context.rb b/spec/support/shared_contexts/requests/api/graphql/work_items/work_item_types_shared_context.rb
new file mode 100644
index 00000000000..3a062d77b4f
--- /dev/null
+++ b/spec/support/shared_contexts/requests/api/graphql/work_items/work_item_types_shared_context.rb
@@ -0,0 +1,64 @@
+# frozen_string_literal: true
+
+RSpec.shared_context 'with work item types request context' do
+ let(:work_item_type_fields) do
+ <<~GRAPHQL
+ id
+ name
+ iconName
+ widgetDefinitions {
+ type
+ ... on WorkItemWidgetDefinitionAssignees {
+ canInviteMembers
+ }
+ ... on WorkItemWidgetDefinitionHierarchy {
+ allowedChildTypes {
+ nodes { id name }
+ }
+ }
+ }
+ GRAPHQL
+ end
+
+ # This is necessary so we can overwrite attributes in EE
+ let(:widget_attributes) { base_widget_attributes }
+ let(:base_widget_attributes) do
+ {
+ assignees: {
+ 'canInviteMembers' => false
+ }
+ }
+ end
+
+ def expected_work_item_type_response(work_item_type = nil)
+ base_scope = WorkItems::Type.default
+ base_scope = base_scope.id_in(work_item_type.id) if work_item_type
+
+ base_scope.map do |type|
+ hash_including(
+ 'id' => type.to_global_id.to_s,
+ 'name' => type.name,
+ 'iconName' => type.icon_name,
+ 'widgetDefinitions' => match_array(widgets_for(type))
+ )
+ end
+ end
+
+ def widgets_for(work_item_type)
+ work_item_type.widgets.map do |widget|
+ base_attributes = { 'type' => widget.type.to_s.upcase }
+ next hierarchy_widget_attributes(work_item_type, base_attributes) if widget == WorkItems::Widgets::Hierarchy
+ next base_attributes unless widget_attributes[widget.type]
+
+ base_attributes.merge(widget_attributes[widget.type])
+ end
+ end
+
+ def hierarchy_widget_attributes(work_item_type, base_attributes)
+ fields = work_item_type.allowed_child_types_by_name.map do |child_type|
+ { "id" => child_type.to_global_id.to_s, "name" => child_type.name }
+ end
+
+ base_attributes.merge({ 'allowedChildTypes' => { 'nodes' => fields } })
+ end
+end