diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
commit | 9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch) | |
tree | 865198c01d1824a9b098127baa3ab980c9cd2c06 /spec/support/shared_contexts/requests/api/graphql/work_items/work_item_types_shared_context.rb | |
parent | 6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff) |
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
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.rb | 64 |
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 |